Skip to content

Commit fa7a80b

Browse files
Added event handling for agent list request on fullscreen widgets
1 parent f4b22a2 commit fa7a80b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pages/helpdesk/fullscreen.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,24 @@ function HelpDeskFullscreen() {
2525
}, [fullscreenWidget, notificationsCount])
2626

2727
useEffect(() => {
28-
if (developerApp) {
28+
if (developerApp && developerApp.authorization?.data) {
2929
fetch(`${developerApp.urls.liveChatApi}/configuration/action/list_agents`, {
3030
method: 'POST',
3131
body: '{}',
3232
headers: {
3333
'Content-Type': 'application/json',
34-
Authorization: `${developerApp.authorization?.data?.token_type} ${developerApp.authorization?.data?.access_token}`,
34+
Authorization: `${developerApp.authorization.data.token_type} ${developerApp.authorization.data.access_token}`,
3535
},
3636
})
3737
.then(async (response) => {
38+
const data = await response.json();
39+
3840
if (response.ok) {
39-
return await response.json()
41+
return data
4042
}
4143

44+
await developerApp.features.reporting.sendError("4xx", `Problem with agent list request [${data.error?.message ?? response.status}]`)
45+
4246
return []
4347
})
4448
.then(setAgents)

pages/livechat/fullscreen.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,24 @@ function LiveChatFullscreen() {
2525
}, [fullscreenWidget, notificationsCount])
2626

2727
useEffect(() => {
28-
if (developerApp) {
28+
if (developerApp && developerApp.authorization?.data) {
2929
fetch(`${developerApp.urls.liveChatApi}/configuration/action/list_agents`, {
3030
method: 'POST',
3131
body: '{}',
3232
headers: {
3333
'Content-Type': 'application/json',
34-
Authorization: `${developerApp.authorization?.data?.token_type} ${developerApp.authorization?.data?.access_token}`,
34+
Authorization: `${developerApp.authorization.data.token_type} ${developerApp.authorization.data.access_token}`,
3535
},
3636
})
3737
.then(async (response) => {
38+
const data = await response.json();
39+
3840
if (response.ok) {
39-
return await response.json()
41+
return data
4042
}
4143

44+
await developerApp.features.reporting.sendError("4xx", `Problem with agent list request [${data.error?.message ?? response.status}]`)
45+
4246
return []
4347
})
4448
.then(setAgents)

0 commit comments

Comments
 (0)