wca-designsystem 1.0.58 → 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.58",
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
  ])
@@ -61,7 +61,7 @@ const Template: any = (args: any) => {
61
61
  {...args}
62
62
  messages={messages}
63
63
  isTyping={isTyping}
64
- disabledInputUser={true}
64
+ disabledInputUser={false}
65
65
  setMessages={setMessages}
66
66
  setIsTyping={setIsTyping}
67
67
  respostaUser={respostaUser}
@@ -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
 
@@ -27,22 +32,27 @@ type ChatBotProps = {
27
32
  messages: MensagemChat[]
28
33
  setMessages: React.Dispatch<React.SetStateAction<MensagemChat[]>>
29
34
  disabledInputUser?: boolean
35
+ handleUserTextInput: () => void
36
+ handleOptionClick: (id: string, opcaoId: OpcaoChat) => void
30
37
  }
31
38
 
32
39
  const ChatBot = ({
33
40
  messages,
34
41
  isTyping,
35
42
  setMessages,
36
- setIsTyping,
37
43
  respostaUser,
38
44
  setRespostaUser,
45
+ handleOptionClick,
46
+ handleUserTextInput,
39
47
  disabledInputUser = false,
40
48
  }: ChatBotProps) => {
41
- const handleOptionSelect = (option: any) => {
42
- 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
+ )
43
53
 
44
54
  if (indexWithOptions !== -1) {
45
- const updatedMessages = messages.map((msg: any, i: number) => {
55
+ const updatedMessages = messages.map((msg: MensagemChat, i: number) => {
46
56
  if (i === indexWithOptions) {
47
57
  const { options, ...rest } = msg
48
58
  return rest
@@ -50,18 +60,16 @@ const ChatBot = ({
50
60
  return msg
51
61
  })
52
62
 
53
- updatedMessages.push({ type: 'user', text: option })
63
+ updatedMessages.push({
64
+ idChat: idChat,
65
+ type: 'user',
66
+ text: option.mensagem,
67
+ })
54
68
  setMessages(updatedMessages)
55
- setIsTyping(true)
69
+ handleOptionClick(idChat, option)
56
70
  }
57
71
  }
58
72
 
59
- const handleSend = (innerHtml: string) => {
60
- setMessages((prev: any) => [...prev, { type: 'user', text: innerHtml }])
61
- setRespostaUser('')
62
- setIsTyping(true)
63
- }
64
-
65
73
  return (
66
74
  <ChatWrapper>
67
75
  <ChatContainer>
@@ -72,7 +80,7 @@ const ChatBot = ({
72
80
  )
73
81
  }
74
82
  >
75
- {messages.map((msg: any, index: number) =>
83
+ {messages.map((msg: MensagemChat, index: number) =>
76
84
  msg.options ? (
77
85
  <Message
78
86
  avatarPosition="top-left"
@@ -90,12 +98,12 @@ const ChatBot = ({
90
98
 
91
99
  <Message.Footer>
92
100
  <Flex mt={5} gap={5} direction={'column'}>
93
- {msg.options.map((opt: any, i: number) => (
101
+ {msg.options.map((opt: OpcaoChat, i: number) => (
94
102
  <BotaoChat
95
- key={opt}
96
- onClick={() => handleOptionSelect(opt)}
103
+ key={opt.id}
104
+ onClick={() => handleOptionSelect(msg.idChat, opt)}
97
105
  >
98
- {i + 1}. {opt}
106
+ {i + 1}. {opt.mensagem}
99
107
  </BotaoChat>
100
108
  ))}
101
109
  </Flex>
@@ -120,7 +128,7 @@ const ChatBot = ({
120
128
  <MessageInput
121
129
  value={respostaUser}
122
130
  onChange={(val) => setRespostaUser(val)}
123
- onSend={(msg) => handleSend(msg)}
131
+ onSend={() => handleUserTextInput()}
124
132
  attachButton={false}
125
133
  placeholder={
126
134
  disabledInputUser