Skip to content

Commit c4bb89d

Browse files
Upgraded developer-sdk to 1.4.0
1 parent 450559c commit c4bb89d

File tree

5 files changed

+64
-110
lines changed

5 files changed

+64
-110
lines changed

hooks/app/useDeveloperApp.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ function useDeveloperApp() {
1010
useEffect(() => {
1111
const app = DeveloperApp.init(config)
1212

13-
app.authorization
1413
if (config.auth?.clientId) {
1514
app.authorize().then(() => setDeveloperApp(app))
1615
} else {

package-lock.json

Lines changed: 32 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@livechat/agent-app-sdk": "^1.6.5",
1313
"@livechat/design-system-react-components": "^1.12.0",
14-
"@livechat/developer-sdk": "^1.3.63",
14+
"@livechat/developer-sdk": "^1.4.3",
1515
"@livechat/helpdesk-sdk": "^1.0.3",
1616
"@livechat/moments-sdk": "^1.8.2",
1717
"camelcase": "^6.3.0",
@@ -20,7 +20,7 @@
2020
"react-dom": "^18.0.0"
2121
},
2222
"devDependencies": {
23-
"@livechat/developer-cli": "^1.2.128",
23+
"@livechat/developer-cli": "^1.2.164",
2424
"@types/node": "^17.0.21",
2525
"@types/react": "^18.0.0",
2626
"@typescript-eslint/eslint-plugin": "^5.14.0",

pages/helpdesk/fullscreen.tsx

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@ import FullScreenLoader from 'components/FullScreenLoader'
44
import ViewContainer from 'components/ViewContainer'
55
import useDeveloperApp from 'hooks/app/useDeveloperApp'
66
import useHelpDeskFullscreenWidget from 'hooks/products/helpdesk/useFullscreenWidget'
7-
8-
type Agent = {
9-
id: string
10-
name: string
11-
role: string
12-
avatar: string
13-
}
7+
import { AgentConfigurationDto, LiveChatConfigurationApiError } from '@livechat/developer-studio-api'
148

159
function HelpDeskFullscreen() {
1610
const developerApp = useDeveloperApp()
1711
const fullscreenWidget = useHelpDeskFullscreenWidget()
18-
const [agents, setAgents] = useState<Agent[] | null>(null)
12+
const [agents, setAgents] = useState<AgentConfigurationDto[] | null>(null)
1913
const [notificationsCount, setNotificationsCount] = useState(0)
2014

2115
useEffect(() => {
@@ -25,28 +19,21 @@ function HelpDeskFullscreen() {
2519
}, [fullscreenWidget, notificationsCount])
2620

2721
useEffect(() => {
28-
if (developerApp && developerApp.authorization?.data) {
29-
fetch(`${developerApp.urls.liveChatApi}/configuration/action/list_agents`, {
30-
method: 'POST',
31-
body: '{}',
32-
headers: {
33-
'Content-Type': 'application/json',
34-
Authorization: `${developerApp.authorization.data.token_type} ${developerApp.authorization.data.access_token}`,
35-
},
36-
})
37-
.then(async (response) => {
38-
const data = await response.json();
39-
40-
if (response.ok) {
41-
return data
42-
}
22+
if (!developerApp?.authorization) {
23+
return
24+
}
4325

44-
await developerApp.features.reporting.sendError("4xx", `Problem with agent list request [${data.error?.message ?? response.status}]`)
26+
developerApp.api.products.livechat.configuration.agents
27+
.getAgents()
28+
.then(({ data }) => {
29+
setAgents(data)
30+
})
31+
.catch(async (error) => {
32+
const apiError = error.response.data.error as LiveChatConfigurationApiError | undefined
33+
const eventMessage = apiError ? `${apiError.type}: ${apiError.message}` : 'Unknown error'
4534

46-
return []
47-
})
48-
.then(setAgents)
49-
}
35+
await developerApp.features.reports.sendError('4xx', eventMessage)
36+
})
5037
}, [developerApp])
5138

5239
if (fullscreenWidget === null || developerApp === null || agents === null) {

pages/livechat/fullscreen.tsx

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@ import FullScreenLoader from 'components/FullScreenLoader'
44
import ViewContainer from 'components/ViewContainer'
55
import useDeveloperApp from 'hooks/app/useDeveloperApp'
66
import useLiveChatFullscreenWidget from 'hooks/products/livechat/useFullscreenWidget'
7-
8-
type Agent = {
9-
id: string
10-
name: string
11-
role: string
12-
avatar: string
13-
}
7+
import { AgentConfigurationDto, LiveChatConfigurationApiError } from '@livechat/developer-studio-api'
148

159
function LiveChatFullscreen() {
1610
const developerApp = useDeveloperApp()
1711
const fullscreenWidget = useLiveChatFullscreenWidget()
18-
const [agents, setAgents] = useState<Agent[] | null>(null)
12+
const [agents, setAgents] = useState<AgentConfigurationDto[] | null>(null)
1913
const [notificationsCount, setNotificationsCount] = useState(0)
2014

2115
useEffect(() => {
@@ -25,28 +19,22 @@ function LiveChatFullscreen() {
2519
}, [fullscreenWidget, notificationsCount])
2620

2721
useEffect(() => {
28-
if (developerApp && developerApp.authorization?.data) {
29-
fetch(`${developerApp.urls.liveChatApi}/configuration/action/list_agents`, {
30-
method: 'POST',
31-
body: '{}',
32-
headers: {
33-
'Content-Type': 'application/json',
34-
Authorization: `${developerApp.authorization.data.token_type} ${developerApp.authorization.data.access_token}`,
35-
},
36-
})
37-
.then(async (response) => {
38-
const data = await response.json();
22+
if (!developerApp?.authorization) {
23+
return
24+
}
3925

40-
if (response.ok) {
41-
return data
42-
}
26+
developerApp.api.products.livechat.configuration.agents
27+
.getAgents()
28+
.then(({ data }) => {
29+
setAgents(data)
30+
})
31+
.catch(async (error) => {
32+
const apiError = error.response.data.error as LiveChatConfigurationApiError | undefined
33+
const eventMessage = apiError ? `${apiError.type}: ${apiError.message}` : 'Unknown error'
4334

44-
await developerApp.features.reporting.sendError("4xx", `Problem with agent list request [${data.error?.message ?? response.status}]`)
35+
await developerApp.features.reports.sendError('4xx', eventMessage)
4536

46-
return []
47-
})
48-
.then(setAgents)
49-
}
37+
})
5038
}, [developerApp])
5139

5240
if (fullscreenWidget === null || developerApp === null || agents === null) {

0 commit comments

Comments
 (0)