From 11a1cf709fc170b0568d1b3c788ee1ac47bbe5a5 Mon Sep 17 00:00:00 2001 From: Delirium Date: Fri, 15 Mar 2024 10:31:47 +0100 Subject: [PATCH] feat(ui): change share modal in player (#1958) * feat(ui): change share modal in player * fix(ui): rm console --- .../Player/ReplayPlayer/AiSubheader.tsx | 15 +- .../Session_/components/HeaderMenu.tsx | 2 + .../SessionCopyLink/SessionCopyLink.tsx | 3 +- .../shared/SharePopup/SharePopup.js | 211 ------------- .../shared/SharePopup/SharePopup.tsx | 289 ++++++++++++++++++ .../shared/SharePopup/sharePopup.module.css | 3 +- 6 files changed, 303 insertions(+), 220 deletions(-) delete mode 100644 frontend/app/components/shared/SharePopup/SharePopup.js create mode 100644 frontend/app/components/shared/SharePopup/SharePopup.tsx diff --git a/frontend/app/components/Session/Player/ReplayPlayer/AiSubheader.tsx b/frontend/app/components/Session/Player/ReplayPlayer/AiSubheader.tsx index 9d37dc839..7d932f6f6 100644 --- a/frontend/app/components/Session/Player/ReplayPlayer/AiSubheader.tsx +++ b/frontend/app/components/Session/Player/ReplayPlayer/AiSubheader.tsx @@ -44,8 +44,8 @@ function SubHeader(props: any) { const location = currentLocation && currentLocation.length > 70 - ? `${currentLocation.slice(0, 25)}...${currentLocation.slice(-40)}` - : currentLocation; + ? `${currentLocation.slice(0, 25)}...${currentLocation.slice(-40)}` + : currentLocation; const showReportModal = () => { const { tabStates, currentTab } = store.get(); @@ -114,6 +114,7 @@ function SubHeader(props: any) { }, { key: 4, + autoclose: true, component: ( ) : ( -
- {/* @ts-ignore */} - -
- )} +
+ {/* @ts-ignore */} + +
+ )} {location && ( diff --git a/frontend/app/components/Session_/components/HeaderMenu.tsx b/frontend/app/components/Session_/components/HeaderMenu.tsx index 960b4a62f..32f8360ea 100644 --- a/frontend/app/components/Session_/components/HeaderMenu.tsx +++ b/frontend/app/components/Session_/components/HeaderMenu.tsx @@ -6,6 +6,7 @@ import OutsideClickDetectingDiv from 'Shared/OutsideClickDetectingDiv'; interface MenuItem { key: number; + autoclose?: boolean; component?: React.ReactElement; } @@ -53,6 +54,7 @@ export default class ItemMenu extends React.PureComponent { item.component ? (
diff --git a/frontend/app/components/shared/SharePopup/SessionCopyLink/SessionCopyLink.tsx b/frontend/app/components/shared/SharePopup/SessionCopyLink/SessionCopyLink.tsx index ce41b3800..9d9e49963 100644 --- a/frontend/app/components/shared/SharePopup/SessionCopyLink/SessionCopyLink.tsx +++ b/frontend/app/components/shared/SharePopup/SessionCopyLink/SessionCopyLink.tsx @@ -9,7 +9,8 @@ import { DateTime } from 'luxon'; function SessionCopyLink({ startedAt }: any) { const [copied, setCopied] = React.useState(false); const { store } = React.useContext(PlayerContext); - const time = store.get().time; + + const time = store?.get().time; const copyHandler = () => { setCopied(true); diff --git a/frontend/app/components/shared/SharePopup/SharePopup.js b/frontend/app/components/shared/SharePopup/SharePopup.js deleted file mode 100644 index 9cebad02a..000000000 --- a/frontend/app/components/shared/SharePopup/SharePopup.js +++ /dev/null @@ -1,211 +0,0 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import { toast } from 'react-toastify'; -import { Form, Button, Popover, Loader } from 'UI'; -import styles from './sharePopup.module.css'; -import IntegrateSlackButton from '../IntegrateSlackButton/IntegrateSlackButton'; -import SessionCopyLink from './SessionCopyLink'; -import Select from 'Shared/Select'; -import cn from 'classnames'; -import { fetchList as fetchSlack, sendSlackMsg } from 'Duck/integrations/slack'; -import { fetchList as fetchTeams, sendMsTeamsMsg } from 'Duck/integrations/teams'; - -@connect( - (state) => ({ - sessionId: state.getIn(['sessions', 'current']).sessionId, - channels: state.getIn(['slack', 'list']), - slackLoaded: state.getIn(['slack', 'loaded']), - msTeamsChannels: state.getIn(['teams', 'list']), - msTeamsLoaded: state.getIn(['teams', 'loaded']), - tenantId: state.getIn(['user', 'account', 'tenantId']), - }), - { fetchSlack, fetchTeams, sendSlackMsg, sendMsTeamsMsg } -) -export default class SharePopup extends React.PureComponent { - state = { - comment: '', - isOpen: false, - channelId: this.props.channels.getIn([0, 'webhookId']), - teamsChannel: this.props.msTeamsChannels.getIn([0, 'webhookId']), - loadingSlack: false, - loadingTeams: false, - }; - - componentDidUpdate() { - if (this.state.isOpen) { - if (this.props.channels.size === 0 && !this.props.slackLoaded) { - this.props.fetchSlack(); - } - if (this.props.msTeamsChannels.size === 0 && !this.props.msTeamsLoaded) { - this.props.fetchTeams(); - } - } - } - - editMessage = (e) => this.setState({ comment: e.target.value }); - shareToSlack = () => { - this.setState({ loadingSlack: true }, () => { - this.props - .sendSlackMsg({ - integrationId: this.state.channelId, - entity: 'sessions', - entityId: this.props.sessionId, - data: { comment: this.state.comment }, - }) - .then(() => this.handleSuccess('Slack')); - }); - }; - - shareToMSTeams = () => { - this.setState({ loadingTeams: true }, () => { - this.props - .sendMsTeamsMsg({ - integrationId: this.state.teamsChannel, - entity: 'sessions', - entityId: this.props.sessionId, - data: { comment: this.state.comment }, - }) - .then(() => this.handleSuccess('MS Teams')); - }); - }; - - handleOpen = () => { - setTimeout(function () { - document.getElementById('message').focus(); - }, 100); - }; - - handleClose = () => { - this.setState({ comment: '' }); - }; - - handleSuccess = (endpoint) => { - const obj = endpoint === 'Slack' ? { loadingSlack: false } : { loadingTeams: false }; - this.setState(obj); - toast.success(`Sent to ${endpoint}.`); - }; - - changeSlackChannel = ({ value }) => this.setState({ channelId: value.value }); - - changeTeamsChannel = ({ value }) => this.setState({ teamsChannel: value.value }); - - onClickHandler = () => { - this.setState({ isOpen: true }); - }; - - render() { - const { trigger, channels, msTeamsChannels, showCopyLink = false } = this.props; - const { comment, channelId, teamsChannel, loadingSlack, loadingTeams } = this.state; - - const slackOptions = channels - .map(({ webhookId, name }) => ({ value: webhookId, label: name })) - .toJS(); - - const msTeamsOptions = msTeamsChannels - .map(({ webhookId, name }) => ({ value: webhookId, label: name })) - .toJS(); - - return ( - this.setState({ isOpen: true })} - onClose={() => this.setState({ isOpen: false, comment: '' })} - render={() => ( -
- {this.state.loadingTeams || this.state.loadingSlack ? ( - - ) : ( - <> -
- Share -
- {slackOptions.length > 0 || msTeamsOptions.length > 0 ? ( -
-
-