@seamly/web-ui 20.0.0-beta.6 → 20.0.0

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.
Files changed (27) hide show
  1. package/build/dist/lib/index.debug.js +11 -22
  2. package/build/dist/lib/index.debug.min.js +1 -1
  3. package/build/dist/lib/index.debug.min.js.LICENSE.txt +0 -4
  4. package/build/dist/lib/index.js +109 -106
  5. package/build/dist/lib/index.min.js +1 -1
  6. package/build/dist/lib/standalone.js +125 -122
  7. package/build/dist/lib/standalone.min.js +1 -1
  8. package/build/dist/lib/style-guide.js +105 -91
  9. package/build/dist/lib/style-guide.min.js +1 -1
  10. package/package.json +1 -2
  11. package/src/javascripts/domains/app/actions.js +23 -1
  12. package/src/javascripts/domains/config/hooks.js +17 -0
  13. package/src/javascripts/domains/config/index.js +0 -1
  14. package/src/javascripts/domains/config/reducer.js +4 -0
  15. package/src/javascripts/domains/store/index.js +1 -5
  16. package/src/javascripts/style-guide/components/app.js +8 -4
  17. package/src/javascripts/style-guide/components/static-core.js +19 -2
  18. package/src/javascripts/style-guide/components/view.js +16 -3
  19. package/src/javascripts/style-guide/states.js +23 -41
  20. package/src/javascripts/style-guide/style-guide-engine.js +13 -1
  21. package/src/javascripts/ui/components/conversation/event/event-participant.js +10 -7
  22. package/src/javascripts/ui/components/conversation/event/participant.js +3 -3
  23. package/src/javascripts/ui/components/layout/agent-info.js +7 -11
  24. package/src/javascripts/ui/components/layout/chat-frame.js +1 -1
  25. package/src/javascripts/ui/components/view/window-view/window-open-button.js +7 -7
  26. package/src/javascripts/ui/utils/seamly-utils.js +9 -2
  27. package/src/javascripts/domains/config/middleware.js +0 -22
@@ -23,6 +23,9 @@ import {
23
23
  Actions as ConfigActions,
24
24
  } from '../../domains/config'
25
25
  import { Reducer as visibilityReducer } from '../../domains/visibility'
26
+ import { seamlyActions } from '../../ui/utils/seamly-utils'
27
+
28
+ const { SET_PARTICIPANT } = seamlyActions
26
29
 
27
30
  const bareApi = {
28
31
  send: () => {},
@@ -33,7 +36,12 @@ const bareApi = {
33
36
  hasConversation: () => false,
34
37
  }
35
38
 
36
- const SeamlyTestCore = ({ state, translations, children }) => {
39
+ const SeamlyTestCore = ({
40
+ state,
41
+ translations,
42
+ participants = [],
43
+ children,
44
+ }) => {
37
45
  const liveMsgRef = useRef(() => {})
38
46
  const eventBusRef = useRef({ emit: () => {} })
39
47
 
@@ -76,8 +84,17 @@ const SeamlyTestCore = ({ state, translations, children }) => {
76
84
  )
77
85
  }
78
86
  newStore.dispatch(I18nActions.setLocale.fulfilled('en-GB', translations))
87
+
88
+ participants.forEach((participant) => {
89
+ newStore.dispatch({
90
+ type: SET_PARTICIPANT,
91
+ participant,
92
+ fromClient: participant.id === 'user',
93
+ })
94
+ })
95
+
79
96
  return newStore
80
- }, [state, translations])
97
+ }, [state, translations, participants])
81
98
 
82
99
  return (
83
100
  state && (
@@ -2,7 +2,12 @@ import { useState, useEffect } from 'preact/hooks'
2
2
  import { View } from '@seamly/web-ui'
3
3
  import StyleGuideStaticCore from './static-core'
4
4
 
5
- const StyleGuideView = ({ state, customComponents = {}, translations }) => {
5
+ const StyleGuideView = ({
6
+ state,
7
+ customComponents = {},
8
+ translations,
9
+ participants,
10
+ }) => {
6
11
  const [renderView, setRenderView] = useState(true)
7
12
  const { config } = state || {}
8
13
  const { layoutMode } = config || {}
@@ -25,11 +30,19 @@ const StyleGuideView = ({ state, customComponents = {}, translations }) => {
25
30
  }
26
31
 
27
32
  return CustomView ? (
28
- <StyleGuideStaticCore state={state} translations={translations}>
33
+ <StyleGuideStaticCore
34
+ state={state}
35
+ translations={translations}
36
+ participants={participants}
37
+ >
29
38
  <CustomView />
30
39
  </StyleGuideStaticCore>
31
40
  ) : (
32
- <StyleGuideStaticCore state={state} translations={translations}>
41
+ <StyleGuideStaticCore
42
+ state={state}
43
+ translations={translations}
44
+ participants={participants}
45
+ >
33
46
  <View />
34
47
  </StyleGuideStaticCore>
35
48
  )
@@ -62,23 +62,8 @@ const avatar =
62
62
 
63
63
  const participantInfo = {
64
64
  participants: {
65
- 'e65fa8dc-97ab-4711-8fec-82bae6461aa2': {
66
- avatar,
67
- id: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
68
- introduction: "You're now talking to {{name}} gimme a minit",
69
- name: 'Mrs. Bot',
70
- service: {
71
- expose: { map: {}, version: 2 },
72
- meta: {},
73
- name: null,
74
- service_session_id: null,
75
- settings: {},
76
- },
77
- },
78
- 'e65fa8dc-97ab-4711-8fec-82bae6461aa3': {
79
- id: 'e65fa8dc-97ab-4711-8fec-82bae6461aa3',
80
- introduction: "You're now talking to {{name}} gimme a minit",
81
- name: 'Mrs. Bot',
65
+ agent: {
66
+ id: 'agent',
82
67
  service: {
83
68
  expose: { map: {}, version: 2 },
84
69
  meta: {},
@@ -87,11 +72,8 @@ const participantInfo = {
87
72
  settings: {},
88
73
  },
89
74
  },
90
- 'seamly-client-participant': {
91
- avatar,
92
- id: 'seamly-client-participant',
93
- introduction: null,
94
- name: 'User',
75
+ user: {
76
+ id: 'user',
95
77
  service: {
96
78
  expose: { map: {}, version: 2 },
97
79
  meta: {},
@@ -101,7 +83,7 @@ const participantInfo = {
101
83
  },
102
84
  },
103
85
  },
104
- currentAgent: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
86
+ currentAgent: 'agent',
105
87
  }
106
88
 
107
89
  const newTopicDivider = {
@@ -215,7 +197,7 @@ const participantMessage = {
215
197
  messageStatus: 'received',
216
198
  participant: {
217
199
  avatar,
218
- id: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
200
+ id: 'agent',
219
201
  introduction: "You're now talking to {{name}} gimme a minit",
220
202
  name: 'Mrs. Bot',
221
203
  service: {
@@ -239,7 +221,7 @@ const participantMessageDefaultIcon = {
239
221
  id: randomId(),
240
222
  messageStatus: 'received',
241
223
  participant: {
242
- id: 'e65fa8dc-97ab-4711-8fec-82bae6461aa3',
224
+ id: 'user',
243
225
  introduction: "You're now talking to {{name}} gimme a minit",
244
226
  name: 'Mrs. Bot',
245
227
  service: {
@@ -264,7 +246,7 @@ const getCustomMessage = ({ type, data, text }) => ({
264
246
  data,
265
247
  variables: {},
266
248
  },
267
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
249
+ participant: 'agent',
268
250
  service: {
269
251
  meta: { additions: {} },
270
252
  name: 'bot',
@@ -292,7 +274,7 @@ const shortTextMessage = {
292
274
  fromHistory: true,
293
275
  id: randomId(),
294
276
  messageStatus: 'read',
295
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
277
+ participant: 'agent',
296
278
  service: {
297
279
  meta: { additions: {} },
298
280
  name: 'bot',
@@ -331,7 +313,7 @@ const ctaMessage = {
331
313
  fromHistory: true,
332
314
  id: 'f5351010-0def-452d-818f-ca22ac61792z',
333
315
  messageStatus: 'read',
334
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
316
+ participant: 'agent',
335
317
  service: {
336
318
  meta: { additions: { hideFeedback: 'true' } },
337
319
  name: 'bot',
@@ -354,7 +336,7 @@ const longTextMessage = {
354
336
  fromHistory: true,
355
337
  id: randomId(),
356
338
  messageStatus: 'read',
357
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
339
+ participant: 'agent',
358
340
  service: {
359
341
  meta: { additions: {} },
360
342
  name: 'bot',
@@ -378,7 +360,7 @@ const textMessageBoldItalicUnderline = {
378
360
  fromHistory: true,
379
361
  id: randomId(),
380
362
  messageStatus: 'read',
381
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
363
+ participant: 'agent',
382
364
  service: {
383
365
  meta: { additions: { hideFeedback: 'true' } },
384
366
  name: 'bot',
@@ -417,7 +399,7 @@ const textMessageWithLinks = {
417
399
  fromHistory: true,
418
400
  id: randomId(),
419
401
  messageStatus: 'read',
420
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
402
+ participant: 'agent',
421
403
  service: {
422
404
  meta: { additions: { hideFeedback: 'true' } },
423
405
  name: 'bot',
@@ -449,7 +431,7 @@ const textMessageWithLongLink = {
449
431
  fromHistory: true,
450
432
  id: 'a964e54e-ea98-46ff-a952-979a47f162c0',
451
433
  messageStatus: 'read',
452
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
434
+ participant: 'agent',
453
435
  service: {
454
436
  meta: { additions: { hideFeedback: 'true' } },
455
437
  name: 'bot',
@@ -473,7 +455,7 @@ const textMesageWithBullets = {
473
455
  fromHistory: true,
474
456
  id: 'f5351010-0def-452d-818f-ca22ac61792a',
475
457
  messageStatus: 'read',
476
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
458
+ participant: 'agent',
477
459
  service: {
478
460
  meta: { additions: { hideFeedback: 'true' } },
479
461
  name: 'bot',
@@ -498,7 +480,7 @@ const imageMessage = {
498
480
  fromHistory: true,
499
481
  id: 'b44ef42c-880c-43ff-b067-499e7f2e81f7',
500
482
  messageStatus: 'read',
501
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
483
+ participant: 'agent',
502
484
  service: {
503
485
  meta: { additions: { hideFeedback: 'true' } },
504
486
  name: 'bot',
@@ -523,7 +505,7 @@ const imageMessageWithLightbox = {
523
505
  fromHistory: true,
524
506
  id: 'b44ef42c-880c-43ff-b067-499e7f2e81f8',
525
507
  messageStatus: 'read',
526
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
508
+ participant: 'agent',
527
509
  service: {
528
510
  meta: { additions: { hideFeedback: 'true' } },
529
511
  name: 'bot',
@@ -548,7 +530,7 @@ const videoMessage = {
548
530
  fromHistory: true,
549
531
  id: randomId(),
550
532
  messageStatus: 'read',
551
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
533
+ participant: 'agent',
552
534
  service: {
553
535
  meta: { additions: { hideFeedback: 'true' } },
554
536
  name: 'bot',
@@ -604,7 +586,7 @@ const choicePromptMessage = {
604
586
  fromHistory: true,
605
587
  id: randomId(),
606
588
  messageStatus: 'read',
607
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
589
+ participant: 'agent',
608
590
  service: {
609
591
  meta: { additions: {} },
610
592
  name: 'bot',
@@ -628,7 +610,7 @@ const userMessage = {
628
610
  fromHistory: true,
629
611
  id: randomId(),
630
612
  messageStatus: 'read',
631
- participant: 'seamly-client-participant',
613
+ participant: 'user',
632
614
  transactionId: '1cdefea9-7437-4672-bcf8-2c75dc99244c',
633
615
  transactionLast: null,
634
616
  type: 'text',
@@ -647,7 +629,7 @@ const userMessageLong = {
647
629
  fromHistory: true,
648
630
  id: randomId(),
649
631
  messageStatus: 'read',
650
- participant: 'seamly-client-participant',
632
+ participant: 'user',
651
633
  transactionId: '1cdefea9-7437-4672-bcf8-2c75dc99244c',
652
634
  transactionLast: null,
653
635
  type: 'text',
@@ -671,7 +653,7 @@ const fileDownloadAgentMessage = {
671
653
  payload: {
672
654
  ...fileDownloadPayload,
673
655
  fromClient: false,
674
- participant: 'e65fa8dc-97ab-4711-8fec-82bae6461aa2',
656
+ participant: 'agent',
675
657
  id: randomId(),
676
658
  },
677
659
  }
@@ -692,7 +674,7 @@ const fileDownloadUserMessage = {
692
674
  payload: {
693
675
  ...fileDownloadPayload,
694
676
  fromClient: true,
695
- participant: 'seamly-client-participant',
677
+ participant: 'user',
696
678
  id: randomId(),
697
679
  },
698
680
  }
@@ -25,7 +25,18 @@ class SeamlyStyleGuideInstance extends Engine {
25
25
  const translations = await api.getTranslations(
26
26
  this.config.context.locale || 'en-GB',
27
27
  )
28
-
28
+ const { agentParticipant, userParticipant } = await api.getConfig()
29
+ const participants = [
30
+ {
31
+ id: 'user',
32
+ ...userParticipant,
33
+ },
34
+ {
35
+ id: 'agent',
36
+ introduction: 'I am {{name}}',
37
+ ...agentParticipant,
38
+ },
39
+ ]
29
40
  const renderConfig = {
30
41
  ...this.config,
31
42
  customComponents: Object.keys(restComponents).length
@@ -38,6 +49,7 @@ class SeamlyStyleGuideInstance extends Engine {
38
49
  config={renderConfig}
39
50
  styleGuideConfig={this.styleGuideConfig}
40
51
  translations={translations}
52
+ participants={participants}
41
53
  />,
42
54
  this.parentElement,
43
55
  )
@@ -1,15 +1,18 @@
1
1
  import { useSeamlyParticipant } from '../../../hooks/seamly-hooks'
2
2
  import { className } from '../../../../lib/css'
3
3
  import { useConfig } from '../../../../domains/config'
4
+ import { useI18n } from '../../../../domains/i18n'
4
5
 
5
6
  const EventParticipant = ({ eventPayload }) => {
7
+ const { t } = useI18n()
6
8
  const { fromClient, participant: participantId } = eventPayload
7
9
  const participant = useSeamlyParticipant(participantId) || {}
8
- const { messages, defaults } = useConfig()
10
+ const { messages } = useConfig()
9
11
 
10
- const participantName = participant && participant.name
12
+ const participantName = fromClient
13
+ ? t('participants.user.name')
14
+ : participant && participant.name
11
15
  const { showAvatar, showName } = messages[fromClient ? 'user' : 'agent'] || {}
12
- const { userName } = defaults || {}
13
16
 
14
17
  if (!showAvatar && !showName) {
15
18
  return null
@@ -25,11 +28,11 @@ const EventParticipant = ({ eventPayload }) => {
25
28
  )
26
29
  }
27
30
 
28
- const authorName = fromClient ? userName || participantName : participantName
29
-
30
- if (showName && authorName) {
31
+ if (showName) {
31
32
  authorInfo.push(
32
- <span className={className('message__author-name')}>{authorName}</span>,
33
+ <span className={className('message__author-name')}>
34
+ {participantName}
35
+ </span>,
33
36
  )
34
37
  }
35
38
 
@@ -3,10 +3,10 @@ import Mustache from 'mustache'
3
3
  import parseBody from '../../../../lib/parse-body'
4
4
  import EventDivider from '../event-divider'
5
5
  import { useTranslatedEventData } from '../../../../domains/translations'
6
- import { useConfig } from '../../../../domains/config'
6
+ import { useParticipants } from '../../../../domains/config'
7
7
 
8
8
  const Participant = ({ event }) => {
9
- const { agentIcon } = useConfig().defaults || {}
9
+ const { agent } = useParticipants()
10
10
 
11
11
  const { participant } = event.payload
12
12
  const [introduction] = useTranslatedEventData(event)
@@ -21,7 +21,7 @@ const Participant = ({ event }) => {
21
21
  return null
22
22
  }
23
23
 
24
- const avatar = participant.avatar || agentIcon
24
+ const avatar = participant.avatar || agent?.avatar
25
25
 
26
26
  return (
27
27
  <EventDivider
@@ -7,7 +7,7 @@ import {
7
7
  import { className } from '../../../lib/css'
8
8
  import { useI18n } from '../../../domains/i18n'
9
9
  import { useInterrupt } from '../../../domains/interrupt'
10
- import { useConfig } from '../../../domains/config'
10
+ import { useStartChatIcon } from '../../../domains/config'
11
11
  import { useVisibility } from '../../../domains/visibility'
12
12
 
13
13
  const AgentInfo = () => {
@@ -17,12 +17,8 @@ const AgentInfo = () => {
17
17
  const { isOpen } = useVisibility()
18
18
  const currentAgent = useSeamlyCurrentAgent()
19
19
  const { hasInterrupt } = useInterrupt()
20
- const { defaults } = useConfig()
21
-
22
- const { startChatIcon } = defaults || {}
23
-
24
- const avatar = currentAgent && !hasInterrupt ? currentAgent.avatar : null
25
-
20
+ const startChatIcon = useStartChatIcon()
21
+ const src = currentAgent?.avatar ?? startChatIcon
26
22
  const displaySubtitle = hasInterrupt ? '' : subTitle
27
23
 
28
24
  const classNames = ['message-count']
@@ -36,13 +32,13 @@ const AgentInfo = () => {
36
32
  }
37
33
 
38
34
  return (
39
- (avatar || displaySubtitle || !isOpen) && (
35
+ (displaySubtitle || !isOpen) && (
40
36
  <div className={className('agent-info')}>
41
37
  <div className={className('agent-info__graphic')}>
42
- {avatar || startChatIcon ? (
38
+ {src ? (
43
39
  <img
44
- className={className(avatar ? 'avatar' : 'icon')}
45
- src={avatar || startChatIcon}
40
+ className={className(currentAgent?.avatar ? 'avatar' : 'icon')}
41
+ src={src}
46
42
  alt=""
47
43
  />
48
44
  ) : (
@@ -22,7 +22,7 @@ function ChatFrame({ children, interruptComponent: InterruptComponent }) {
22
22
  <>
23
23
  <TranslationsChatStatus />
24
24
  <div className={className('chat__container')}>{getContent()}</div>
25
- <AppOptions />
25
+ {isOpen && <AppOptions />}
26
26
  </>
27
27
  )
28
28
  }
@@ -6,7 +6,7 @@ import {
6
6
  useSkiplinkTargetFocusing,
7
7
  } from '../../../hooks/seamly-hooks'
8
8
  import { useI18n } from '../../../../domains/i18n'
9
- import { useConfig } from '../../../../domains/config'
9
+ import { useStartChatIcon } from '../../../../domains/config'
10
10
  import { useVisibility } from '../../../../domains/visibility'
11
11
  import Icon from '../../layout/icon'
12
12
  import { useInterrupt } from '../../../../domains/interrupt'
@@ -16,15 +16,15 @@ import InOutTransition, {
16
16
  import { useSeamlyHasConversation } from '../../../hooks/seamly-api-hooks'
17
17
 
18
18
  const ButtonIcon = () => {
19
+ const startChatIcon = useStartChatIcon()
19
20
  const currentAgent = useSeamlyCurrentAgent()
20
21
  const { hasInterrupt } = useInterrupt()
21
- const { defaults } = useConfig()
22
- const startChatIcon = defaults?.startChatIcon
23
- const avatar = currentAgent && !hasInterrupt ? currentAgent.avatar : undefined
24
- return avatar || startChatIcon ? (
22
+ const isActiveConversation = currentAgent && !hasInterrupt
23
+ const src = isActiveConversation ? currentAgent.avatar : startChatIcon
24
+ return src ? (
25
25
  <img
26
- className={className(avatar ? 'avatar' : 'icon')}
27
- src={avatar || startChatIcon}
26
+ className={className(isActiveConversation ? 'avatar' : 'icon')}
27
+ src={src}
28
28
  alt=""
29
29
  />
30
30
  ) : (
@@ -200,9 +200,16 @@ const participantReducer = (state, action) => {
200
200
  currentAgent: '',
201
201
  }
202
202
  case SET_PARTICIPANT:
203
- const { participants } = state
204
- const { id, avatar, name, introduction } = action.participant
203
+ // TODO: a) Styleguide only! b) Should be removed after styleguide overhaul.
204
+ if (!state) {
205
+ return {
206
+ participants: {},
207
+ currentAgent: '',
208
+ }
209
+ }
205
210
 
211
+ const { participants } = state || { participants: {} }
212
+ const { id, avatar, name, introduction } = action.participant
206
213
  const oldParticipant = participants[id]
207
214
 
208
215
  const newParticipants = {
@@ -1,22 +0,0 @@
1
- import * as Actions from './actions'
2
- import { seamlyActions } from '../../ui/utils/seamly-utils'
3
-
4
- export default function createMiddleware() {
5
- return ({ dispatch }) =>
6
- (next) =>
7
- (action) => {
8
- const result = next(action)
9
-
10
- switch (action.type) {
11
- case String(Actions.initialize):
12
- case String(Actions.update):
13
- if (action?.config?.defaults?.agentName) {
14
- dispatch({
15
- type: seamlyActions.SET_HEADER_SUB_TITLE,
16
- title: action?.config?.defaults?.agentName,
17
- })
18
- }
19
- }
20
- return result
21
- }
22
- }