pager-widget 0.2.6 → 0.2.7
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/App.jsx +1149 -981
- package/ConsentPopup.jsx +265 -94
- package/Dropdown.jsx +36 -23
- package/InputConverter.jsx +45 -42
- package/dist/lib.js +3144 -10
- package/md/assistant_md.js +32 -22
- package/package.json +2 -1
package/ConsentPopup.jsx
CHANGED
|
@@ -8,13 +8,162 @@ import {
|
|
|
8
8
|
windowHeight,
|
|
9
9
|
} from "react-device-detect";
|
|
10
10
|
import axios from "axios";
|
|
11
|
+
import styled from "styled-components";
|
|
11
12
|
|
|
12
13
|
import { useState, useEffect } from "react";
|
|
13
14
|
import AssistantMd, {
|
|
14
15
|
evalNormalOrJoinText,
|
|
15
16
|
parseUrlAndString,
|
|
16
|
-
} from "./md/assistant_md"
|
|
17
|
+
} from "./md/assistant_md";
|
|
17
18
|
import { EndPointContext } from "./useEndpoint";
|
|
19
|
+
|
|
20
|
+
const Container = styled.div`
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
align-items: flex-start;
|
|
24
|
+
gap: 10px;
|
|
25
|
+
margin-bottom: 12px;
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
const MessageContainer = styled.div`
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
align-items: flex-start;
|
|
32
|
+
gap: 6px;
|
|
33
|
+
width: 100%;
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
const BotHeader = styled.div`
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
gap: 10px;
|
|
40
|
+
padding: 0 26px;
|
|
41
|
+
width: 100%;
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
const BotLabel = styled.span`
|
|
45
|
+
font-family: "Inter", sans-serif;
|
|
46
|
+
font-size: 12px;
|
|
47
|
+
font-weight: 500;
|
|
48
|
+
color: #020618;
|
|
49
|
+
line-height: 18px;
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
const MessageBubbleContainer = styled.div`
|
|
53
|
+
display: flex;
|
|
54
|
+
align-items: flex-start;
|
|
55
|
+
gap: 4px;
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
const AvatarContainer = styled.div`
|
|
59
|
+
width: 26px;
|
|
60
|
+
height: 26px;
|
|
61
|
+
border-radius: 50%;
|
|
62
|
+
display: flex;
|
|
63
|
+
align-items: center;
|
|
64
|
+
justify-content: center;
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const AvatarImage = styled.div`
|
|
68
|
+
width: 24px;
|
|
69
|
+
height: 24px;
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
const MessageCard = styled.div`
|
|
73
|
+
background: #f4f4f5;
|
|
74
|
+
border-radius: 8px;
|
|
75
|
+
padding: 14px;
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
const MessageText = styled.p`
|
|
79
|
+
font-family: "Inter", sans-serif;
|
|
80
|
+
font-size: 14px;
|
|
81
|
+
font-weight: 400;
|
|
82
|
+
color: #020618;
|
|
83
|
+
line-height: 20px;
|
|
84
|
+
margin-bottom: 10px;
|
|
85
|
+
margin-top: 0px;
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
const SuggestionContainer = styled.div`
|
|
89
|
+
display: flex;
|
|
90
|
+
flex-direction: column;
|
|
91
|
+
gap: 10px;
|
|
92
|
+
width: 100%;
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
const SuggestionButton = styled.button`
|
|
96
|
+
width: 100%;
|
|
97
|
+
padding: 6px;
|
|
98
|
+
background: white;
|
|
99
|
+
border: 1px solid #e4e4e7;
|
|
100
|
+
border-radius: 6px;
|
|
101
|
+
color: #314158;
|
|
102
|
+
font-family: "Inter", sans-serif;
|
|
103
|
+
font-size: 14px;
|
|
104
|
+
font-weight: 500;
|
|
105
|
+
line-height: 20px;
|
|
106
|
+
cursor: pointer;
|
|
107
|
+
|
|
108
|
+
&:hover {
|
|
109
|
+
background: #ebefff;
|
|
110
|
+
border: 1px solid #4b2fff;
|
|
111
|
+
color: #4b2fff;
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
const BottomContainer = styled.div`
|
|
116
|
+
display: flex;
|
|
117
|
+
width: 289px;
|
|
118
|
+
align-items: flex-start;
|
|
119
|
+
gap: 4px;
|
|
120
|
+
`;
|
|
121
|
+
|
|
122
|
+
const Timestamp = styled.div`
|
|
123
|
+
display: flex;
|
|
124
|
+
align-items: center;
|
|
125
|
+
gap: 10px;
|
|
126
|
+
padding: 0 8px 0 30px;
|
|
127
|
+
flex: 1;
|
|
128
|
+
`;
|
|
129
|
+
|
|
130
|
+
const TimestampText = styled.span`
|
|
131
|
+
font-family: "Inter", sans-serif;
|
|
132
|
+
font-size: 12px;
|
|
133
|
+
font-weight: 400;
|
|
134
|
+
color: #45556c;
|
|
135
|
+
line-height: 18px;
|
|
136
|
+
`;
|
|
137
|
+
|
|
138
|
+
const ReactionContainer = styled.div`
|
|
139
|
+
display: flex;
|
|
140
|
+
align-items: center;
|
|
141
|
+
gap: 4px;
|
|
142
|
+
padding-right: 8px;
|
|
143
|
+
`;
|
|
144
|
+
|
|
145
|
+
const ReactionButton = styled.button`
|
|
146
|
+
width: 22px;
|
|
147
|
+
height: 22px;
|
|
148
|
+
padding: 4px;
|
|
149
|
+
background: #f4f4f5;
|
|
150
|
+
border-radius: 50%;
|
|
151
|
+
border: none;
|
|
152
|
+
cursor: pointer;
|
|
153
|
+
display: flex;
|
|
154
|
+
align-items: center;
|
|
155
|
+
justify-content: center;
|
|
156
|
+
|
|
157
|
+
&:hover {
|
|
158
|
+
background: #e4e4e7;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
svg {
|
|
162
|
+
width: 14px;
|
|
163
|
+
height: 14px;
|
|
164
|
+
}
|
|
165
|
+
`;
|
|
166
|
+
|
|
18
167
|
const ConsentPopup = ({
|
|
19
168
|
formData,
|
|
20
169
|
conversationId,
|
|
@@ -24,51 +173,47 @@ const ConsentPopup = ({
|
|
|
24
173
|
isVisible,
|
|
25
174
|
setIsVisible,
|
|
26
175
|
setSourceState,
|
|
27
|
-
userDetails
|
|
28
|
-
|
|
176
|
+
userDetails,
|
|
29
177
|
}) => {
|
|
30
|
-
|
|
31
178
|
const [deviceLocation, setDeviceLocation] = useState("");
|
|
32
179
|
|
|
33
180
|
// const consentOutput = JSON.parse(widget?.consent_data)
|
|
34
181
|
|
|
35
|
-
const endpoint = useContext(EndPointContext)
|
|
182
|
+
const endpoint = useContext(EndPointContext);
|
|
36
183
|
console.log("ConsentPopup Endpoint:", endpoint);
|
|
37
|
-
console.log("consent widget", widget?.accent_color)
|
|
184
|
+
console.log("consent widget", widget?.accent_color);
|
|
38
185
|
const handleCheckboxChange = (event) => {
|
|
39
186
|
setIsVisible(event.target.checked);
|
|
40
187
|
};
|
|
41
188
|
useEffect(() => {
|
|
42
189
|
if (navigator.geolocation) {
|
|
43
|
-
navigator.geolocation.getCurrentPosition(
|
|
44
|
-
(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
setDeviceLocation(
|
|
190
|
+
navigator.geolocation.getCurrentPosition((position) => {
|
|
191
|
+
setDeviceLocation({
|
|
192
|
+
lat: position.coords.latitude,
|
|
193
|
+
long: position.coords.longitude,
|
|
194
|
+
});
|
|
195
|
+
axios
|
|
196
|
+
.get(
|
|
197
|
+
`https://nominatim.openstreetmap.org/reverse?format=json&lat=${position.coords.latitude}&lon=${position.coords.longitude}`
|
|
198
|
+
)
|
|
199
|
+
.then((res) => {
|
|
200
|
+
setDeviceLocation(res.data.address?.country);
|
|
54
201
|
})
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
);
|
|
202
|
+
.catch((err) => {
|
|
203
|
+
setDeviceLocation("");
|
|
204
|
+
});
|
|
205
|
+
});
|
|
59
206
|
} else {
|
|
60
|
-
setDeviceLocation("")
|
|
207
|
+
setDeviceLocation("");
|
|
61
208
|
console.error("Geolocation is not supported by this browser.");
|
|
62
209
|
}
|
|
63
210
|
}, []);
|
|
64
211
|
|
|
65
212
|
const handleSubmit = () => {
|
|
66
|
-
|
|
67
|
-
|
|
68
213
|
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
69
214
|
const language = navigator.language;
|
|
70
215
|
|
|
71
|
-
console.log("url location",window.location)
|
|
216
|
+
console.log("url location", window.location);
|
|
72
217
|
const systemDetails = [
|
|
73
218
|
{ field_id: "SYS_browser", value: browserName },
|
|
74
219
|
{ field_id: "SYS_browser_os", value: osName },
|
|
@@ -87,8 +232,8 @@ const ConsentPopup = ({
|
|
|
87
232
|
// Correctly updated location
|
|
88
233
|
{
|
|
89
234
|
field_id: "SYS_From_Page",
|
|
90
|
-
value:
|
|
91
|
-
}
|
|
235
|
+
value: window.location.origin,
|
|
236
|
+
},
|
|
92
237
|
];
|
|
93
238
|
|
|
94
239
|
const submissionPayload = {
|
|
@@ -124,86 +269,112 @@ const ConsentPopup = ({
|
|
|
124
269
|
});
|
|
125
270
|
};
|
|
126
271
|
|
|
127
|
-
|
|
272
|
+
const suggestionOptions = [
|
|
273
|
+
{ title: "Yes", func: handleSubmit },
|
|
274
|
+
{ title: "No", func: () => {} },
|
|
275
|
+
];
|
|
276
|
+
|
|
277
|
+
console.log("url location", window.location.origin);
|
|
128
278
|
|
|
129
279
|
return (
|
|
130
|
-
<div
|
|
131
|
-
{
|
|
280
|
+
<div
|
|
281
|
+
style={{
|
|
132
282
|
display: "flex",
|
|
133
283
|
flexDirection: "column",
|
|
134
|
-
justifyContent: "
|
|
135
|
-
height:"100%",
|
|
136
|
-
width:"100%"
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}}>
|
|
163
|
-
<AssistantMd mdText={widget?.consent_data}/>
|
|
164
|
-
</div>
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
{/* <AssistantMd mdText={{
|
|
168
|
-
|
|
169
|
-
"type": "join",
|
|
170
|
-
"lhs": {
|
|
171
|
-
"type": "text",
|
|
172
|
-
"value": "Hi haha"
|
|
173
|
-
},
|
|
174
|
-
"rhs": {
|
|
175
|
-
"type": "bold",
|
|
176
|
-
"value": {
|
|
177
|
-
"type": "text",
|
|
178
|
-
"value": "Hello "
|
|
179
|
-
}
|
|
180
|
-
}
|
|
284
|
+
justifyContent: "flex-start",
|
|
285
|
+
height: "100%",
|
|
286
|
+
width: "100%",
|
|
287
|
+
}}
|
|
288
|
+
>
|
|
289
|
+
<Container>
|
|
290
|
+
<MessageContainer>
|
|
291
|
+
<BotHeader>
|
|
292
|
+
<BotLabel>{widget && widget.name}</BotLabel>
|
|
293
|
+
</BotHeader>
|
|
294
|
+
<MessageBubbleContainer>
|
|
295
|
+
<AvatarContainer>
|
|
296
|
+
<AvatarImage>
|
|
297
|
+
<img
|
|
298
|
+
alt={"logo"}
|
|
299
|
+
src={
|
|
300
|
+
(widget && widget.logo_url) ||
|
|
301
|
+
"https://workativ-asssistant-widget-images.s3.amazonaws.com/chat_logo.png"
|
|
302
|
+
}
|
|
303
|
+
/>
|
|
304
|
+
</AvatarImage>
|
|
305
|
+
</AvatarContainer>
|
|
306
|
+
<MessageCard>
|
|
307
|
+
<MessageText>
|
|
308
|
+
<AssistantMd mdText={widget?.consent_data} />
|
|
309
|
+
</MessageText>
|
|
181
310
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
311
|
+
<SuggestionContainer>
|
|
312
|
+
{suggestionOptions.map((option, index) => (
|
|
313
|
+
<SuggestionButton onClick={option?.func} key={index}>
|
|
314
|
+
{option?.title}
|
|
315
|
+
</SuggestionButton>
|
|
316
|
+
))}
|
|
317
|
+
</SuggestionContainer>
|
|
318
|
+
</MessageCard>
|
|
319
|
+
</MessageBubbleContainer>
|
|
320
|
+
<BottomContainer>
|
|
321
|
+
<Timestamp>
|
|
322
|
+
<TimestampText>Just now</TimestampText>
|
|
323
|
+
|
|
324
|
+
</Timestamp>
|
|
325
|
+
<ReactionContainer></ReactionContainer>
|
|
326
|
+
</BottomContainer>
|
|
327
|
+
</MessageContainer>
|
|
328
|
+
</Container>
|
|
329
|
+
{/* <div
|
|
330
|
+
style={{
|
|
331
|
+
display: "flex",
|
|
332
|
+
alignItems: "start",
|
|
333
|
+
paddingBottom: "16px",
|
|
334
|
+
gap: "8px",
|
|
335
|
+
}}
|
|
336
|
+
>
|
|
337
|
+
<input
|
|
338
|
+
type="checkbox"
|
|
339
|
+
id="consentCheckbox"
|
|
340
|
+
checked={isVisible}
|
|
341
|
+
onChange={handleCheckboxChange}
|
|
342
|
+
/>
|
|
343
|
+
{console.log("output struct 2", widget.consent_data)}
|
|
344
|
+
<div
|
|
345
|
+
style={{
|
|
346
|
+
fontSize: "16px",
|
|
347
|
+
fontWeight: "400",
|
|
348
|
+
lineHeight: "24px",
|
|
349
|
+
fontFamily: "Inter, Open Sans",
|
|
350
|
+
}}
|
|
351
|
+
>
|
|
352
|
+
<AssistantMd mdText={widget?.consent_data} />
|
|
353
|
+
</div>
|
|
186
354
|
</div>
|
|
187
|
-
<div
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
355
|
+
<div
|
|
356
|
+
style={{
|
|
357
|
+
width: "100%",
|
|
358
|
+
paddingTop: "16px",
|
|
359
|
+
borderTop: "1px solid lightgrey",
|
|
360
|
+
display: "flex",
|
|
361
|
+
justifyContent: "center",
|
|
362
|
+
}}
|
|
363
|
+
>
|
|
195
364
|
<button
|
|
196
|
-
|
|
197
365
|
disabled={isVisible == false ? true : false}
|
|
198
|
-
style={{
|
|
366
|
+
style={{
|
|
367
|
+
...popupStyles.button,
|
|
368
|
+
width: "90%",
|
|
369
|
+
background: isVisible === false ? "#E2E8F0" : widget?.accent_color,
|
|
370
|
+
}}
|
|
199
371
|
onClick={handleSubmit}
|
|
200
372
|
>
|
|
201
373
|
Submit
|
|
202
374
|
</button>
|
|
203
|
-
</div>
|
|
375
|
+
</div> */}
|
|
204
376
|
</div>
|
|
205
377
|
);
|
|
206
|
-
|
|
207
378
|
};
|
|
208
379
|
|
|
209
380
|
const popupStyles = {
|
|
@@ -244,7 +415,7 @@ const popupStyles = {
|
|
|
244
415
|
cursor: "pointer",
|
|
245
416
|
backgroundColor: "#007bff",
|
|
246
417
|
color: "white",
|
|
247
|
-
width: "90%"
|
|
418
|
+
width: "90%",
|
|
248
419
|
},
|
|
249
420
|
};
|
|
250
421
|
|
package/Dropdown.jsx
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
2
|
import { countries } from "country-codes-flags-phone-codes";
|
|
3
3
|
import styled from "styled-components";
|
|
4
|
+
import { SearchIcon } from "./App";
|
|
4
5
|
|
|
5
6
|
const DropdownWrapper = styled.div`
|
|
6
7
|
width: 100%;
|
|
7
8
|
position: relative;
|
|
8
|
-
|
|
9
9
|
`;
|
|
10
10
|
const DropdownContent = styled.span`
|
|
11
11
|
border-radius: 8px;
|
|
12
|
-
border: 1px solid
|
|
13
|
-
|
|
12
|
+
border: 1px solid
|
|
13
|
+
${({ error }) =>
|
|
14
|
+
error === "true" ? "var(--red-300, #FFA2A2)" : "transparent"};
|
|
14
15
|
font-size: 14px;
|
|
15
16
|
font-style: normal;
|
|
16
17
|
font-weight: 400;
|
|
17
18
|
background: #fff;
|
|
18
|
-
padding: 10px
|
|
19
|
+
padding: 10px 10px 10px 16px;
|
|
19
20
|
cursor: pointer;
|
|
20
|
-
width:
|
|
21
|
-
height:
|
|
21
|
+
width: 90%;
|
|
22
|
+
height: 14px;
|
|
22
23
|
display: flex;
|
|
23
24
|
justify-content: space-between;
|
|
24
25
|
align-items: center;
|
|
@@ -39,17 +40,16 @@ const DropdownList = styled.div`
|
|
|
39
40
|
height: 250px;
|
|
40
41
|
`;
|
|
41
42
|
const DropdownInput = styled.input`
|
|
42
|
-
width:
|
|
43
|
-
padding-left:
|
|
44
|
-
|
|
43
|
+
width: 94%;
|
|
44
|
+
padding-left: 16px;
|
|
45
|
+
margin-left: 3%;
|
|
46
|
+
margin-top: 7px;
|
|
47
|
+
border-radius: 8px;
|
|
48
|
+
border: 1px solid #d0d5dd;
|
|
45
49
|
outline: none;
|
|
46
|
-
|
|
47
|
-
border-left: none;
|
|
48
|
-
border-right: none;
|
|
50
|
+
font-size: 14px;
|
|
49
51
|
background: transparent;
|
|
50
|
-
height:
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
height: 36px;
|
|
53
53
|
`;
|
|
54
54
|
const DropdownNode = styled.span`
|
|
55
55
|
padding: 8px 8px;
|
|
@@ -57,7 +57,7 @@ const DropdownNode = styled.span`
|
|
|
57
57
|
cursor: pointer;
|
|
58
58
|
`;
|
|
59
59
|
|
|
60
|
-
const Dropdown = ({error,updateFieldValue, fieldId}) => {
|
|
60
|
+
const Dropdown = ({ error, updateFieldValue, fieldId }) => {
|
|
61
61
|
const [selectedCountry, setSelectedCountry] = useState({
|
|
62
62
|
flag: null,
|
|
63
63
|
country: "Select a country",
|
|
@@ -73,16 +73,17 @@ const Dropdown = ({error,updateFieldValue, fieldId}) => {
|
|
|
73
73
|
const handleSelectDropdown = (flag, country) => {
|
|
74
74
|
setSelectedCountry({ flag, country });
|
|
75
75
|
setIsDropDownOpen(false);
|
|
76
|
-
updateFieldValue(fieldId, country)
|
|
77
|
-
|
|
76
|
+
updateFieldValue(fieldId, country);
|
|
78
77
|
};
|
|
79
78
|
|
|
80
79
|
return (
|
|
81
80
|
<>
|
|
82
|
-
|
|
83
81
|
<DropdownWrapper>
|
|
84
|
-
<DropdownContent
|
|
85
|
-
{
|
|
82
|
+
<DropdownContent
|
|
83
|
+
error={error}
|
|
84
|
+
onClick={() => setIsDropDownOpen(!isDropDownOpen)}
|
|
85
|
+
>
|
|
86
|
+
{selectedCountry.flag && selectedCountry.flag}{" "}
|
|
86
87
|
{selectedCountry.country}{" "}
|
|
87
88
|
<span style={{ rotate: isDropDownOpen ? "180deg" : "0deg" }}>
|
|
88
89
|
<svg
|
|
@@ -104,7 +105,20 @@ const Dropdown = ({error,updateFieldValue, fieldId}) => {
|
|
|
104
105
|
</DropdownContent>
|
|
105
106
|
{isDropDownOpen && (
|
|
106
107
|
<DropdownList>
|
|
107
|
-
<
|
|
108
|
+
<div style={{ position: "relative" }}>
|
|
109
|
+
<DropdownInput
|
|
110
|
+
onChange={(e) => setSearchQuery(e.target.value)}
|
|
111
|
+
placeholder="Search..."
|
|
112
|
+
/>
|
|
113
|
+
<SearchIcon
|
|
114
|
+
style={{
|
|
115
|
+
color: "#a7aaaf",
|
|
116
|
+
position: "absolute",
|
|
117
|
+
right: "7%",
|
|
118
|
+
top: "15px",
|
|
119
|
+
}}
|
|
120
|
+
/>
|
|
121
|
+
</div>
|
|
108
122
|
<div
|
|
109
123
|
style={{
|
|
110
124
|
height: "220px",
|
|
@@ -139,7 +153,6 @@ const Dropdown = ({error,updateFieldValue, fieldId}) => {
|
|
|
139
153
|
)}
|
|
140
154
|
</DropdownWrapper>
|
|
141
155
|
</>
|
|
142
|
-
|
|
143
156
|
);
|
|
144
157
|
};
|
|
145
158
|
|