@botonic/react 0.37.2-alpha.0 → 0.38.0-alpha.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.
- package/lib/cjs/components/custom-message.js +2 -3
- package/lib/cjs/components/custom-message.js.map +1 -1
- package/lib/cjs/webchat/context/actions.d.ts +1 -0
- package/lib/cjs/webchat/context/actions.js +1 -0
- package/lib/cjs/webchat/context/actions.js.map +1 -1
- package/lib/cjs/webchat/context/index.js +3 -0
- package/lib/cjs/webchat/context/index.js.map +1 -1
- package/lib/cjs/webchat/context/messages-reducer.js +55 -21
- package/lib/cjs/webchat/context/messages-reducer.js.map +1 -1
- package/lib/cjs/webchat/context/types.d.ts +1 -0
- package/lib/cjs/webchat/context/use-webchat.d.ts +1 -0
- package/lib/cjs/webchat/context/use-webchat.js +5 -0
- package/lib/cjs/webchat/context/use-webchat.js.map +1 -1
- package/lib/cjs/webchat/custom-messages/rating/index.js +18 -34
- package/lib/cjs/webchat/custom-messages/rating/index.js.map +1 -1
- package/lib/cjs/webchat/webchat.js +2 -1
- package/lib/cjs/webchat/webchat.js.map +1 -1
- package/lib/esm/components/custom-message.js +2 -3
- package/lib/esm/components/custom-message.js.map +1 -1
- package/lib/esm/webchat/context/actions.d.ts +1 -0
- package/lib/esm/webchat/context/actions.js +1 -0
- package/lib/esm/webchat/context/actions.js.map +1 -1
- package/lib/esm/webchat/context/index.js +3 -0
- package/lib/esm/webchat/context/index.js.map +1 -1
- package/lib/esm/webchat/context/messages-reducer.js +55 -21
- package/lib/esm/webchat/context/messages-reducer.js.map +1 -1
- package/lib/esm/webchat/context/types.d.ts +1 -0
- package/lib/esm/webchat/context/use-webchat.d.ts +1 -0
- package/lib/esm/webchat/context/use-webchat.js +5 -0
- package/lib/esm/webchat/context/use-webchat.js.map +1 -1
- package/lib/esm/webchat/custom-messages/rating/index.js +18 -33
- package/lib/esm/webchat/custom-messages/rating/index.js.map +1 -1
- package/lib/esm/webchat/webchat.js +2 -1
- package/lib/esm/webchat/webchat.js.map +1 -1
- package/package.json +2 -2
- package/src/components/custom-message.tsx +2 -3
- package/src/webchat/context/actions.ts +1 -0
- package/src/webchat/context/index.tsx +3 -0
- package/src/webchat/context/messages-reducer.ts +90 -23
- package/src/webchat/context/types.ts +4 -0
- package/src/webchat/context/use-webchat.ts +14 -0
- package/src/webchat/custom-messages/rating/index.tsx +18 -35
- package/src/webchat/webchat.tsx +2 -0
|
@@ -55,6 +55,10 @@ export interface UseWebchat {
|
|
|
55
55
|
toggleEmojiPicker: (toggle: boolean) => void
|
|
56
56
|
togglePersistentMenu: (toggle: boolean) => void
|
|
57
57
|
toggleWebchat: (toggle: boolean) => void
|
|
58
|
+
updateCustomMessageProps: (
|
|
59
|
+
props: Record<string, any>,
|
|
60
|
+
messageId?: string
|
|
61
|
+
) => void
|
|
58
62
|
updateDevSettings: (settings: DevSettings) => void
|
|
59
63
|
updateHandoff: (handoff: boolean) => void
|
|
60
64
|
updateLastMessageDate: (date: string) => void
|
|
@@ -102,6 +106,15 @@ export function useWebchat(theme?: WebchatTheme): UseWebchat {
|
|
|
102
106
|
payload: message,
|
|
103
107
|
})
|
|
104
108
|
|
|
109
|
+
const updateCustomMessageProps = (
|
|
110
|
+
props: Record<string, any>,
|
|
111
|
+
messageId?: string
|
|
112
|
+
) =>
|
|
113
|
+
webchatDispatch({
|
|
114
|
+
type: WebchatAction.UPDATE_CUSTOM_MESSAGE_PROPS,
|
|
115
|
+
payload: { messageId, props },
|
|
116
|
+
})
|
|
117
|
+
|
|
105
118
|
const updateMessage = (message: WebchatMessage) =>
|
|
106
119
|
webchatDispatch({ type: WebchatAction.UPDATE_MESSAGE, payload: message })
|
|
107
120
|
|
|
@@ -260,6 +273,7 @@ export function useWebchat(theme?: WebchatTheme): UseWebchat {
|
|
|
260
273
|
toggleEmojiPicker,
|
|
261
274
|
togglePersistentMenu,
|
|
262
275
|
toggleWebchat,
|
|
276
|
+
updateCustomMessageProps,
|
|
263
277
|
updateDevSettings,
|
|
264
278
|
updateHandoff,
|
|
265
279
|
updateLastMessageDate,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { INPUT, InputType } from '@botonic/core'
|
|
2
|
-
import merge from 'lodash.merge'
|
|
3
2
|
import React, { useContext, useState } from 'react'
|
|
4
3
|
import { ThemeContext } from 'styled-components'
|
|
5
4
|
|
|
@@ -14,56 +13,40 @@ interface CustomRatingMessageProps {
|
|
|
14
13
|
messageText: string
|
|
15
14
|
buttonText: string
|
|
16
15
|
ratingType: RatingType
|
|
17
|
-
|
|
16
|
+
id?: string // This id not exist in local development
|
|
17
|
+
valueSent?: number
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const CustomRatingMessage: React.FC<CustomRatingMessageProps> = props => {
|
|
21
|
-
const { payloads, messageText, buttonText, ratingType } = props
|
|
22
|
-
const {
|
|
21
|
+
const { payloads, messageText, buttonText, ratingType, id, valueSent } = props
|
|
22
|
+
const { updateCustomMessageProps, sendInput } = useContext(WebchatContext)
|
|
23
23
|
|
|
24
24
|
const theme = useContext(ThemeContext)
|
|
25
25
|
const color = theme?.brand?.color ?? ''
|
|
26
26
|
|
|
27
|
-
const [ratingValue, setRatingValue] = useState(
|
|
28
|
-
props.json?.valueSent ? props.json.valueSent : -1
|
|
29
|
-
)
|
|
27
|
+
const [ratingValue, setRatingValue] = useState(valueSent ? valueSent : -1)
|
|
30
28
|
const [showRating, setShowRating] = useState(true)
|
|
31
29
|
|
|
32
30
|
const ratingChanged = (newRating: number) => {
|
|
33
31
|
setRatingValue(newRating)
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
const updateMessageJSON = (messageId?: string) => {
|
|
37
|
-
if (messageId) {
|
|
38
|
-
const messageToUpdate = webchatState.messagesJSON.filter(m => {
|
|
39
|
-
return m.id === messageId
|
|
40
|
-
})[0]
|
|
41
|
-
const messageInfo = {
|
|
42
|
-
data: {
|
|
43
|
-
json: {
|
|
44
|
-
valueSent: ratingValue,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
}
|
|
48
|
-
const updatedMsg = merge(messageToUpdate, messageInfo)
|
|
49
|
-
updateMessage(updatedMsg)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
34
|
const handleButtonSend = () => {
|
|
54
|
-
if (ratingValue
|
|
55
|
-
setShowRating(false)
|
|
35
|
+
if (ratingValue === -1) return
|
|
56
36
|
|
|
57
|
-
|
|
37
|
+
const json = {
|
|
38
|
+
valueSent: ratingValue,
|
|
39
|
+
}
|
|
40
|
+
updateCustomMessageProps(json, id)
|
|
58
41
|
|
|
59
|
-
|
|
42
|
+
setShowRating(false)
|
|
43
|
+
const payload = payloads[ratingValue - 1]
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
void sendInput(input)
|
|
45
|
+
const input = {
|
|
46
|
+
type: INPUT.POSTBACK as InputType,
|
|
47
|
+
payload,
|
|
66
48
|
}
|
|
49
|
+
void sendInput(input)
|
|
67
50
|
}
|
|
68
51
|
|
|
69
52
|
const disabled = ratingValue === -1
|
|
@@ -77,10 +60,10 @@ const CustomRatingMessage: React.FC<CustomRatingMessageProps> = props => {
|
|
|
77
60
|
onRatingChange={ratingChanged}
|
|
78
61
|
ratingValue={ratingValue}
|
|
79
62
|
ratingType={ratingType}
|
|
80
|
-
valueSent={
|
|
63
|
+
valueSent={valueSent}
|
|
81
64
|
/>
|
|
82
65
|
</MessageBubble>
|
|
83
|
-
{!props
|
|
66
|
+
{!props?.valueSent && showRating && (
|
|
84
67
|
<Button
|
|
85
68
|
autodisable={true}
|
|
86
69
|
disabled={disabled}
|
package/src/webchat/webchat.tsx
CHANGED
|
@@ -86,6 +86,7 @@ const Webchat = forwardRef<WebchatRef | null, WebchatProps>((props, ref) => {
|
|
|
86
86
|
toggleEmojiPicker,
|
|
87
87
|
togglePersistentMenu,
|
|
88
88
|
toggleWebchat,
|
|
89
|
+
updateCustomMessageProps,
|
|
89
90
|
updateDevSettings,
|
|
90
91
|
updateHandoff,
|
|
91
92
|
updateLastMessageDate,
|
|
@@ -650,6 +651,7 @@ const Webchat = forwardRef<WebchatRef | null, WebchatProps>((props, ref) => {
|
|
|
650
651
|
toggleEmojiPicker,
|
|
651
652
|
togglePersistentMenu,
|
|
652
653
|
toggleCoverComponent,
|
|
654
|
+
updateCustomMessageProps,
|
|
653
655
|
updateLatestInput,
|
|
654
656
|
updateMessage,
|
|
655
657
|
updateReplies,
|