-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
175 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,34 @@ | ||
import React, { useState, useEffect, useRef } from 'react'; | ||
import React from 'react'; | ||
import { RcDrawer, styled } from '@ringcentral/juno'; | ||
import { SmartNoteApp } from './SmartNoteApp'; | ||
|
||
const StyledDrawer = styled(RcDrawer)` | ||
height: 100%; | ||
width: 50%; | ||
.RcDrawer-paper { | ||
&.MuiDrawer-docked { | ||
height: 100%; | ||
width: 50%; | ||
.RcDrawer-paper { | ||
width: 50%; | ||
} | ||
} | ||
`; | ||
|
||
export function SideDrawerView({ | ||
smartNoteClient, | ||
smartNoteSession, | ||
smartNoteRemoteEntry, | ||
show, | ||
onClose, | ||
onAlert, | ||
themeType, | ||
onSmartNoteSave, | ||
children, | ||
variant = 'permanent', | ||
}) { | ||
const [session, setSession] = useState(null); | ||
const sessionRef = useRef(session); | ||
useEffect(() => { | ||
if ( | ||
sessionRef.current && | ||
smartNoteSession && | ||
sessionRef.current.id === smartNoteSession.id | ||
) { | ||
// avoid re-render when session is the same | ||
return; | ||
} | ||
sessionRef.current = smartNoteSession; | ||
setSession(null); | ||
const timeout = setTimeout(() => { | ||
setSession(smartNoteSession); | ||
}, 50); | ||
return () => { | ||
clearTimeout(timeout); | ||
}; | ||
}, [smartNoteSession]); | ||
if (!show) { | ||
return null; | ||
} | ||
if (!session || !smartNoteClient) { | ||
|
||
if (!show && variant === 'permanent') { | ||
return null; | ||
} | ||
|
||
return ( | ||
<StyledDrawer | ||
anchor="right" | ||
variant="permanent" | ||
variant={variant as "permanent" | "temporary"} | ||
open={show} | ||
keepMounted | ||
> | ||
<SmartNoteApp | ||
client={smartNoteClient} | ||
onClose={onClose} | ||
onAlert={onAlert} | ||
smartNoteRemoteEntry={smartNoteRemoteEntry} | ||
themeType={themeType} | ||
onSave={onSmartNoteSave} | ||
/> | ||
{children} | ||
</StyledDrawer> | ||
); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useState, useEffect, useRef } from 'react'; | ||
import { SmartNoteApp } from './SmartNoteApp'; | ||
|
||
export function SmartNotesPanel({ | ||
smartNoteClient, | ||
smartNoteSession, | ||
smartNoteRemoteEntry, | ||
onClose, | ||
onAlert, | ||
themeType, | ||
onSave, | ||
}) { | ||
const [session, setSession] = useState(null); | ||
const sessionRef = useRef(session); | ||
|
||
useEffect(() => { | ||
if ( | ||
sessionRef.current && | ||
smartNoteSession && | ||
sessionRef.current.id === smartNoteSession.id | ||
) { | ||
// avoid re-render when session is the same | ||
return; | ||
} | ||
sessionRef.current = smartNoteSession; | ||
setSession(null); | ||
const timeout = setTimeout(() => { | ||
setSession(smartNoteSession); | ||
}, 50); | ||
return () => { | ||
clearTimeout(timeout); | ||
}; | ||
}, [smartNoteSession]); | ||
|
||
useEffect(() => { | ||
console.log('SmartNotesPanel mounted'); | ||
}, []); | ||
|
||
if (!session || !smartNoteClient) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<SmartNoteApp | ||
client={smartNoteClient} | ||
onClose={onClose} | ||
onAlert={onAlert} | ||
smartNoteRemoteEntry={smartNoteRemoteEntry} | ||
themeType={themeType} | ||
onSave={onSave} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { connectModule } from '@ringcentral-integration/widgets/lib/phoneContext'; | ||
import { SmartNotesPanel } from '../../components/SmartNotesPanel'; | ||
|
||
const SmartNotesPage = connectModule( | ||
(phone) => phone.smartNotesUI, | ||
)(SmartNotesPanel); | ||
|
||
export { SmartNotesPage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Module } from '@ringcentral-integration/commons/lib/di'; | ||
import { RcUIModuleV2, watch } from '@ringcentral-integration/core'; | ||
|
||
@Module({ | ||
name: 'SmartNotesUI', | ||
deps: [ | ||
'SmartNotes', | ||
'Alert', | ||
'Theme', | ||
'SideDrawerUI', | ||
], | ||
}) | ||
export class SmartNotesUI extends RcUIModuleV2 { | ||
constructor(deps) { | ||
super({ | ||
deps, | ||
}); | ||
|
||
watch( | ||
this, | ||
() => this._deps.smartNotes.session, | ||
(smartNoteSession) => { | ||
this._deps.sideDrawerUI.setShow(!!smartNoteSession); | ||
}, | ||
); | ||
} | ||
|
||
getUIProps() { | ||
const { smartNotes, theme } = this._deps; | ||
return { | ||
smartNoteSession: smartNotes.session, | ||
smartNoteClient: smartNotes.smartNoteClient, | ||
smartNoteRemoteEntry: smartNotes.smartNoteMFERemoteEntry, | ||
themeType: theme.themeType, | ||
}; | ||
} | ||
|
||
onClose = () => { | ||
this._deps.sideDrawerUI.setShow(false); | ||
if (this._deps.smartNotes.session.status === 'Disconnected') { | ||
this._deps.smartNotes.setSession(null); | ||
} | ||
} | ||
|
||
onAlert = ({ level, message }) => { | ||
this._deps.alert.alert({ | ||
message: 'showCustomAlertMessage', | ||
level, | ||
payload: { | ||
alertMessage: message | ||
} | ||
}); | ||
} | ||
|
||
onSave = async (data) => { | ||
return this._deps.smartNotes.onSmartNoteSave(); | ||
} | ||
|
||
getUIFunctions() { | ||
return { | ||
onClose: this.onClose, | ||
onAlert: this.onAlert, | ||
onSave: this.onSave, | ||
}; | ||
} | ||
} |