wca-designsystem 1.0.59 → 1.0.60

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,5 +1,5 @@
1
1
  {
2
- "version": "1.0.59",
2
+ "version": "1.0.60",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -32,10 +32,10 @@ const Template: any = (args: any) => {
32
32
  type: 'bot',
33
33
  text: ' Legal! De que etapa prefere falar primero?',
34
34
  options: [
35
- 'Ciclos da Crítica',
36
- 'Acompanhamento da Crítica',
37
- 'Execução Crítica',
38
- 'Outra',
35
+ { id: 1, mensagem: 'Ciclos da Crítica' },
36
+ { id: 2, mensagem: 'Acompanhamento da Crítica' },
37
+ { id: 3, mensagem: 'Execução Crítica' },
38
+ { id: 4, mensagem: 'Outra' },
39
39
  ],
40
40
  },
41
41
  ])
@@ -12,10 +12,15 @@ import { Flex } from '@mantine/core'
12
12
  import icon from '../../../assets/imagens/WCA/wca_inteligencia_comercial_logo.png'
13
13
  import '@chatscope/chat-ui-kit-styles/dist/default/styles.min.css'
14
14
 
15
+ export type OpcaoChat = {
16
+ id: number
17
+ mensagem: string
18
+ }
19
+
15
20
  export type MensagemChat = {
16
21
  idChat: string
17
22
  text: string
18
- options?: string[]
23
+ options?: OpcaoChat[]
19
24
  type: 'bot' | 'user'
20
25
  }
21
26
 
@@ -28,7 +33,7 @@ type ChatBotProps = {
28
33
  setMessages: React.Dispatch<React.SetStateAction<MensagemChat[]>>
29
34
  disabledInputUser?: boolean
30
35
  handleUserTextInput: () => void
31
- handleOptionClick: (id: string, opcaoId: string) => void
36
+ handleOptionClick: (id: string, opcaoId: OpcaoChat) => void
32
37
  }
33
38
 
34
39
  const ChatBot = ({
@@ -41,11 +46,13 @@ const ChatBot = ({
41
46
  handleUserTextInput,
42
47
  disabledInputUser = false,
43
48
  }: ChatBotProps) => {
44
- const handleOptionSelect = (idChat: string, option: any) => {
45
- const indexWithOptions = messages.findIndex((msg: any) => msg.options)
49
+ const handleOptionSelect = (idChat: string, option: OpcaoChat) => {
50
+ const indexWithOptions = messages.findIndex(
51
+ (msg: MensagemChat) => msg.options
52
+ )
46
53
 
47
54
  if (indexWithOptions !== -1) {
48
- const updatedMessages = messages.map((msg: any, i: number) => {
55
+ const updatedMessages = messages.map((msg: MensagemChat, i: number) => {
49
56
  if (i === indexWithOptions) {
50
57
  const { options, ...rest } = msg
51
58
  return rest
@@ -53,7 +60,11 @@ const ChatBot = ({
53
60
  return msg
54
61
  })
55
62
 
56
- updatedMessages.push({ type: 'user', text: option })
63
+ updatedMessages.push({
64
+ idChat: idChat,
65
+ type: 'user',
66
+ text: option.mensagem,
67
+ })
57
68
  setMessages(updatedMessages)
58
69
  handleOptionClick(idChat, option)
59
70
  }
@@ -69,7 +80,7 @@ const ChatBot = ({
69
80
  )
70
81
  }
71
82
  >
72
- {messages.map((msg: any, index: number) =>
83
+ {messages.map((msg: MensagemChat, index: number) =>
73
84
  msg.options ? (
74
85
  <Message
75
86
  avatarPosition="top-left"
@@ -87,12 +98,12 @@ const ChatBot = ({
87
98
 
88
99
  <Message.Footer>
89
100
  <Flex mt={5} gap={5} direction={'column'}>
90
- {msg.options.map((opt: any, i: number) => (
101
+ {msg.options.map((opt: OpcaoChat, i: number) => (
91
102
  <BotaoChat
92
- key={opt}
103
+ key={opt.id}
93
104
  onClick={() => handleOptionSelect(msg.idChat, opt)}
94
105
  >
95
- {i + 1}. {opt}
106
+ {i + 1}. {opt.mensagem}
96
107
  </BotaoChat>
97
108
  ))}
98
109
  </Flex>