pager-widget 0.2.0 → 0.2.1

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.
@@ -41,10 +41,14 @@ option {
41
41
 
42
42
  `;
43
43
 
44
- const InputConverter = ({ formData, conversationId,workspace, widgetId, setFormSubmit, setSourceState }) => {
45
-
46
-
47
-
44
+ const InputConverter = ({
45
+ formData,
46
+ conversationId,
47
+ workspace,
48
+ widgetId,
49
+ setFormSubmit,
50
+ setSourceState,
51
+ }) => {
48
52
  const [errors, setErrors] = useState({});
49
53
 
50
54
  // State to hold form data
@@ -53,9 +57,15 @@ const InputConverter = ({ formData, conversationId,workspace, widgetId, setFormS
53
57
  formData.form_data.form_template.map((field) => [field.field_id, ""])
54
58
  )
55
59
  );
56
- const [selectedCountry, setSelectedCountry] = useState({flag:null,country:"select a country"})
57
- const [isDropDownOpen, setIsDropDownOpen] = useState(false)
58
- const [hoveredCountry, setHoveredCountry] = useState(null)
60
+
61
+
62
+ const [selectedCountry, setSelectedCountry] = useState({
63
+ flag: null,
64
+ country: "select a country",
65
+ });
66
+ const [isDropDownOpen, setIsDropDownOpen] = useState(false);
67
+ const [hoveredCountry, setHoveredCountry] = useState(null);
68
+ const [searchQuery, setSearchQuery] = useState("");
59
69
  // Handle input changes
60
70
  const handleChange = (e) => {
61
71
  const { id, value } = e.target;
@@ -65,82 +75,91 @@ const InputConverter = ({ formData, conversationId,workspace, widgetId, setFormS
65
75
  }));
66
76
  };
67
77
 
68
- // Handle form submission
78
+
79
+
80
+ console.log("errors obj", Object.values(errors));
81
+
82
+
69
83
  const handleSubmit = (e) => {
70
84
  e.preventDefault();
71
-
85
+
72
86
  const newErrors = {};
73
- formData.form_data.form_template.map((field) => {
74
-
75
- if (field.is_mandatory && field.field_type == "country"? selectedCountry.country =="select a country"?true:false: !formValues[field.field_id]) {
76
- newErrors[field.field_id] = "This field is required.";
77
- }
78
-
79
- if (Object.keys(newErrors).length > 0) {
80
- setErrors(newErrors);
81
- return;
82
- }
83
- setErrors({});
84
- // localStorage.setItem("leadform", JSON.stringify({ widget: widgetId, submission: true }));
85
-
86
- const submittedValues = formData.form_data.form_template.map((field) => ({
87
- ...field,
88
- value: field.field_type == "country"? selectedCountry.country:formValues[field.field_id], // Attach user input to the corresponding field
89
- }));
90
- const submittedData = {
91
- form_id: formData.form_data.form_id,
92
- conversation_id: conversationId,
93
- lead_data: {
94
- name: formData.form_data.name,
95
- fields: submittedValues,
96
- ws: formData.form_data.ws,
97
- user_consent: true,
98
- },
99
- type:"lead"
100
- };
101
-
102
-
103
- axios
104
- .post(
105
- // "https://dev.pagergpt.ai/widget/harisw/f54c92b4-27c9-4260-9c02-cd00640e0cb4/",
106
- `https://dev.pagergpt.ai/wgt-hook/${workspace}/${widgetId}/lead`,
107
- submittedData,
108
- {
109
- withCredentials: true,
87
+
88
+ formData.form_data.form_template.forEach((field) => {
89
+ if (field.is_mandatory) {
90
+ if (field.field_type === "country") {
91
+ if (selectedCountry.country === "select a country") {
92
+ newErrors[field.field_id] = `${field.name} is required`;
110
93
  }
111
- )
112
- .then((res) => {
113
-
114
-
115
- setSourceState(res.data.source_id)
116
-
117
-
118
- })
119
- .catch((err) => {
120
- setFormSubmit(true)
121
-
122
- });
123
-
94
+ } else if (!formValues[field.field_id]?.trim()) {
95
+ newErrors[field.field_id] = `${field.name} is required`;
96
+ }
97
+ }
124
98
  });
125
-
126
- // Map form values back to the original structure
99
+
100
+ if (Object.keys(newErrors).length > 0) {
101
+ setErrors(newErrors);
102
+ return;
103
+ }
104
+
105
+ setErrors({});
106
+
107
+ const submittedValues = formData.form_data.form_template.map((field) => ({
108
+ ...field,
109
+ value: field.field_type === "country" ? selectedCountry.country : formValues[field.field_id],
110
+ }));
111
+
112
+ const submittedData = {
113
+ form_id: formData.form_data.form_id,
114
+ conversation_id: conversationId,
115
+ lead_data: {
116
+ name: formData.form_data.name,
117
+ fields: submittedValues,
118
+ ws: formData.form_data.ws,
119
+ user_consent: true,
120
+ },
121
+ type: "lead",
122
+ };
123
+
124
+ axios
125
+ .post(`https://dev.pagergpt.ai/wgt-hook/${workspace}/${widgetId}/lead`, submittedData, {
126
+ withCredentials: true,
127
+ })
128
+ .then((res) => {
129
+ setSourceState(res.data.source_id);
130
+ })
131
+ .catch((err) => {
132
+ setFormSubmit(true);
133
+ });
127
134
  };
128
135
 
136
+
137
+ const filteredCountries = countries.filter((country) =>
138
+ country.name.toLowerCase().includes(searchQuery.toLowerCase())
139
+ );
140
+
129
141
  const handleSelectDropdown = (flag, country) => {
130
- setSelectedCountry({flag,country})
131
- setIsDropDownOpen(false)
132
- }
142
+ setSelectedCountry({ flag, country });
143
+ setIsDropDownOpen(false);
144
+
145
+ // Update formValues with the selected country
146
+ setFormValues((prev) => ({
147
+ ...prev,
148
+ SYS_country: country, // Adjust this based on your actual field_id
149
+ }));
150
+ };
133
151
  return (
134
152
  <div style={{ padding: "20px", maxWidth: "600px", margin: "0 auto" }}>
135
- <h2>{formData.form_data.name}</h2>
136
- <form onSubmit={handleSubmit}>
153
+ <form onSubmit={handleSubmit} style={{marginTop: "5px"}}>
137
154
  {formData.form_data.form_template.map((field) => (
138
- <div key={field.id} style={{ marginBottom: "15px" }}>
155
+ <div key={field.id} style={{ marginBottom: "10px" }}>
156
+
139
157
  <label
140
158
  htmlFor={field.field_id}
141
- style={{ display: "block", marginBottom: "5px" }}
159
+ style={{ display: "block", marginBottom: "5px", fontSize: "14px", fontWeight: "500", lineHeight:"20px" }}
142
160
  >
143
- {field.display_name}
161
+
162
+ {field.dispaly_name ? field.dispaly_name : field?.name}
144
163
  {field.is_mandatory && (
145
164
  <span style={{ color: "red", marginLeft: "5px" }}>*</span>
146
165
  )}
@@ -154,7 +173,6 @@ const InputConverter = ({ formData, conversationId,workspace, widgetId, setFormS
154
173
  <textarea
155
174
  id={field.field_id}
156
175
  placeholder={field.placeholder}
157
- // required={field.is_mandatory}
158
176
  value={formValues[field.field_id]}
159
177
  onChange={handleChange}
160
178
  style={{
@@ -162,7 +180,7 @@ const InputConverter = ({ formData, conversationId,workspace, widgetId, setFormS
162
180
  border: "1px solid var(--k300, #D0D5DD)",
163
181
  background: "#FFF",
164
182
  outline: "none",
165
- height: "52px",
183
+ height: "130px",
166
184
  width: "100%",
167
185
  }}
168
186
  ></textarea>
@@ -186,57 +204,111 @@ const InputConverter = ({ formData, conversationId,workspace, widgetId, setFormS
186
204
  // </option>
187
205
  // ))}
188
206
  // </SelectWrapper>
189
- <div style={{
190
- width:"100%",
191
- position:"relative",
192
-
193
- }}>
194
- <span style={{
195
- borderRadius: "8px",
196
- border: "1px solid var(--k300, #D0D5DD)",
197
- background: "#FFF",
198
- padding:"10px 16px",
199
- cursor:"pointer",
200
- width: "91%",
201
- display: "flex",
202
- justifyContent:"space-between",
203
- alignItems:"center"
204
-
207
+ <div
208
+ style={{
209
+ width: "100%",
210
+ position: "relative",
205
211
  }}
206
- onClick={()=> setIsDropDownOpen(!isDropDownOpen)}
207
- >{selectedCountry.flag&&selectedCountry.flag} &nbsp; {selectedCountry.country} <span style={{rotate:isDropDownOpen?"180deg":"0deg"}}><svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 20 20" fill="none">
208
- <path d="M6.66675 8.45312C7.5518 9.67136 8.58931 10.7625 9.75185 11.6983C9.89789 11.8158 10.1023 11.8158 10.2483 11.6983C11.4109 10.7625 12.4484 9.67136 13.3334 8.45312" stroke="#344054" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>
209
- </svg></span></span>
210
- {isDropDownOpen && <div style={{
211
- display:"flex",
212
- flexDirection:"column",
213
- gap:"8px",
214
- border:"1px solid #cbc8c8fa",
215
- padding: "12px 6px",
216
- position:"absolute",
217
- width:"96%",
218
- bottom:"84px",
219
- background:"white",
220
- borderRadius:"12px",
221
- left:"0px",
222
- height:"150px",
223
- overflowY:"scroll"
224
- }}>
225
- {countries &&countries.map((country,index)=>(
226
- <span style={{
227
- padding:"12px 8px",
228
- borderRadius:"8px",
229
- cursor:"pointer",
230
- background:hoveredCountry === index?"#e9e5e5":"white"
231
- }} onClick={()=>handleSelectDropdown(country.flag, country.name)}
232
- onMouseOver={()=>setHoveredCountry(index)}
233
- onMouseLeave={()=>setHoveredCountry(null)}
234
- >{country.flag} &nbsp; {country.name}</span>
235
- ))}
236
- </div>}
237
-
212
+ >
213
+ <span
214
+ style={{
215
+ borderRadius: "8px",
216
+ border: "1px solid var(--k300, #D0D5DD)",
217
+ background: "#FFF",
218
+ padding: "10px 35px 10px 2px",
219
+ cursor: "pointer",
220
+ width: "91%",
221
+ height: "15px",
222
+ display: "flex",
223
+ justifyContent: "space-between",
224
+ alignItems: "center",
225
+ }}
226
+ onClick={() => setIsDropDownOpen(!isDropDownOpen)}
227
+ >
228
+ {selectedCountry.flag && selectedCountry.flag} &nbsp;{" "}
229
+ {selectedCountry.country}{" "}
230
+ <span style={{ rotate: isDropDownOpen ? "180deg" : "0deg" }}>
231
+ <svg
232
+ xmlns="http://www.w3.org/2000/svg"
233
+ width="28"
234
+ height="28"
235
+ viewBox="0 0 20 20"
236
+ fill="none"
237
+ >
238
+ <path
239
+ d="M6.66675 8.45312C7.5518 9.67136 8.58931 10.7625 9.75185 11.6983C9.89789 11.8158 10.1023 11.8158 10.2483 11.6983C11.4109 10.7625 12.4484 9.67136 13.3334 8.45312"
240
+ stroke="#344054"
241
+ stroke-width="1.4"
242
+ stroke-linecap="round"
243
+ stroke-linejoin="round"
244
+ />
245
+ </svg>
246
+ </span>
247
+ </span>
248
+ {isDropDownOpen && (
249
+ <div
250
+ style={{
251
+ display: "flex",
252
+ flexDirection: "column",
253
+ gap: "8px",
254
+ border: "1px solid #cbc8c8fa",
255
+ padding: "12px 6px",
256
+ position: "absolute",
257
+ width: "96%",
258
+ top: "38px",
259
+ background: "white",
260
+ borderRadius: "12px",
261
+ left: "0px",
262
+ height: "200px",
263
+ overflowY: "scroll",
264
+ }}
265
+ >
266
+ {/* Search input inside dropdown */}
267
+ <input
268
+ type="text"
269
+ placeholder="Search country..."
270
+ value={searchQuery}
271
+ onChange={(e) => setSearchQuery(e.target.value)}
272
+ style={{
273
+ width: "95%",
274
+ padding: "8px",
275
+ marginBottom: "8px",
276
+ border: "1px solid #D0D5DD",
277
+ borderRadius: "8px",
278
+ outline: "none",
279
+ }}
280
+ />
281
+
282
+ {filteredCountries.length > 0 ? (
283
+ filteredCountries.map((country, index) => (
284
+ <span
285
+ key={country.name}
286
+ style={{
287
+ padding: "8px 8px",
288
+ borderRadius: "8px",
289
+ cursor: "pointer",
290
+ background:
291
+ hoveredCountry === index ? "#e9e5e5" : "white",
292
+ }}
293
+ onClick={() =>
294
+ handleSelectDropdown(country.flag, country.name)
295
+ }
296
+ onMouseOver={() => setHoveredCountry(index)}
297
+ onMouseLeave={() => setHoveredCountry(null)}
298
+ >
299
+ {country.flag} &nbsp; {country.name}
300
+ </span>
301
+ ))
302
+ ) : (
303
+ <span style={{ padding: "10px", textAlign: "center" }}>
304
+ No results found
305
+ </span>
306
+ )}
307
+ </div>
308
+ )}
238
309
  </div>
239
- ) : (
310
+ ) :
311
+ (
240
312
  <InputWrapper
241
313
  id={field.field_id}
242
314
  type={
@@ -246,16 +318,17 @@ const InputConverter = ({ formData, conversationId,workspace, widgetId, setFormS
246
318
  // required={field.is_mandatory}
247
319
  value={formValues[field.field_id]}
248
320
  onChange={handleChange}
249
- // style={{
250
- // borderRadius: "8px",
251
- // border: "1px solid var(--k300, #D0D5DD)",
252
- // background: "#FFF",
253
- // outline: "none",
254
- // height: "52px",
255
- // width: "100%",
256
- // }}
321
+ style={{
322
+ borderRadius: "8px",
323
+ border: "1px solid var(--k300, #D0D5DD)",
324
+ background: "#FFF",
325
+ outline: "none",
326
+ height: "40px",
327
+ width: "100%",
328
+ }}
257
329
  />
258
- )}
330
+ )
331
+ }
259
332
  </div>
260
333
  ))}
261
334
  <button
@@ -267,6 +340,7 @@ const InputConverter = ({ formData, conversationId,workspace, widgetId, setFormS
267
340
  border: "none",
268
341
  borderRadius: "4px",
269
342
  cursor: "pointer",
343
+ width: "100%"
270
344
  }}
271
345
  >
272
346
  Submit
@@ -278,164 +352,4 @@ const InputConverter = ({ formData, conversationId,workspace, widgetId, setFormS
278
352
 
279
353
  export default InputConverter;
280
354
 
281
- // import React, { useState } from "react";
282
- // import { countries } from "country-codes-flags-phone-codes";
283
- // import axios from "axios";
284
-
285
- // console.log("country", countries);
286
- // const InputConverter = ({ formData, conversationId }) => {
287
- // const [errors, setErrors] = useState({});
288
- // // State to hold form data
289
- // const [formValues, setFormValues] = useState(
290
- // Object.fromEntries(
291
- // formData.form_data.form_template.map((field) => [field.field_id, ""])
292
- // )
293
- // );
294
-
295
- // // Handle input changes
296
- // const handleChange = (e) => {
297
- // const { id, value } = e.target;
298
- // setFormValues((prev) => ({
299
- // ...prev,
300
- // [id]: value,
301
- // }));
302
- // };
303
-
304
- // // Handle form submission
305
- // const handleSubmit = (e) => {
306
- // e.preventDefault();
307
-
308
- // const newErrors = {};
309
- // formData.form_data.form_template.map((field) => {
310
- // console.log("fields",field.is_mandatory,formValues[field.field_id])
311
- // if (field.is_mandatory && !formValues[field.field_id]) {
312
- // newErrors[field.field_id] = "This field is required.";
313
- // }
314
- // if (Object.keys(newErrors).length > 0) {
315
- // setErrors(newErrors);
316
- // return;
317
- // }
318
- // setErrors({});
319
- // const submittedValues = formData.form_data.form_template.map((field) => ({
320
- // ...field,
321
- // value: formValues[field.field_id], // Attach user input to the corresponding field
322
- // }));
323
- // const submittedData = {
324
- // form_id: formData.form_data.form_id,
325
- // conversation_id: conversationId,
326
- // lead_data: {
327
- // name: formData.form_data.name,
328
- // fields: submittedValues,
329
- // ws: formData.form_data.ws,
330
- // user_consent: true,
331
- // },
332
- // };
333
- // axios.post('https://dev.pagergpt.ai/widget/harisw/f54c92b4-27c9-4260-9c02-cd00640e0cb4/',submittedData).then((res)=>{
334
- // console.log("Form Submitted", submittedData);
335
- // })
336
- // .catch((err)=> {
337
- // console.log("error submitting form", err)
338
- // })
339
-
340
- // });
341
-
342
- // // Map form values back to the original structure
343
-
344
- // };
345
-
346
- // console.log("errors", errors);
347
- // return (
348
- // <div style={{ padding: "20px", maxWidth: "600px", margin: "0 auto" }}>
349
-
350
- // <h2>{formData.form_data.name}</h2>
351
- // <form onSubmit={handleSubmit}>
352
- // {formData.form_data.form_template.map((field) => (
353
- // <div key={field.id} style={{ marginBottom: "15px" }}>
354
- // <label
355
- // htmlFor={field.field_id}
356
- // style={{ display: "block", marginBottom: "5px" }}
357
- // >
358
- // {field.display_name}
359
- // {field.is_mandatory && (
360
- // <span style={{ color: "red", marginLeft: "5px" }}>*</span>
361
- // )}
362
- // </label>
363
- // {errors[field.field_id] && (
364
- // <div style={{ color: "red", marginBottom: "5px" }}>
365
- // {errors[field.field_id]}
366
- // </div>
367
- // )}
368
- // {field.field_type === "long_text" ? (
369
- // <textarea
370
- // id={field.field_id}
371
- // placeholder={field.placeholder}
372
- // // required={field.is_mandatory}
373
- // value={formValues[field.field_id]}
374
- // onChange={handleChange}
375
- // style={{
376
- // width: "100%",
377
- // padding: "8px",
378
- // border: "1px solid #ccc",
379
- // borderRadius: "4px",
380
- // minHeight: "100px",
381
- // }}
382
- // ></textarea>
383
- // ) : field.field_type === "country" ? (
384
- // <select
385
- // id={field.field_id}
386
- // // required={field.is_mandatory}
387
- // value={formValues[field.field_id]}
388
- // onChange={handleChange}
389
- // style={{
390
- // width: "100%",
391
- // padding: "8px",
392
- // border: "1px solid #ccc",
393
- // borderRadius: "4px",
394
- // }}
395
- // >
396
- // <option value="">Select a country</option>
397
- // {countries.map((country) => (
398
- // <option key={country.name} value={country.name}>
399
- // {country.flag} {country.name}
400
- // </option>
401
- // ))}
402
- // </select>
403
- // ) : (
404
- // <input
405
- // id={field.field_id}
406
- // type={
407
- // field.field_type === "short_text" ? "text" : field.field_type
408
- // }
409
- // placeholder={field.placeholder}
410
- // // required={field.is_mandatory}
411
- // value={formValues[field.field_id]}
412
- // onChange={handleChange}
413
- // style={{
414
- // width: "100%",
415
- // padding: "8px",
416
- // border: "1px solid #ccc",
417
- // borderRadius: "4px",
418
- // }}
419
- // />
420
- // )}
421
- // </div>
422
- // ))}
423
- // <button
424
- // type="submit"
425
- // style={{
426
- // padding: "10px 20px",
427
- // backgroundColor: "#007BFF",
428
- // color: "#fff",
429
- // border: "none",
430
- // borderRadius: "4px",
431
- // cursor: "pointer",
432
- // }}
433
- // >
434
- // Submit
435
- // </button>
436
- // </form>
437
- // </div>
438
- // );
439
- // };
440
355
 
441
- // export default InputConverter;