Skip to content

Commit 45551ed

Browse files
committed
- Add note form in calling panel
- Update authorization panel UI
1 parent 7aa699d commit 45551ed

File tree

9 files changed

+199
-161
lines changed

9 files changed

+199
-161
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pipedrive-embeddable-ringcentral-phone-spa",
3-
"version": "2.0.4",
3+
"version": "2.1.0",
44
"description": "Add RingCentral Embeddable Voice widgets to Pipedrive",
55
"keywords": [
66
"RingCentral",

src/config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import {
2121
showAuthBtn,
2222
unAuth,
2323
doAuth,
24-
notifyRCAuthed,
25-
renderAuthButton
24+
notifyRCAuthed
2625
} from './features/auth'
2726
import * as ls from 'ringcentral-embeddable-extension-common/src/common/ls'
2827

@@ -41,6 +40,7 @@ import {
4140
match
4241
} from 'ringcentral-embeddable-extension-common/src/common/db'
4342
import initReact from './lib/react-entry'
43+
import initInner from './lib/inner-entry'
4444

4545
let {
4646
pageSize = 100
@@ -359,13 +359,12 @@ export async function initThirdParty () {
359359
window.rc.userAuthed = userAuthed
360360
window.rc.syncTimestamp = await ls.get('syncTimestamp') || null
361361
window.rc.syncTimestampDeal = await ls.get('syncTimestampDeal') || null
362-
// get the html ready
363-
renderAuthButton()
364362
if (window.rc.userAuthed) {
365363
notifyRCAuthed()
366364
}
367365
upgrade()
368366
initReact()
367+
initInner()
369368
}
370369

371370
// init call with ringcenntral button at page bottom

src/features/auth.js

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,12 @@
22
* auth related feature
33
*/
44

5-
import { thirdPartyConfigs } from 'ringcentral-embeddable-extension-common/src/common/app-config'
6-
import logo from 'ringcentral-embeddable-extension-common/src/common/rc-logo'
75
import {
8-
createElementFromHTML,
9-
findParentBySel,
106
sendMsgToRCIframe
117
} from 'ringcentral-embeddable-extension-common/src/common/helpers'
128
import * as ls from 'ringcentral-embeddable-extension-common/src/common/ls'
139

1410
let tokenHandler
15-
let {
16-
serviceName
17-
} = thirdPartyConfigs
1811

1912
window.rc = {
2013
postMessage: sendMsgToRCIframe
@@ -45,22 +38,9 @@ export function hideAuthBtn () {
4538
* need show auth button to user
4639
*/
4740
export function showAuthBtn () {
48-
let dom = document.querySelector('.rc-auth-button-wrap')
49-
dom && dom.classList.remove('rc-hide-to-side')
50-
}
51-
52-
/**
53-
* hanle user click auth button
54-
* @param {*} e
55-
*/
56-
function handleAuthClick (e) {
57-
let { target } = e
58-
let { classList } = target
59-
if (findParentBySel(target, '.rc-auth-btn')) {
60-
doAuth()
61-
} else if (classList.contains('rc-dismiss-auth')) {
62-
hideAuthBtn()
63-
}
41+
window.postMessage({
42+
type: 'rc-show-auth-panel'
43+
}, '*')
6444
}
6545

6646
/**
@@ -80,9 +60,6 @@ export async function doAuth () {
8060
if (window.rc.userAuthed) {
8161
return
8262
}
83-
hideAuthBtn()
84-
let frameWrap = document.getElementById('rc-auth-hs')
85-
frameWrap && frameWrap.classList.remove('rc-hide-to-side')
8663
updateUserAuthed(true)
8764
notifyRCAuthed()
8865
}
@@ -110,40 +87,3 @@ export async function unAuth () {
11087
refreshContactsBtn.remove()
11188
}
11289
}
113-
114-
/**
115-
* render auth button
116-
* todo: you can customize this
117-
*/
118-
export function renderAuthButton () {
119-
let btn = createElementFromHTML(
120-
`
121-
<div class="rc-auth-button-wrap animate rc-hide-to-side">
122-
<span class="rc-auth-btn">
123-
<span class="rc-iblock">Auth</span>
124-
<img class="rc-iblock" src="${logo}" />
125-
<span class="rc-iblock">access ${serviceName} data</span>
126-
</span>
127-
<div class="rc-auth-desc rc-pd1t">
128-
After auth, you can access ${serviceName} contacts from RingCentral phone's contacts list. You can revoke access from RingCentral phone's setting.
129-
</div>
130-
<div class="rc-pd1t">
131-
<span class="rc-dismiss-auth" title="dismiss">&times;</span>
132-
</div>
133-
</div>
134-
`
135-
)
136-
btn.onclick = handleAuthClick
137-
if (
138-
!document.querySelector('.rc-auth-button-wrap')
139-
) {
140-
document.body.appendChild(btn)
141-
}
142-
}
143-
144-
/**
145-
* todo: you can customize this
146-
*/
147-
export function renderAuthPanel () {
148-
return false
149-
}

src/features/call-log-sync.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from 'ringcentral-embeddable-extension-common/src/common/helpers'
1616
import fetch from 'ringcentral-embeddable-extension-common/src/common/fetch'
1717
import moment from 'moment'
18-
import { getSessionToken } from './common'
18+
import { getSessionToken, autoLogPrefix } from './common'
1919
import {
2020
match
2121
} from 'ringcentral-embeddable-extension-common/src/common/db'
@@ -185,6 +185,13 @@ async function filterLoggered (arr) {
185185
*/
186186
async function doSyncOne (contact, body, formData, isManuallySync) {
187187
let { id, org_id: oid } = contact
188+
let desc = formData.description
189+
const sid = _.get(body, 'call.telephonySessionId') || 'not-exist'
190+
const sessid = autoLogPrefix + sid
191+
if (!isManuallySync) {
192+
desc = await ls.get(sessid) || ''
193+
console.log('ff', sessid, desc)
194+
}
188195
let toNumber = _.get(body, 'call.to.phoneNumber')
189196
let fromNumber = _.get(body, 'call.from.phoneNumber')
190197
let duration = _.get(body, 'call.duration') || 0
@@ -230,7 +237,7 @@ async function doSyncOne (contact, body, formData, isManuallySync) {
230237
let bodyAll = mainBody.map(mm => {
231238
return {
232239
id: mm.id,
233-
body: `<p>${formData.description || ''}</p><p>${mm.body}</p>${recording}`
240+
body: `<p>${desc || ''}</p><p>${mm.body}</p>${recording}`
234241
}
235242
})
236243
for (const uit of bodyAll) {
@@ -267,4 +274,7 @@ async function doSyncOne (contact, body, formData, isManuallySync) {
267274
notify('call log sync to third party failed', 'warn')
268275
}
269276
}
277+
if (!isManuallySync) {
278+
await ls.clear(sessid)
279+
}
270280
}

src/features/common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export function getSessionToken () {
1111
return arr ? arr[1] : ''
1212
}
1313

14+
export const autoLogPrefix = 'rc-auto-log-id:'
1415
/**
1516
* get current user info
1617
* @param {string} token

src/lib/inner-elem.js

Lines changed: 104 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,91 +2,109 @@
22
* react element in widget wrapper
33
*/
44

5-
// import { useEffect, useState } from 'react'
6-
// import { Modal, Button } from 'antd'
7-
// import { SyncOutlined } from '@ant-design/icons'
8-
// import { reSyncData } from '../features/contacts'
5+
import { useEffect, useState } from 'react'
6+
import { Tooltip, Input } from 'antd'
7+
import { EditOutlined, LeftCircleOutlined } from '@ant-design/icons'
8+
import * as ls from 'ringcentral-embeddable-extension-common/src/common/ls'
9+
// prefix telephonySessionId
10+
import { autoLogPrefix } from '../features/common'
11+
import _ from 'lodash'
12+
import './inner.styl'
913

10-
// function showSyncMenu () {
11-
// let mod = null
12-
// function syncRecent () {
13-
// reSyncData(true)
14-
// destroyMod()
15-
// }
16-
// function syncAll () {
17-
// reSyncData()
18-
// destroyMod()
19-
// }
20-
// function destroyMod () {
21-
// mod.destroy()
22-
// }
23-
// const content = (
24-
// <div>
25-
// <div className='pd2b'>After Sync contacts, conatacts data will update, so auto call log can match right contacts, you could choose sync only recent updated/created contacts or sync all contacts.</div>
26-
// <div>
27-
// <Button
28-
// type='primary'
29-
// className='mg1r mg1b'
30-
// onClick={syncRecent}
31-
// >
32-
// Sync recent update/created contacts
33-
// </Button>
34-
// <Button
35-
// type='primary'
36-
// className='mg1r mg1b'
37-
// onClick={syncAll}
38-
// >
39-
// Sync all contacts
40-
// </Button>
41-
// <Button
42-
// type='ghost'
43-
// className='mg1r mg1b'
44-
// onClick={destroyMod}
45-
// >
46-
// Cancel
47-
// </Button>
48-
// </div>
49-
// </div>
50-
// )
51-
// const btnProps = {
52-
// disabled: true,
53-
// className: 'hide'
54-
// }
55-
// mod = Modal.confirm({
56-
// title: 'Sync contacts',
57-
// width: '90%',
58-
// icon: <SyncOutlined />,
59-
// content,
60-
// zIndex: 11000,
61-
// closable: false,
62-
// okButtonProps: btnProps,
63-
// cancelButtonProps: btnProps
64-
// })
65-
// }
14+
const { TextArea } = Input
6615

67-
// // function showNotification (info, destroyPrev = false) {
68-
69-
// // }
70-
71-
// export default () => {
72-
// // const [showForm, setShowForm] = useState(false)
73-
// // function onEvent (e) {
74-
// // if (!e || !e.data || !e.data.type) {
75-
// // return
76-
// // }
77-
// // const { type } = e.data
78-
// // if (type === 'rc-call-init-notify') {
79-
// // setShowForm(true)
80-
// // } else if (type === 'rc-show-notification') {
81-
// // showNotification(e.data.info)
82-
// // }
83-
// // }
84-
// // useEffect(() => {
85-
// // window.addEventListener('message', onEvent)
86-
// // return () => {
87-
// // window.removeEventListener('message', onEvent)
88-
// // }
89-
// // }, [])
90-
91-
// return null
92-
// }
16+
export default () => {
17+
const [state, setStateOri] = useState({
18+
calling: false,
19+
note: '',
20+
hideForm: false
21+
})
22+
const { note, hideForm, calling } = state
23+
function setState (obj) {
24+
setStateOri(s => ({
25+
...s,
26+
...obj
27+
}))
28+
console.log('state', state)
29+
}
30+
function saveNote (id) {
31+
console.log('sid', id)
32+
console.log('statebbb', note)
33+
ls.set(id, note)
34+
}
35+
function onEvent (e) {
36+
if (!e || !e.data || !e.data.type) {
37+
return
38+
}
39+
const { type } = e.data
40+
if (type === 'rc-call-start-notify') {
41+
setState({
42+
calling: true,
43+
note: '',
44+
hideForm: false
45+
})
46+
} else if (type === 'rc-call-end-notify') {
47+
// setState({
48+
// hideForm: true
49+
// })
50+
const sid = _.get(e, 'data.call.partyData.sessionId')
51+
if (!sid) {
52+
return
53+
}
54+
const id = autoLogPrefix + sid
55+
saveNote(id)
56+
}
57+
}
58+
function handleChangeNote (e) {
59+
setState({
60+
note: e.target.value
61+
})
62+
}
63+
useEffect(() => {
64+
window.addEventListener('message', onEvent)
65+
return () => {
66+
window.removeEventListener('message', onEvent)
67+
}
68+
}, [note])
69+
if (!calling) {
70+
return null
71+
}
72+
if (hideForm) {
73+
return (
74+
<Tooltip title='Show note edit form' overlayClassName='rc-toolt-tip-card'>
75+
<EditOutlined
76+
onClick={() => setState({
77+
hideForm: false
78+
})}
79+
className='pointer rc-show-note-form'
80+
/>
81+
</Tooltip>
82+
)
83+
}
84+
return (
85+
<div className='rc-call-note-form'>
86+
<div className='pd1'>
87+
<Tooltip overlayClassName='rc-toolt-tip-card' title='Note will synced with call log when call end'>
88+
<TextArea
89+
value={note}
90+
style={{
91+
width: 'calc(100% - 24px)',
92+
marginLeft: '24px'
93+
}}
94+
rows={1}
95+
placeholder='Take some notes'
96+
onChange={handleChangeNote}
97+
/>
98+
</Tooltip>
99+
<Tooltip title='Hide form' overlayClassName='rc-toolt-tip-card'>
100+
<LeftCircleOutlined
101+
onClick={() => setState({
102+
hideForm: true
103+
})}
104+
className='pointer rc-hide-note-form'
105+
/>
106+
</Tooltip>
107+
</div>
108+
</div>
109+
)
110+
}

0 commit comments

Comments
 (0)