@seamly/web-ui 20.8.0-beta.1 → 20.8.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamly/web-ui",
3
- "version": "20.8.0-beta.1",
3
+ "version": "20.8.0-beta.4",
4
4
  "main": "build/dist/lib/index.js",
5
5
  "types": "build/src/javascripts/index.d.ts",
6
6
  "module": "",
@@ -3,6 +3,7 @@ import SeamlySessionExpiredError from 'api/errors/seamly-session-expired-error'
3
3
  import SeamlyUnavailableError from 'api/errors/seamly-unavailable-error'
4
4
  import { Config } from 'config.types'
5
5
  import { initializeConfig, resetConfig } from 'domains/config/actions'
6
+ import { setLocale } from 'domains/i18n/actions'
6
7
  import { ThunkAPI } from 'domains/redux/redux.types'
7
8
  import type { RootState } from 'domains/store'
8
9
  import { initializeVisibility } from 'domains/visibility/actions'
@@ -16,58 +17,61 @@ export const initializeApp = createAsyncThunk<
16
17
  },
17
18
  void,
18
19
  ThunkAPI
19
- >('initializeApp', async (_, { extra: { api, config }, rejectWithValue }) => {
20
- let locale = config?.context?.locale
21
- try {
22
- if (api.hasConversation()) {
23
- const initialState = await api.getConversationIntitialState()
20
+ >(
21
+ 'initializeApp',
22
+ async (_, { extra: { api, config }, rejectWithValue, dispatch }) => {
23
+ let locale = config?.context?.locale
24
+ try {
25
+ if (api.hasConversation()) {
26
+ const initialState = await api.getConversationIntitialState()
24
27
 
25
- locale = initialState.translation?.locale || locale
28
+ locale = initialState.translation?.locale || locale
26
29
 
27
- return { initialState, locale, config }
28
- } else {
29
- if (config?.context?.topic) {
30
- api.send('action', {
31
- type: actionTypes.setTopic,
32
- body: {
33
- name: config.context.topic,
34
- // Separate fallback message is not needed here. Only an attached service will use this, but none will
35
- // be attached before the conversation has started (meaning the fallback message will never be shown).
36
- fallbackMessage: config.context.topic,
37
- },
38
- })
30
+ return { initialState, locale, config }
31
+ } else {
32
+ if (config?.context?.topic) {
33
+ api.send('action', {
34
+ type: actionTypes.setTopic,
35
+ body: {
36
+ name: config.context.topic,
37
+ // Separate fallback message is not needed here. Only an attached service will use this, but none will
38
+ // be attached before the conversation has started (meaning the fallback message will never be shown).
39
+ fallbackMessage: config.context.topic,
40
+ },
41
+ })
42
+ }
43
+ if (config?.context?.translationLocale) {
44
+ locale = config.context.translationLocale
45
+ api.send('action', {
46
+ type: actionTypes.setTranslation,
47
+ body: { enabled: true, locale },
48
+ })
49
+ }
50
+ dispatch(setLocale(locale))
51
+ return { initialState: undefined, locale, config }
39
52
  }
40
- if (config?.context?.translationLocale) {
41
- locale = config.context.translationLocale
42
- api.send('action', {
43
- type: actionTypes.setTranslation,
44
- body: { enabled: true, locale },
53
+ } catch (e) {
54
+ if (e instanceof SeamlySessionExpiredError) {
55
+ const err = new SeamlySessionExpiredError()
56
+
57
+ return rejectWithValue({
58
+ name: err.name,
59
+ message: err.message,
60
+ originalEvent: err.originalEvent,
61
+ originalError: err.originalError,
62
+ action: err.action,
45
63
  })
46
64
  }
47
65
 
48
- return { initialState: undefined, locale, config }
49
- }
50
- } catch (e) {
51
- if (e instanceof SeamlySessionExpiredError) {
52
- const err = new SeamlySessionExpiredError()
53
-
66
+ const err = new SeamlyUnavailableError()
54
67
  return rejectWithValue({
55
68
  name: err.name,
56
69
  message: err.message,
57
- originalEvent: err.originalEvent,
58
- originalError: err.originalError,
59
- action: err.action,
70
+ langKey: err.langKey,
60
71
  })
61
72
  }
62
-
63
- const err = new SeamlyUnavailableError()
64
- return rejectWithValue({
65
- name: err.name,
66
- message: err.message,
67
- langKey: err.langKey,
68
- })
69
- }
70
- })
73
+ },
74
+ )
71
75
 
72
76
  export const resetApp = createAsyncThunk<unknown, void, ThunkAPI>(
73
77
  'resetApp',
@@ -360,7 +360,7 @@ export const storeSlice = createSlice({
360
360
  )
361
361
 
362
362
  // Only set uploads if it was initialised by the account config.
363
- if (newFeaturesHasUpload && lastParticipantEvent.type === 'message') {
363
+ if (newFeaturesHasUpload && lastParticipantEvent?.type === 'message') {
364
364
  const { payload: lastParticipantEventPayload } = lastParticipantEvent
365
365
  const entryType = lastParticipantEventPayload?.entry?.type || {}
366
366
  newFeatures = {
@@ -394,7 +394,12 @@ export const storeSlice = createSlice({
394
394
  ...state.serviceInfo,
395
395
  activeServiceSessionId,
396
396
  }
397
- state.serviceData = serviceData || {}
397
+
398
+ state.serviceData = {
399
+ ...state.serviceData,
400
+ ...serviceData,
401
+ }
402
+
398
403
  state.options = {
399
404
  ...state.options,
400
405
  features: newFeatures || {},
@@ -87,12 +87,6 @@ export const translationSlice = createSlice({
87
87
  },
88
88
  extraReducers: (builder) => {
89
89
  builder
90
- .addCase(initializeApp.fulfilled, (state, { payload }) => {
91
- if (!payload.config?.context?.translationLocale) return
92
-
93
- state.isActive = true
94
- state.currentLocale = payload.locale
95
- })
96
90
  .addCase(initializeConfig.fulfilled, (state, { payload }) => {
97
91
  const feature = payload?.features?.translation
98
92
  if (!feature) return
@@ -11,12 +11,12 @@ import { useEvents, useSeamlyLayoutMode } from './seamly-state-hooks'
11
11
  import useSeamlyCommands from './use-seamly-commands'
12
12
 
13
13
  const useSeamlyChat = () => {
14
+ const events = useEvents()
14
15
  const { t } = useI18n()
15
16
  const { isInline, isWindow } = useSeamlyLayoutMode()
16
17
  const { isOpen, isVisible, setVisibility } = useVisibility()
17
18
  const showInlineView = useSelector(selectShowInlineView)
18
19
  const dispatch = useDispatch()
19
- const events = useEvents()
20
20
  const spinnerTimeout = useRef(null)
21
21
  const { start, connect, apiConfigReady, apiConnected } = useSeamlyCommands()
22
22
  const hasConversation = useSeamlyHasConversation()
@@ -25,8 +25,6 @@ const useSeamlyChat = () => {
25
25
  const startCalled = useRef(false)
26
26
  const { sendAssertive } = useLiveRegion()
27
27
 
28
- const hasEvents = events.length > 0
29
-
30
28
  useEffect(() => {
31
29
  if (isVisible) {
32
30
  // Wait for the live containers to stabilise in the DOM before injecting
@@ -60,14 +58,23 @@ const useSeamlyChat = () => {
60
58
  spinnerTimeout.current = setTimeout(() => {
61
59
  dispatch(setIsLoading(true))
62
60
  }, 500)
61
+
62
+ return () => {
63
+ clearTimeout(spinnerTimeout.current)
64
+ }
63
65
  }, [dispatch])
64
66
 
65
67
  useEffect(() => {
66
- if (hasEvents) {
68
+ if (events.length) {
69
+ spinnerTimeout.current = setTimeout(() => {
70
+ dispatch(setIsLoading(false))
71
+ }, 5000)
72
+ }
73
+
74
+ return () => {
67
75
  clearTimeout(spinnerTimeout.current)
68
- dispatch(setIsLoading(false))
69
76
  }
70
- }, [hasEvents, dispatch])
77
+ }, [events, dispatch])
71
78
 
72
79
  useEffect(() => {
73
80
  // This is needed to reset the ref to allow connect and start to happen again.