diff --git a/src/containers/AppView/index.js b/src/containers/AppView/index.js index 881704c9..d61e6196 100644 --- a/src/containers/AppView/index.js +++ b/src/containers/AppView/index.js @@ -28,7 +28,7 @@ const MainContent = styled.div` flex-direction: column; flex: 1; height: 100%; - max-width: 100%; + max-width: ${({ showSideDrawer }) => showSideDrawer ? '50%' : '100%'}; position: relative; `; @@ -40,7 +40,7 @@ const Content = styled.div` function AppView(props) { return ( - + ({ @@ -117,6 +118,7 @@ export default withPhone(connect((_, { (auth.loggedIn && callingSettings.callingMode === callingModes.webphone) ) ), + showSideDrawer: sideDrawerUI.show, }), (_, { phone: { environment, diff --git a/src/lib/Adapter/index.js b/src/lib/Adapter/index.js index 0c297d40..385137d2 100644 --- a/src/lib/Adapter/index.js +++ b/src/lib/Adapter/index.js @@ -201,7 +201,7 @@ class Adapter extends AdapterCore { console.log(data.calls); break; case 'rc-login-status-notify': - console.log('rc-login-status-notify:', data.loggedIn, data.loginNumber, data.contractedCountryCode); + console.log('rc-login-status-notify:', data.loggedIn, data.loginNumber, data.contractedCountryCode, data.admin, data.features); break; case 'rc-calling-settings-notify': console.log('rc-calling-settings-notify:', data.callWith, data.callingMode); diff --git a/src/modules/Adapter/index.js b/src/modules/Adapter/index.js index 0c10fd74..a49a8f5f 100644 --- a/src/modules/Adapter/index.js +++ b/src/modules/Adapter/index.js @@ -561,13 +561,17 @@ export default class Adapter extends AdapterModuleCore { return; } if (this._auth.loggedIn && ( - !this._extensionInfo.ready || !this._accountInfo.ready + !this._extensionInfo.ready || + !this._accountInfo.ready || + !this._appFeatures.ready )) { return; } this._loggedIn = this._auth.loggedIn; let loginNumber; let contractedCountryCode; + let isAdmin = false; + let features = {}; if (this._loggedIn) { const extensionNumber = this._extensionInfo.extensionNumber && this._extensionInfo.extensionNumber !== '0' @@ -580,12 +584,27 @@ export default class Adapter extends AdapterModuleCore { this._accountInfo.serviceInfo && this._accountInfo.serviceInfo.contractedCountry && this._accountInfo.serviceInfo.contractedCountry.isoCode; + isAdmin = ( + this._extensionInfo.info && + this._extensionInfo.info.permissions && + this._extensionInfo.info.permissions.admin && + this._extensionInfo.info.permissions.admin.enabled + ) || false; + features = { + sms: this._appFeatures.hasSMSSendingFeature, + meeting: this._appFeatures.hasMeetingsPermission, + glip: this._appFeatures.hasGlipPermission, + smartNote: this._appFeatures.hasSmartNotePermission, + call: this._appFeatures.isCallingEnabled, + }; } this._postMessage({ type: 'rc-login-status-notify', loggedIn: this._loggedIn, loginNumber, contractedCountryCode, + admin: isAdmin, + features, }); } diff --git a/src/modules/SmartNotes/index.ts b/src/modules/SmartNotes/index.ts index 8d63af32..1df1b35d 100644 --- a/src/modules/SmartNotes/index.ts +++ b/src/modules/SmartNotes/index.ts @@ -37,6 +37,7 @@ export class SmartNotes extends RcModuleV2 { protected _smartNoteClient: any; protected _smartNoteMFERemoteEntry: string; protected _smartNoteIframeUri: string; + protected _webphoneHookAdded: boolean; constructor(deps) { super({ @@ -48,51 +49,67 @@ export class SmartNotes extends RcModuleV2 { this._smartNoteClient = null; this._smartNoteIframeUri = ''; this._smartNoteMFERemoteEntry = ''; + this._webphoneHookAdded = false; } - async onInitOnce() { + async onInit() { if (!this.hasPermission) { return; } - this._deps.webphone.onCallStart((webphoneSession) => { - if (!this.showSmartNote) { - return; - } - if (!webphoneSession.partyData) { - return; - } - const phoneNumber = - webphoneSession.direction === callDirections.outbound ? - webphoneSession.to : - webphoneSession.from; - const feedbackName = - webphoneSession.direction === callDirections.outbound ? - webphoneSession.toUserName : - webphoneSession.fromUserName; - const contactMatches = this._deps.contactMatcher.dataMapping[phoneNumber]; - this.setSession({ - id: webphoneSession.partyData.sessionId, - status: 'Answered', - phoneNumber: phoneNumber, - contact: contactMatches && contactMatches.length > 0 ? contactMatches[0] : { - name: feedbackName, - }, - direction: webphoneSession.direction, - startTime: new Date(webphoneSession.startTime).toISOString(), - }); - }); - this._deps.webphone.onCallEnd((webphoneSession) => { - if (!webphoneSession.partyData) { - return; - } - if (this.session?.id === webphoneSession.partyData.sessionId) { + if (this.clientInitialized) { + return; + } + if (!this._webphoneHookAdded) { + this._deps.webphone.onCallStart((webphoneSession) => { + if (!this.hasPermission) { + return; + } + if (!this.showSmartNote) { + return; + } + if (!webphoneSession.partyData) { + return; + } + const phoneNumber = + webphoneSession.direction === callDirections.outbound ? + webphoneSession.to : + webphoneSession.from; + const feedbackName = + webphoneSession.direction === callDirections.outbound ? + webphoneSession.toUserName : + webphoneSession.fromUserName; + const contactMatches = this._deps.contactMatcher.dataMapping[phoneNumber]; this.setSession({ id: webphoneSession.partyData.sessionId, - status: 'Disconnected', + status: 'Answered', + phoneNumber: phoneNumber, + contact: contactMatches && contactMatches.length > 0 ? contactMatches[0] : { + name: feedbackName, + }, direction: webphoneSession.direction, + startTime: new Date(webphoneSession.startTime).toISOString(), }); - } - }); + }); + this._deps.webphone.onCallEnd((webphoneSession) => { + if (!this.hasPermission) { + return; + } + if (!this.showSmartNote) { + return; + } + if (!webphoneSession.partyData) { + return; + } + if (this.session?.id === webphoneSession.partyData.sessionId) { + this.setSession({ + id: webphoneSession.partyData.sessionId, + status: 'Disconnected', + direction: webphoneSession.direction, + }); + } + }); + this._webphoneHookAdded = true + } try { const plugins = await fetch('./plugins.json').then((res) => res.json()); const smartNotesRemoteEntry = plugins.smartNotesMFE; @@ -113,6 +130,17 @@ export class SmartNotes extends RcModuleV2 { } } + onReset() { + this.clearStates() + } + + @action + clearStates() { + this.callsQueryResults = []; + this.smartNoteTextStore = []; + this.session = null; + } + @state session = null;