diff --git a/packages/plugin-calls-ui/src/components/Form.tsx b/packages/plugin-calls-ui/src/components/Form.tsx index 45aea947122..2f3f305b7e5 100644 --- a/packages/plugin-calls-ui/src/components/Form.tsx +++ b/packages/plugin-calls-ui/src/components/Form.tsx @@ -10,10 +10,10 @@ import { IFormProps } from '@erxes/ui/src/types'; import { __ } from '@erxes/ui/src/utils'; import React, { useState } from 'react'; -interface Props { +interface IProps { closeModal?: () => void; data: any; - callData?: { callerNumber: String }; + callData?: { callerNumber: string }; setConfig?: any; } @@ -26,12 +26,17 @@ const renderInput = ( return ( {label} - + ); }; -const CallIntegrationForm = (props: Props) => { +const CallIntegrationForm = (props: IProps) => { const { closeModal, data = {}, setConfig } = props; const [selectedIntegrationId, setSelectedIntegrationId] = useState(''); const integration = selectedIntegrationId @@ -39,6 +44,7 @@ const CallIntegrationForm = (props: Props) => { : data?.[0]; const saveCallConfig = () => { + // tslint:disable-next-line:no-unused-expression integration && localStorage.setItem( 'config:call_integrations', @@ -51,6 +57,7 @@ const CallIntegrationForm = (props: Props) => { isAvailable: true }) ); + // tslint:disable-next-line:no-unused-expression integration && setConfig({ inboxId: integration.inboxId, @@ -63,6 +70,33 @@ const CallIntegrationForm = (props: Props) => { closeModal(); }; + const skipCallConnection = () => { + // tslint:disable-next-line:no-unused-expression + integration && + localStorage.setItem( + 'config:call_integrations', + JSON.stringify({ + inboxId: integration?.inboxId, + phone: integration?.phone, + wsServer: integration?.wsServer, + token: integration?.token, + operators: integration?.operators, + isAvailable: false + }) + ); + // tslint:disable-next-line:no-unused-expression + integration && + setConfig({ + inboxId: integration.inboxId, + phone: integration.phone, + wsServer: integration.wsServer, + token: integration.token, + operators: integration.operators, + isAvailable: false + }); + closeModal(); + }; + const onChange = e => { setSelectedIntegrationId(e.target.value); }; @@ -124,6 +158,15 @@ const CallIntegrationForm = (props: Props) => { > Cancel + + + <> + + + + + )} - {Sip.call?.status !== CALL_STATUS_IDLE && ( + {Sip.call && Sip.call?.status !== CALL_STATUS_IDLE && ( )} + {!Sip.call && ( + + )} )} diff --git a/packages/plugin-calls-ui/src/components/SipProvider/index.tsx b/packages/plugin-calls-ui/src/components/SipProvider/index.tsx index 7a2f950822c..0fe3ddb4fb4 100644 --- a/packages/plugin-calls-ui/src/components/SipProvider/index.tsx +++ b/packages/plugin-calls-ui/src/components/SipProvider/index.tsx @@ -167,6 +167,14 @@ export default class SipProvider extends React.Component< } public componentDidMount() { + const callConfig = JSON.parse( + localStorage.getItem('config:call_integrations') + ); + + if (callConfig && !callConfig.isAvailable) { + return this.props.children(this.state); + } + if (window.document.getElementById('sip-provider-audio')) { throw new Error( `Creating two SipProviders in one application is forbidden. If that's not the case ` + @@ -184,6 +192,14 @@ export default class SipProvider extends React.Component< } public componentDidUpdate(prevProps) { + const callConfig = JSON.parse( + localStorage.getItem('config:call_integrations') + ); + + if (callConfig && !callConfig.isAvailable) { + return this.props.children(this.state); + } + if (this.props.debug !== prevProps.debug) { this.reconfigureDebug(); } diff --git a/packages/plugin-calls-ui/src/components/Widget.tsx b/packages/plugin-calls-ui/src/components/Widget.tsx index 587aaa882fb..2da66c36057 100644 --- a/packages/plugin-calls-ui/src/components/Widget.tsx +++ b/packages/plugin-calls-ui/src/components/Widget.tsx @@ -3,7 +3,7 @@ import Tip from '@erxes/ui/src/components/Tip'; import { __ } from '@erxes/ui/src/utils'; import React from 'react'; import OverlayTrigger from 'react-bootstrap/OverlayTrigger'; -import { NotifButton } from '@erxes/ui-notifications/src/components/styles'; +import { NotifButton } from '../styles'; import WidgetPopover from './WidgetPopover'; type Props = { diff --git a/packages/plugin-calls-ui/src/containers/IncomingCall.tsx b/packages/plugin-calls-ui/src/containers/IncomingCall.tsx index 319918a09e8..8d129de8781 100644 --- a/packages/plugin-calls-ui/src/containers/IncomingCall.tsx +++ b/packages/plugin-calls-ui/src/containers/IncomingCall.tsx @@ -10,12 +10,12 @@ import { Alert } from '@erxes/ui/src/utils'; import client from '@erxes/ui/src/apolloClient'; import queries from '../graphql/queries'; -interface Props { +interface IProps { closeModal?: () => void; callIntegrationsOfUser: any; } -const IncomingCallContainer = (props: Props, context) => { +const IncomingCallContainer = (props: IProps, context) => { const [customer, setCustomer] = useState(undefined); const [conversation, setConversation] = useState(undefined); @@ -91,8 +91,8 @@ const IncomingCallContainer = (props: Props, context) => { }); }; - const getCustomerDetail = (phoneNumber?: string) => { - if (!phoneNumber) { + const getCustomerDetail = (phone?: string) => { + if (!phone) { return null; } @@ -100,7 +100,7 @@ const IncomingCallContainer = (props: Props, context) => { .query({ query: gql(queries.callCustomerDetail), fetchPolicy: 'network-only', - variables: { callerNumber: phoneNumber } + variables: { callerNumber: phone } }) .then(({ data }: { data: any }) => { if (data && data.callsCustomerDetail) { @@ -114,8 +114,8 @@ const IncomingCallContainer = (props: Props, context) => { return; }; - const toggleSection = (phoneNumber): void => { - getCustomerDetail(phoneNumber); + const toggleSection = (phone): void => { + getCustomerDetail(phone); }; const taggerRefetchQueries = [ diff --git a/packages/plugin-calls-ui/src/containers/SipProvider.tsx b/packages/plugin-calls-ui/src/containers/SipProvider.tsx index 2b7f46afda4..7ef33ecf771 100644 --- a/packages/plugin-calls-ui/src/containers/SipProvider.tsx +++ b/packages/plugin-calls-ui/src/containers/SipProvider.tsx @@ -24,7 +24,9 @@ const SipProviderContainer = props => { return null; } - if (error) return Alert.error(error.message); + if (error) { + return Alert.error(error.message); + } const { callIntegrationsOfUser } = data; if (!callIntegrationsOfUser || callIntegrationsOfUser.length === 0) { @@ -48,6 +50,15 @@ const SipProviderContainer = props => { ); } + if (!config.isAvailable) { + return ( + + ); + } const defaultIntegration = config || callIntegrationsOfUser?.[0]; diff --git a/packages/plugin-calls-ui/src/styles.ts b/packages/plugin-calls-ui/src/styles.ts index 833a0d34c6c..2e24be8a583 100644 --- a/packages/plugin-calls-ui/src/styles.ts +++ b/packages/plugin-calls-ui/src/styles.ts @@ -392,3 +392,31 @@ export const CallTabContent = styledTS<{ tab: string; show: boolean }>( flex: 1; } `; + +export const NotifButton = styled.div` + cursor: pointer; + text-align: center; + width: 100%; + position: relative; + transition: all 0.3s ease; + color: ${colors.textSecondary}; + + span { + position: absolute; + top: -4px; + right: -8px; + padding: 3px; + min-width: 18px; + min-height: 18px; + line-height: 12px; + } +`; + +export const DisconnectCall = styled.div` + padding: 10px 20px; + width: 100%; + button { + margin: 0; + width: 100%; + } +`;