@bigbinary/neeto-form-frontend 4.4.6 → 4.4.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.
Files changed (58) hide show
  1. package/README.md +4 -1
  2. package/app/javascript/src/translations/en.json +10 -1
  3. package/package.json +1 -5
  4. package/types.d.ts +1 -0
  5. package/dist/BuildForm.js +0 -3035
  6. package/dist/BuildForm.js.map +0 -1
  7. package/dist/ExternalForm.js +0 -639
  8. package/dist/ExternalForm.js.map +0 -1
  9. package/dist/NeetoFormProvider.js +0 -11
  10. package/dist/NeetoFormProvider.js.map +0 -1
  11. package/dist/Submission.js +0 -2832
  12. package/dist/Submission.js.map +0 -1
  13. package/dist/UrlBuilder.js +0 -309
  14. package/dist/UrlBuilder.js.map +0 -1
  15. package/dist/buildForm-CgofRtEN.js +0 -38
  16. package/dist/buildForm-CgofRtEN.js.map +0 -1
  17. package/dist/buildForm-D-epUrZG.js +0 -35
  18. package/dist/buildForm-D-epUrZG.js.map +0 -1
  19. package/dist/cjs/BuildForm.js +0 -3056
  20. package/dist/cjs/BuildForm.js.map +0 -1
  21. package/dist/cjs/ExternalForm.js +0 -641
  22. package/dist/cjs/ExternalForm.js.map +0 -1
  23. package/dist/cjs/NeetoFormProvider.js +0 -13
  24. package/dist/cjs/NeetoFormProvider.js.map +0 -1
  25. package/dist/cjs/Submission.js +0 -2834
  26. package/dist/cjs/Submission.js.map +0 -1
  27. package/dist/cjs/UrlBuilder.js +0 -311
  28. package/dist/cjs/UrlBuilder.js.map +0 -1
  29. package/dist/cjs/hooks.js +0 -33
  30. package/dist/cjs/hooks.js.map +0 -1
  31. package/dist/cjs/index.js +0 -112
  32. package/dist/cjs/index.js.map +0 -1
  33. package/dist/constants-BNfHPNOx.js +0 -493
  34. package/dist/constants-BNfHPNOx.js.map +0 -1
  35. package/dist/constants-CfUZ9B6N.js +0 -512
  36. package/dist/constants-CfUZ9B6N.js.map +0 -1
  37. package/dist/hooks.js +0 -20
  38. package/dist/hooks.js.map +0 -1
  39. package/dist/index-0m1EzLFY.js +0 -51
  40. package/dist/index-0m1EzLFY.js.map +0 -1
  41. package/dist/index-y4GiXx7o.js +0 -43
  42. package/dist/index-y4GiXx7o.js.map +0 -1
  43. package/dist/index.js +0 -94
  44. package/dist/index.js.map +0 -1
  45. package/dist/main.css +0 -2
  46. package/dist/main.css.map +0 -1
  47. package/dist/useFormSubmission-Cx63P761.js +0 -22
  48. package/dist/useFormSubmission-Cx63P761.js.map +0 -1
  49. package/dist/useFormSubmission-DyS5Dm1q.js +0 -24
  50. package/dist/useFormSubmission-DyS5Dm1q.js.map +0 -1
  51. package/dist/utils-C9nDMm4c.js +0 -2652
  52. package/dist/utils-C9nDMm4c.js.map +0 -1
  53. package/dist/utils-DEBFghm4.js +0 -2683
  54. package/dist/utils-DEBFghm4.js.map +0 -1
  55. package/dist/yup-CMEoabdy.js +0 -1076
  56. package/dist/yup-CMEoabdy.js.map +0 -1
  57. package/dist/yup-Dx1WK2_p.js +0 -995
  58. package/dist/yup-Dx1WK2_p.js.map +0 -1
@@ -1,2652 +0,0 @@
1
- import { useEffect, useState, useImperativeHandle, memo, Fragment as Fragment$1 } from 'react';
2
- import { useFormikContext, useField, Field as Field$1, FastField } from 'formik';
3
- import { isPresent, isNotEmpty, findBy, filterBy, findById, isNotPresent, hyphenate, noop, toLabelAndValue, getRandomInt, randomPick, slugify, notEqualsDeep } from '@bigbinary/neeto-cist';
4
- import { i as isFunction, b as isEmptyValues, f as fieldWithFallback } from './index-y4GiXx7o.js';
5
- import { dayjs, getFromLocalStorage, setToLocalStorage, removeFromLocalStorage, withEventTargetValue, buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
6
- import { parsePhoneNumber } from 'libphonenumber-js';
7
- import { pick, mergeRight, omit, isEmpty, max, when, is, last, includes, __, mergeLeft, isNil, clamp, prop, trim, map, zipObj, identity, pluck, values, pipe, dec, equals } from 'ramda';
8
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
9
- import EditorContent from '@bigbinary/neeto-editor/EditorContent';
10
- import { Q as QUESTION_TYPES, C as CAPTCHA_TYPES, E as EMAIL_VERIFICATIONS_CREATE_URL, j as EMAIL_VERIFICATIONS_VERIFY_URL } from './constants-BNfHPNOx.js';
11
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
12
- import Plus from '@bigbinary/neeto-icons/Plus';
13
- import Button from '@bigbinary/neetoui/Button';
14
- import NeetoUIMultiEmailInput from '@bigbinary/neetoui/MultiEmailInput';
15
- import { useTranslation, Trans } from 'react-i18next';
16
- import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
17
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
18
- import _regeneratorRuntime from '@babel/runtime/regenerator';
19
- import { isEditorEmpty } from '@bigbinary/neeto-editor/utils';
20
- import { validation, PhoneNumberInput } from '@bigbinary/neeto-molecules/PhoneNumber';
21
- import i18next from 'i18next';
22
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
23
- import { a as QUESTION_KIND, P as PARENTHESES_REGEX, R as RATING_VALUES, E as EMAIL_REGEX, S as SCHEMA_LESS_QUESTION_KINDS, c as SIX_DIGIT_NUMBER_REGEX, A as ADDRESS_FIELD_TYPES, d as ADDRESS_FIELD_WIDTHS, e as LABEL_FIELDS, g as generateArray, D as DEFAULT_CHOICE_QUESTION_ATTRIBUTES, f as RADIO_DESELECT_KEYS, h as RATING_OPTIONS, I as ICONS_MAP } from './yup-Dx1WK2_p.js';
24
- import _toArray from '@babel/runtime/helpers/toArray';
25
- import * as yup from 'yup';
26
- import classnames from 'classnames';
27
- import Select from '@bigbinary/neetoui/Select';
28
- import Input from '@bigbinary/neetoui/Input';
29
- import { useUpdateEffect, useStateWithDependency, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
30
- import Refresh from '@bigbinary/neeto-icons/Refresh';
31
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
32
- import { globalProps } from '@bigbinary/neeto-commons-frontend/initializers';
33
- import ReCAPTCHA from 'react-google-recaptcha';
34
- import Checkbox from '@bigbinary/neetoui/Checkbox';
35
- import DatePicker from '@bigbinary/neetoui/DatePicker';
36
- import Toastr from '@bigbinary/neetoui/Toastr';
37
- import { useMutation } from '@tanstack/react-query';
38
- import axios from 'axios';
39
- import CheckCircle from '@bigbinary/neeto-icons/CheckCircle';
40
- import Spinner from '@bigbinary/neetoui/Spinner';
41
- import NeetoUICallout from '@bigbinary/neetoui/Callout';
42
- import { FileUpload } from '@bigbinary/neeto-molecules/FileUpload';
43
- import Label from '@bigbinary/neetoui/Label';
44
- import Radio from '@bigbinary/neetoui/Radio';
45
- import Image from '@bigbinary/neeto-icons/Image';
46
- import NeetoEditor from '@bigbinary/neeto-editor/Editor';
47
- import Textarea from '@bigbinary/neetoui/Textarea';
48
-
49
- var clientI18nInstance = i18next.cloneInstance();
50
-
51
- var clearLocalStorageValues = function clearLocalStorageValues(key) {
52
- try {
53
- localStorage.removeItem(key);
54
- } catch (error) {
55
- // eslint-disable-next-line no-console
56
- console.error(error);
57
- }
58
- };
59
- var setWithExpiry = function setWithExpiry(key, value) {
60
- var expireInDays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
61
- var expiryDate = dayjs().add(expireInDays, "day").toDate();
62
- var item = {
63
- value: value,
64
- localStorageExpiry: expiryDate.getTime()
65
- };
66
- try {
67
- localStorage.setItem(key, JSON.stringify(item));
68
- } catch (error) {
69
- // eslint-disable-next-line no-console
70
- console.error(error);
71
- }
72
- };
73
- var getWithExpiry = function getWithExpiry(key) {
74
- try {
75
- var itemStr = localStorage.getItem(key);
76
- if (!itemStr) {
77
- return null;
78
- }
79
- var item = JSON.parse(itemStr);
80
- var now = new Date();
81
- if (now.getTime() > item.localStorageExpiry) {
82
- localStorage.removeItem(key);
83
- return null;
84
- }
85
- return item.value;
86
- } catch (error) {
87
- // eslint-disable-next-line no-console
88
- console.error(error);
89
- return null;
90
- }
91
- };
92
-
93
- var FormikWrap = function FormikWrap(_ref) {
94
- var onError = _ref.onError,
95
- children = _ref.children,
96
- formId = _ref.formId,
97
- preserveValues = _ref.preserveValues,
98
- onValuesChange = _ref.onValuesChange,
99
- dataUpdateCount = _ref.dataUpdateCount;
100
- var _useFormikContext = useFormikContext(),
101
- errors = _useFormikContext.errors,
102
- touched = _useFormikContext.touched,
103
- isValid = _useFormikContext.isValid,
104
- isSubmitting = _useFormikContext.isSubmitting,
105
- values = _useFormikContext.values,
106
- validateForm = _useFormikContext.validateForm;
107
- var revalidate = function revalidate() {
108
- return isPresent(errors) && validateForm();
109
- };
110
- useEffect(function () {
111
- revalidate();
112
- }, [clientI18nInstance.language, dataUpdateCount]);
113
- var syncValuesWithLocalStorage = function syncValuesWithLocalStorage() {
114
- return preserveValues && !isEmptyValues(values) && setWithExpiry("".concat(formId, "/values"), values);
115
- };
116
- useEffect(function () {
117
- syncValuesWithLocalStorage();
118
- onValuesChange && onValuesChange(values);
119
- }, [values, formId, preserveValues]);
120
- useEffect(function () {
121
- if (isSubmitting || isValid) return;
122
-
123
- // include only touched fields
124
- var touchedErrors = Object.keys(errors).filter(function (key) {
125
- return touched[key];
126
- }).reduce(function (obj, key) {
127
- obj[key] = errors[key];
128
- return obj;
129
- }, {});
130
- if (isFunction(onError)) onError(touchedErrors);
131
- }, [isValid, isSubmitting]);
132
- return children;
133
- };
134
-
135
- var RESEND_DELAY = 120;
136
- var ONE_SECOND = 1000;
137
- var EMAIL_VERIFICATION_FIELD_NAME_PREFIX = "verificationCode";
138
- var EMAIL_VERIFICATION_PREFIX = "neeto_form_nano_email_verification_details_";
139
- var EMAIL_VERIFICATION_KEYS = {
140
- EMAIL: "email",
141
- TOKEN: "token",
142
- VERIFIED: "verified",
143
- CODE: "code",
144
- CODE_SENT_AT: "code-sent-at"
145
- };
146
- var CALLOUT_STYLES = {
147
- WARNING: "warning",
148
- ERROR: "danger"
149
- };
150
- var DEFAULT_CALLOUT_DETAILS = {
151
- message: "",
152
- style: ""
153
- };
154
-
155
- var getEmailVerificationKey = function getEmailVerificationKey(formId) {
156
- return "".concat(EMAIL_VERIFICATION_PREFIX, "-").concat(formId);
157
- };
158
- var getEmailVerificationDetails = function getEmailVerificationDetails(formId) {
159
- return getFromLocalStorage(getEmailVerificationKey(formId)) || {};
160
- };
161
- var buildVerificationFieldName = function buildVerificationFieldName(questionId) {
162
- return "".concat(EMAIL_VERIFICATION_FIELD_NAME_PREFIX, "-").concat(questionId);
163
- };
164
- var getLastVerificationCodeSentAt = function getLastVerificationCodeSentAt(formId, questionId) {
165
- var codeSentAt = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.CODE_SENT_AT);
166
- return Number(codeSentAt) || 0;
167
- };
168
- var storeLastVerificationCodeSentAt = function storeLastVerificationCodeSentAt(formId, questionId) {
169
- var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
170
- return setEmailVerificationDetail(formId, questionId, _defineProperty({}, EMAIL_VERIFICATION_KEYS.CODE_SENT_AT, Date.now() - offset));
171
- };
172
- var getRemainingTime = function getRemainingTime(formId, questionId) {
173
- var elapsedTime = Math.floor((Date.now() - getLastVerificationCodeSentAt(formId, questionId)) / ONE_SECOND);
174
- return max(RESEND_DELAY - elapsedTime, 0);
175
- };
176
- var getEmailVerificationDetail = function getEmailVerificationDetail(formId, questionId) {
177
- var _questionDetails$keys;
178
- var allDetails = getEmailVerificationDetails(formId);
179
- var questionDetails = allDetails[questionId] || {};
180
- for (var _len = arguments.length, keys = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
181
- keys[_key - 2] = arguments[_key];
182
- }
183
- return keys.length === 1 ? (_questionDetails$keys = questionDetails[keys[0]]) !== null && _questionDetails$keys !== void 0 ? _questionDetails$keys : "" : pick(keys, allDetails);
184
- };
185
- var setEmailVerificationDetail = function setEmailVerificationDetail(formId, questionId, data) {
186
- var storageKey = getEmailVerificationKey(formId);
187
- var allDetails = getEmailVerificationDetails(formId);
188
- allDetails[questionId] = mergeRight(allDetails[questionId] || {}, data);
189
- setToLocalStorage(storageKey, allDetails);
190
- };
191
- var removeEmailVerificationDetail = function removeEmailVerificationDetail(formId, questionId) {
192
- var storageKey = getEmailVerificationKey(formId);
193
- var allDetails = getEmailVerificationDetails(formId);
194
- for (var _len2 = arguments.length, keys = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
195
- keys[_key2 - 2] = arguments[_key2];
196
- }
197
- allDetails[questionId] = omit(keys, allDetails[questionId]);
198
- if (isEmpty(allDetails[questionId])) delete allDetails[questionId];
199
- isEmpty(allDetails) ? removeFromLocalStorage(storageKey) : setToLocalStorage(storageKey, allDetails);
200
- };
201
- var clearEmailVerificationDetails = function clearEmailVerificationDetails(formId) {
202
- removeFromLocalStorage(getEmailVerificationKey(formId));
203
- };
204
-
205
- var t$1 = clientI18nInstance.t;
206
- var getInvalidFieldError = function getInvalidFieldError(label) {
207
- return t$1("neetoForm.error.invalidField", {
208
- label: label
209
- });
210
- };
211
- var getRequiredFieldError = function getRequiredFieldError(label) {
212
- return t$1("neetoForm.error.requiredField", {
213
- label: label
214
- });
215
- };
216
- var getSelectMinError = function getSelectMinError() {
217
- var entity = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : t$1("neetoForm.common.option");
218
- return t$1("neetoForm.error.minOneEntity", {
219
- entity: entity
220
- });
221
- };
222
- var getInvalidTypeError = function getInvalidTypeError(label, type) {
223
- return t$1("neetoForm.error.invalidType", {
224
- label: label,
225
- type: type
226
- });
227
- };
228
-
229
- function ownKeys$i(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
230
- function _objectSpread$i(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$i(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$i(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
231
- var resolveQueryParamValue = when(is(Array), last);
232
- var toEmailValues = function toEmailValues() {
233
- var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
234
- return values.map(function (value) {
235
- return {
236
- label: value,
237
- value: value,
238
- valid: true
239
- };
240
- });
241
- };
242
- var getPhoneNumberFromUrl = function getPhoneNumberFromUrl(fieldCodes, fieldCode) {
243
- var _resolveQueryParamVal;
244
- var countryCode = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".country")]);
245
- var phoneNumber = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".number")]);
246
- var phoneNumberWithCountryCode = (_resolveQueryParamVal = resolveQueryParamValue(fieldCodes[fieldCode])) === null || _resolveQueryParamVal === void 0 ? void 0 : _resolveQueryParamVal.replace(PARENTHESES_REGEX, "");
247
- if (phoneNumberWithCountryCode) return phoneNumberWithCountryCode;
248
- if (!countryCode || !phoneNumber) return undefined;
249
- var formattedValue = getPhoneData(phoneNumber, countryCode);
250
- if (!formattedValue) return undefined;
251
- return formattedValue.formatInternational();
252
- };
253
- var getOptionFromURL = function getOptionFromURL(_ref) {
254
- var _findBy;
255
- var optionsAttributes = _ref.optionsAttributes,
256
- fieldCodes = _ref.fieldCodes,
257
- fieldCode = _ref.fieldCode;
258
- var preFillOption = resolveQueryParamValue(fieldCodes[fieldCode]);
259
- return (_findBy = findBy({
260
- label: preFillOption
261
- }, optionsAttributes)) === null || _findBy === void 0 ? void 0 : _findBy.id;
262
- };
263
- var getMultipleOptionsFromURL = function getMultipleOptionsFromURL(_ref2) {
264
- var optionsAttributes = _ref2.optionsAttributes,
265
- fieldCodes = _ref2.fieldCodes,
266
- fieldCode = _ref2.fieldCode;
267
- var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
268
- if (!fieldCodeValue) return new Array(optionsAttributes.length).fill(false);
269
- var allOptions = fieldCodeValue.split(",").map(trim);
270
- return optionsAttributes.map(function (option) {
271
- return allOptions.includes(option.label);
272
- });
273
- };
274
- var getStarRatingOrOpinionScaleFromUrl = function getStarRatingOrOpinionScaleFromUrl(_ref3) {
275
- var minValue = _ref3.minValue,
276
- maxValue = _ref3.maxValue,
277
- fieldCodes = _ref3.fieldCodes,
278
- fieldCode = _ref3.fieldCode;
279
- var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
280
- var rating = parseInt(fieldCodeValue);
281
- return isNil(rating) || isNaN(rating) ? "" : clamp(minValue, maxValue, rating);
282
- };
283
- var getAdditionalGuestsFromUrl = function getAdditionalGuestsFromUrl(_ref4) {
284
- var fieldCodes = _ref4.fieldCodes,
285
- fieldCode = _ref4.fieldCode;
286
- var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
287
- var allEmails = fieldCodeValue === null || fieldCodeValue === void 0 ? void 0 : fieldCodeValue.split(",");
288
- if (!allEmails) return [];
289
- return allEmails.map(function (email) {
290
- return {
291
- label: email.trim(),
292
- value: email.trim(),
293
- valid: EMAIL_REGEX.test(email.trim())
294
- };
295
- });
296
- };
297
- var getRatingFromUrl = function getRatingFromUrl(_ref5) {
298
- var fieldCodes = _ref5.fieldCodes,
299
- fieldCode = _ref5.fieldCode;
300
- var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
301
- var allowedValues = Object.values(RATING_VALUES).map(prop("value"));
302
- return allowedValues.includes(fieldCodeValue) ? fieldCodeValue : "";
303
- };
304
- var getNumberFromUrl = function getNumberFromUrl(_ref6) {
305
- var fieldCodes = _ref6.fieldCodes,
306
- fieldCode = _ref6.fieldCode,
307
- kind = _ref6.kind;
308
- var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
309
- var parsedValue = kind === QUESTION_KIND.INTEGER.value ? parseInt(fieldCodeValue) : parseFloat(fieldCodeValue);
310
- return parsedValue || "";
311
- };
312
- var getNameFromUrl = function getNameFromUrl(_ref7, fieldCodes) {
313
- var isSplitMode = _ref7.isSplitMode,
314
- fieldCode = _ref7.fieldCode;
315
- var fullName = resolveQueryParamValue(fieldCodes[fieldCode]) || "";
316
- if (!isSplitMode) return {
317
- fullName: fullName
318
- };
319
- var firstName = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".first_name")]) || "";
320
- var lastName = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".last_name")]) || "";
321
- if (isPresent(firstName) || isPresent(lastName)) {
322
- return {
323
- firstName: firstName,
324
- lastName: lastName
325
- };
326
- }
327
- if (isPresent(fullName)) {
328
- var _fullName$trim$split = fullName.trim().split(/\s+/),
329
- _fullName$trim$split2 = _toArray(_fullName$trim$split),
330
- computedFirstName = _fullName$trim$split2[0],
331
- remainingParts = _fullName$trim$split2.slice(1);
332
- return {
333
- firstName: computedFirstName,
334
- lastName: remainingParts.join(" ")
335
- };
336
- }
337
- return {
338
- firstName: firstName,
339
- lastName: lastName
340
- };
341
- };
342
- var buildEmailVerificationEntries = function buildEmailVerificationEntries() {
343
- var questions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
344
- var emailQuestionsRequiringVerification = filterBy({
345
- kind: QUESTION_TYPES.EMAIL,
346
- isVerificationEnabled: true
347
- }, questions);
348
- var fieldNames = map(function (_ref8) {
349
- var id = _ref8.id;
350
- return buildVerificationFieldName(id);
351
- }, emailQuestionsRequiringVerification);
352
- return zipObj(fieldNames, Array(fieldNames.length).fill(""));
353
- };
354
- var getLabel = function getLabel(label, isRequired) {
355
- return isRequired ? "".concat(label, "*") : label;
356
- };
357
- var generateInitValues = function generateInitValues(_ref9) {
358
- var questions = _ref9.questions,
359
- _ref9$initialValues = _ref9.initialValues,
360
- initialValues = _ref9$initialValues === void 0 ? [] : _ref9$initialValues,
361
- _ref9$localValues = _ref9.localValues,
362
- localValues = _ref9$localValues === void 0 ? {} : _ref9$localValues,
363
- _ref9$fieldCodes = _ref9.fieldCodes,
364
- fieldCodes = _ref9$fieldCodes === void 0 ? {} : _ref9$fieldCodes;
365
- var initValues = {};
366
- var valuesMap = {};
367
- if (initialValues) {
368
- valuesMap = initialValues.reduce(function (acc, answer) {
369
- return _objectSpread$i(_objectSpread$i({}, acc), {}, _defineProperty({}, answer.questionId, {
370
- value: answer.value,
371
- optionIds: answer.optionIds
372
- }));
373
- }, {});
374
- }
375
- questions.forEach(function (question) {
376
- var id = question.id,
377
- kind = question.kind,
378
- optionsAttributes = question.optionsAttributes,
379
- fieldCode = question.fieldCode,
380
- minValue = question.minValue,
381
- maxValue = question.maxValue,
382
- fields = question.fields;
383
- switch (kind) {
384
- case QUESTION_KIND.CONDITION.value:
385
- {
386
- var _valuesMap$id$value, _valuesMap;
387
- initValues[id] = (_valuesMap$id$value = (_valuesMap = valuesMap) === null || _valuesMap === void 0 || (_valuesMap = _valuesMap[id]) === null || _valuesMap === void 0 ? void 0 : _valuesMap.value) !== null && _valuesMap$id$value !== void 0 ? _valuesMap$id$value : false;
388
- return;
389
- }
390
- case QUESTION_KIND.ADDITIONAL_GUESTS.value:
391
- {
392
- var _valuesMap2;
393
- var emailsFromSubmission = toEmailValues((_valuesMap2 = valuesMap) === null || _valuesMap2 === void 0 || (_valuesMap2 = _valuesMap2[id]) === null || _valuesMap2 === void 0 ? void 0 : _valuesMap2.value);
394
- initValues[id] = isNotEmpty(emailsFromSubmission) ? emailsFromSubmission : getAdditionalGuestsFromUrl({
395
- fieldCodes: fieldCodes,
396
- fieldCode: fieldCode
397
- });
398
- return;
399
- }
400
- case QUESTION_KIND.CHECKBOX.value:
401
- {
402
- var _valuesMap$id;
403
- initValues[id] = (_valuesMap$id = valuesMap[id]) !== null && _valuesMap$id !== void 0 && (_valuesMap$id = _valuesMap$id.optionIds) !== null && _valuesMap$id !== void 0 && _valuesMap$id.length ? optionsAttributes.map(function (option) {
404
- var _valuesMap$id2;
405
- return (_valuesMap$id2 = valuesMap[id]) === null || _valuesMap$id2 === void 0 || (_valuesMap$id2 = _valuesMap$id2.optionIds) === null || _valuesMap$id2 === void 0 ? void 0 : _valuesMap$id2.includes(option.id);
406
- }) : getMultipleOptionsFromURL({
407
- optionsAttributes: optionsAttributes,
408
- fieldCodes: fieldCodes,
409
- fieldCode: fieldCode
410
- });
411
- return;
412
- }
413
- case QUESTION_KIND.RADIO.value:
414
- case QUESTION_KIND.DROPDOWN.value:
415
- {
416
- var _optionsAttributes$fi;
417
- initValues[id] = ((_optionsAttributes$fi = optionsAttributes.find(function (option) {
418
- var _valuesMap$id3;
419
- return (_valuesMap$id3 = valuesMap[id]) === null || _valuesMap$id3 === void 0 || (_valuesMap$id3 = _valuesMap$id3.optionIds) === null || _valuesMap$id3 === void 0 ? void 0 : _valuesMap$id3.includes(option.id);
420
- })) === null || _optionsAttributes$fi === void 0 ? void 0 : _optionsAttributes$fi.id) || getOptionFromURL({
421
- optionsAttributes: optionsAttributes,
422
- fieldCodes: fieldCodes,
423
- fieldCode: fieldCode
424
- });
425
- return;
426
- }
427
- case QUESTION_KIND.INTEGER.value:
428
- case QUESTION_KIND.DECIMAL.value:
429
- {
430
- var _valuesMap3;
431
- initValues[id] = ((_valuesMap3 = valuesMap) === null || _valuesMap3 === void 0 || (_valuesMap3 = _valuesMap3[id]) === null || _valuesMap3 === void 0 ? void 0 : _valuesMap3.value) || getNumberFromUrl({
432
- fieldCodes: fieldCodes,
433
- fieldCode: fieldCode,
434
- kind: kind
435
- });
436
- return;
437
- }
438
- case QUESTION_KIND.RATING.value:
439
- {
440
- var _valuesMap4;
441
- initValues[id] = ((_valuesMap4 = valuesMap) === null || _valuesMap4 === void 0 || (_valuesMap4 = _valuesMap4[id]) === null || _valuesMap4 === void 0 ? void 0 : _valuesMap4.value) || getRatingFromUrl({
442
- fieldCodes: fieldCodes,
443
- fieldCode: fieldCode
444
- });
445
- return;
446
- }
447
- case QUESTION_KIND.TERMS.value:
448
- {
449
- initValues[id] = false;
450
- return;
451
- }
452
- case QUESTION_KIND.FILE_UPLOAD.value:
453
- {
454
- var _valuesMap$id$value2, _valuesMap5;
455
- initValues[id] = {
456
- files: (_valuesMap$id$value2 = (_valuesMap5 = valuesMap) === null || _valuesMap5 === void 0 || (_valuesMap5 = _valuesMap5[id]) === null || _valuesMap5 === void 0 ? void 0 : _valuesMap5.value) !== null && _valuesMap$id$value2 !== void 0 ? _valuesMap$id$value2 : []
457
- };
458
- return;
459
- }
460
- case QUESTION_KIND.PHONE.value:
461
- case QUESTION_KIND.SMS_REMINDER.value:
462
- {
463
- var _valuesMap$id$value3, _valuesMap6;
464
- initValues[id] = (_valuesMap$id$value3 = (_valuesMap6 = valuesMap) === null || _valuesMap6 === void 0 || (_valuesMap6 = _valuesMap6[id]) === null || _valuesMap6 === void 0 ? void 0 : _valuesMap6.value) !== null && _valuesMap$id$value3 !== void 0 ? _valuesMap$id$value3 : getPhoneNumberFromUrl(fieldCodes, fieldCode);
465
- return;
466
- }
467
- case QUESTION_KIND.STAR_RATING.value:
468
- case QUESTION_KIND.OPINION_SCALE.value:
469
- {
470
- var _valuesMap$id$value4, _valuesMap7;
471
- initValues[id] = (_valuesMap$id$value4 = (_valuesMap7 = valuesMap) === null || _valuesMap7 === void 0 || (_valuesMap7 = _valuesMap7[id]) === null || _valuesMap7 === void 0 ? void 0 : _valuesMap7.value) !== null && _valuesMap$id$value4 !== void 0 ? _valuesMap$id$value4 : getStarRatingOrOpinionScaleFromUrl({
472
- minValue: minValue,
473
- maxValue: maxValue,
474
- fieldCodes: fieldCodes,
475
- fieldCode: fieldCode
476
- });
477
- return;
478
- }
479
- case QUESTION_KIND.NAME.value:
480
- {
481
- var _valuesMap$id$value5, _valuesMap8;
482
- initValues[id] = (_valuesMap$id$value5 = (_valuesMap8 = valuesMap) === null || _valuesMap8 === void 0 || (_valuesMap8 = _valuesMap8[id]) === null || _valuesMap8 === void 0 ? void 0 : _valuesMap8.value) !== null && _valuesMap$id$value5 !== void 0 ? _valuesMap$id$value5 : getNameFromUrl(question, fieldCodes);
483
- return;
484
- }
485
- case QUESTION_KIND.ADDRESS.value:
486
- {
487
- var _valuesMap$id$value6, _valuesMap9;
488
- initValues[id] = (_valuesMap$id$value6 = (_valuesMap9 = valuesMap) === null || _valuesMap9 === void 0 || (_valuesMap9 = _valuesMap9[id]) === null || _valuesMap9 === void 0 ? void 0 : _valuesMap9.value) !== null && _valuesMap$id$value6 !== void 0 ? _valuesMap$id$value6 : fields.reduce(function (values, field) {
489
- values[field.id] = "";
490
- return values;
491
- }, {});
492
- return;
493
- }
494
- default:
495
- {
496
- var _valuesMap$id$value7, _valuesMap10;
497
- initValues[id] = (_valuesMap$id$value7 = (_valuesMap10 = valuesMap) === null || _valuesMap10 === void 0 || (_valuesMap10 = _valuesMap10[id]) === null || _valuesMap10 === void 0 ? void 0 : _valuesMap10.value) !== null && _valuesMap$id$value7 !== void 0 ? _valuesMap$id$value7 : resolveQueryParamValue(fieldCodes[fieldCode] || "");
498
- return;
499
- }
500
- }
501
- });
502
- var formInitialValues = !isEmptyValues(localValues) ? localValues : initValues;
503
- return mergeLeft(formInitialValues, buildEmailVerificationEntries(questions));
504
- };
505
- var generateFormResponse = function generateFormResponse(response, questions) {
506
- var formResponse = [];
507
- questions.forEach(function (question) {
508
- var id = question.id,
509
- kind = question.kind,
510
- optionsAttributes = question.optionsAttributes;
511
- if (!SCHEMA_LESS_QUESTION_KINDS.includes(kind)) {
512
- var responseValue = response[id];
513
- if (kind === QUESTION_KIND.RADIO.value || kind === QUESTION_KIND.DROPDOWN.value) {
514
- var option = findById(responseValue, optionsAttributes);
515
- if (option) {
516
- formResponse.push({
517
- questionId: id,
518
- questionOptionId: option.id,
519
- value: option.label,
520
- kind: kind
521
- });
522
- }
523
- } else if (kind === QUESTION_KIND.CHECKBOX.value) {
524
- responseValue.forEach(function (isChecked, index) {
525
- if (!isChecked) return;
526
- var option = optionsAttributes[index];
527
- formResponse.push({
528
- questionId: id,
529
- questionOptionId: option.id,
530
- value: option.label,
531
- kind: kind
532
- });
533
- });
534
- } else if (isPhoneNumberField(kind)) {
535
- formResponse.push({
536
- questionId: id,
537
- value: responseValue ? parsePhoneNumber(responseValue).formatInternational() : "",
538
- kind: kind
539
- });
540
- } else if (kind === QUESTION_KIND.ADDITIONAL_GUESTS.value) {
541
- formResponse.push({
542
- questionId: id,
543
- value: responseValue ? pluck("value", responseValue) : null,
544
- kind: kind
545
- });
546
- } else if (kind === QUESTION_KIND.RICH_TEXT.value) {
547
- formResponse.push({
548
- questionId: id,
549
- value: isEditorEmpty(responseValue) ? null : responseValue,
550
- kind: kind
551
- });
552
- } else if (kind === QUESTION_KIND.FILE_UPLOAD.value) {
553
- formResponse.push({
554
- questionId: id,
555
- files: isPresent(responseValue) ? responseValue.files : null,
556
- kind: kind
557
- });
558
- } else if (kind === QUESTION_KIND.DATE.value) {
559
- formResponse.push({
560
- questionId: id,
561
- value: dayjs(responseValue).isValid() ?
562
- // YYYY-MM-DD format is not supported by dateFormat.
563
- // eslint-disable-next-line @bigbinary/neeto/use-standard-date-time-formats
564
- dayjs(responseValue).format("YYYY-MM-DD") : "",
565
- kind: kind
566
- });
567
- } else formResponse.push({
568
- questionId: id,
569
- value: responseValue,
570
- kind: kind
571
- });
572
- }
573
- });
574
- return formResponse;
575
- };
576
- var mergeRefs = function mergeRefs() {
577
- for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
578
- refs[_key] = arguments[_key];
579
- }
580
- return function (node) {
581
- return refs.forEach(function (ref) {
582
- return typeof ref === "function" ? ref(node) : ref.current = node;
583
- });
584
- };
585
- };
586
- var getError = function getError(meta) {
587
- if (meta.error && meta.touched) {
588
- return typeof meta.error === "string" ? meta.error : "";
589
- }
590
- return "";
591
- };
592
- var buildAutoCompleteAttribute = function buildAutoCompleteAttribute(kind, autoCompleteKinds, formDomProps) {
593
- return (formDomProps === null || formDomProps === void 0 ? void 0 : formDomProps.autoComplete) === "off" && includes(kind, autoCompleteKinds) ? "on" : undefined;
594
- };
595
- var renderButtonsInOrder = function renderButtonsInOrder(buttonsArray, shouldReverse) {
596
- var orderedButtons = shouldReverse ? buttonsArray.reverse() : buttonsArray;
597
- return map(identity, orderedButtons);
598
- };
599
- var getSelectedRating = function getSelectedRating(value) {
600
- var parsedValue = parseInt(value);
601
- return isNaN(parsedValue) ? -1 : parsedValue;
602
- };
603
- var isPhoneNumberField = includes(__, [QUESTION_KIND.PHONE.value, QUESTION_KIND.SMS_REMINDER.value]);
604
-
605
- var _excluded$4 = ["kind", "customValidator"];
606
- var _fieldKindValidatorMa;
607
- function ownKeys$h(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
608
- function _objectSpread$h(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$h(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$h(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
609
- var t = clientI18nInstance.t;
610
- var isValidDate = function isValidDate(date) {
611
- return date && dayjs(date).isValid();
612
- };
613
- var extractEmailDomain = function extractEmailDomain(email) {
614
- return email === null || email === void 0 ? void 0 : email.split("@")[1];
615
- };
616
- var isEmailFromWhitelistedDomain = function isEmailFromWhitelistedDomain(email, whitelistedDomains) {
617
- if (isEmpty(whitelistedDomains)) return true;
618
- var domain = extractEmailDomain(email);
619
- return includes(domain, whitelistedDomains);
620
- };
621
- var isEmailFromBlacklistedDomain = function isEmailFromBlacklistedDomain(email, blacklistedDomains) {
622
- var domain = extractEmailDomain(email);
623
- return includes(domain, blacklistedDomains);
624
- };
625
- var validateTextField = function validateTextField(_ref) {
626
- var kind = _ref.kind,
627
- label = _ref.label,
628
- isRequired = _ref.isRequired;
629
- var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
630
- if (isPhoneNumberField(kind)) {
631
- schema = validation(getInvalidFieldError(t("neetoForm.common.phoneNumberValidation")));
632
- }
633
- if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
634
- return schema.trim();
635
- };
636
- var validateEmailField = function validateEmailField(_ref2) {
637
- var label = _ref2.label,
638
- isRequired = _ref2.isRequired,
639
- whitelistedDomains = _ref2.whitelistedDomains,
640
- blacklistedDomains = _ref2.blacklistedDomains;
641
- var schema = yup.string().typeError(getInvalidTypeError(label, "string")).email(getInvalidFieldError("Email")).test("verify domain", function (_ref3) {
642
- var value = _ref3.value;
643
- return t("neetoForm.error.emailFromRestrictedDomain", {
644
- domain: extractEmailDomain(value)
645
- });
646
- }, function (value) {
647
- return isNotPresent(value) || isEmailFromWhitelistedDomain(value, whitelistedDomains) && !isEmailFromBlacklistedDomain(value, blacklistedDomains);
648
- });
649
- if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
650
- return schema.trim();
651
- };
652
- var validateNameField = function validateNameField(_ref4) {
653
- var label = _ref4.label,
654
- isRequired = _ref4.isRequired;
655
- var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
656
- if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
657
- return schema.trim();
658
- };
659
- var validateSingleChoiceField = function validateSingleChoiceField(_ref5) {
660
- var label = _ref5.label,
661
- isRequired = _ref5.isRequired;
662
- var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
663
- if (isRequired) schema = schema.required(getSelectMinError());
664
- return schema.trim();
665
- };
666
- var validateMultiChoiceField = function validateMultiChoiceField(_ref6) {
667
- var isRequired = _ref6.isRequired;
668
- var schema = yup.array().of(yup["boolean"]());
669
- if (isRequired) schema = schema.compact().min(1, getSelectMinError());
670
- return schema;
671
- };
672
- var validateRatingField = function validateRatingField(_ref7) {
673
- var label = _ref7.label,
674
- isRequired = _ref7.isRequired;
675
- var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
676
- if (isRequired) schema = schema.required(getSelectMinError());
677
- return schema.trim();
678
- };
679
- var validateStarRatingField = function validateStarRatingField(_ref8) {
680
- var label = _ref8.label,
681
- isRequired = _ref8.isRequired;
682
- var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
683
- if (isRequired) {
684
- schema = schema.required(getSelectMinError(t("neetoForm.common.rating")));
685
- }
686
- return schema.trim();
687
- };
688
- var validateOpinionScaleField = function validateOpinionScaleField(_ref9) {
689
- var label = _ref9.label,
690
- isRequired = _ref9.isRequired;
691
- var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
692
- if (isRequired) {
693
- schema = schema.required(getSelectMinError(t("neetoForm.common.selection")));
694
- }
695
- return schema.trim();
696
- };
697
- var validateTermsField = function validateTermsField(_ref10) {
698
- var _ref10$isRequired = _ref10.isRequired,
699
- isRequired = _ref10$isRequired === void 0 ? true : _ref10$isRequired;
700
- return isRequired ? yup["boolean"]().oneOf([true], t("neetoForm.common.mustAcceptTermsAndConditions")) : yup["boolean"]().notRequired();
701
- };
702
- var validateConditionField = function validateConditionField(_ref11) {
703
- var _ref11$isRequired = _ref11.isRequired,
704
- isRequired = _ref11$isRequired === void 0 ? true : _ref11$isRequired;
705
- return isRequired ? yup["boolean"]().oneOf([true], t("neetoForm.common.mustAcceptCondition")) : yup["boolean"]().notRequired();
706
- };
707
- var validateDateField = function validateDateField(_ref12) {
708
- var label = _ref12.label,
709
- isRequired = _ref12.isRequired;
710
- var schema = yup.string().test("is valid date", getInvalidTypeError(label, "date"), function (value) {
711
- return isNotPresent(value) || isValidDate(value);
712
- });
713
- if (isRequired) {
714
- schema = schema.required(getRequiredFieldError(label));
715
- }
716
- return schema;
717
- };
718
- var validateMultiEmailField = function validateMultiEmailField(_ref13) {
719
- var isRequired = _ref13.isRequired;
720
- var schema = yup.array().of(yup.object().shape({
721
- value: yup.string().email(getInvalidFieldError("Email")).trim()
722
- })).nullable();
723
- if (isRequired) {
724
- schema = schema.compact().min(1, getSelectMinError(t("neetoForm.common.email")));
725
- }
726
- return schema;
727
- };
728
- var validateAddressField = function validateAddressField(_ref14) {
729
- var label = _ref14.label,
730
- isRequired = _ref14.isRequired;
731
- var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
732
- if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
733
- return schema.trim();
734
- };
735
- var editorHasValue = function editorHasValue(content) {
736
- return !isEditorEmpty(content);
737
- };
738
- var validateRichTextField = function validateRichTextField(_ref15) {
739
- var isRequired = _ref15.isRequired;
740
- var schema = yup.string();
741
- if (isRequired) {
742
- schema = schema.test("required", getRequiredFieldError("content"), editorHasValue);
743
- }
744
- return schema.trim();
745
- };
746
- var validateFileUploadField = function validateFileUploadField(_ref16) {
747
- var isRequired = _ref16.isRequired,
748
- multipleFilesAllowed = _ref16.multipleFilesAllowed;
749
- var files_schema = yup.array();
750
- if (isRequired) {
751
- files_schema = files_schema.of(yup.object().shape({
752
- name: yup.string(),
753
- signedId: yup.string().required(t("neetoForm.fileUpload.validations.waitForUpload")),
754
- url: yup.string().required(t("neetoForm.fileUpload.validations.waitForUpload"))
755
- })).unique("name", t("neetoForm.fileUpload.validations.removeDuplicates")).min(1, multipleFilesAllowed ? t("neetoForm.fileUpload.validations.atLeastOneFileRequired") : t("neetoForm.fileUpload.validations.fileIsRequired"));
756
- }
757
- return yup.object().shape({
758
- files: files_schema
759
- });
760
- };
761
- var validateCaptchaField = function validateCaptchaField(_ref17) {
762
- var variant = _ref17.variant;
763
- return variant === CAPTCHA_TYPES.MATH_CAPTCHA ? yup.mixed().test("verification failed", t("neetoForm.error.captchaVerificationFailed"), function (value) {
764
- return isNotPresent(value) || value;
765
- }).transform(function (value) {
766
- return value === "" ? null : value;
767
- }).required(t("neetoForm.error.incompleteCaptcha")) : yup.string().trim().required(t("neetoForm.error.incompleteCaptcha"));
768
- };
769
- var fieldKindValidatorMap = (_fieldKindValidatorMa = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_fieldKindValidatorMa, QUESTION_KIND.EMAIL.value, validateEmailField), QUESTION_KIND.NAME.value, validateNameField), QUESTION_KIND.PHONE.value, validateTextField), QUESTION_KIND.TEXT.value, validateTextField), QUESTION_KIND.QUESTION.value, validateTextField), QUESTION_KIND.TEXTAREA.value, validateTextField), QUESTION_KIND.DECIMAL.value, validateTextField), QUESTION_KIND.INTEGER.value, validateTextField), QUESTION_KIND.DROPDOWN.value, validateSingleChoiceField), QUESTION_KIND.RADIO.value, validateSingleChoiceField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_fieldKindValidatorMa, QUESTION_KIND.CHECKBOX.value, validateMultiChoiceField), QUESTION_KIND.RATING.value, validateRatingField), QUESTION_KIND.TERMS.value, validateTermsField), QUESTION_KIND.DATE.value, validateDateField), QUESTION_KIND.STAR_RATING.value, validateStarRatingField), QUESTION_KIND.OPINION_SCALE.value, validateOpinionScaleField), QUESTION_KIND.ADDITIONAL_GUESTS.value, validateMultiEmailField), QUESTION_KIND.RICH_TEXT.value, validateRichTextField), QUESTION_KIND.CONDITION.value, validateConditionField), QUESTION_KIND.FILE_UPLOAD.value, validateFileUploadField), _defineProperty(_defineProperty(_defineProperty(_fieldKindValidatorMa, QUESTION_KIND.CAPTCHA.value, validateCaptchaField), QUESTION_KIND.SMS_REMINDER.value, validateTextField), QUESTION_KIND.ADDRESS.value, validateAddressField));
770
- var validateFieldValue = function validateFieldValue(_ref18) {
771
- var kind = _ref18.kind,
772
- customValidator = _ref18.customValidator,
773
- otherProps = _objectWithoutProperties(_ref18, _excluded$4);
774
- return function (value) {
775
- if (!(kind in fieldKindValidatorMap)) return;
776
- var validator = fieldKindValidatorMap[kind];
777
- var schema = customValidator || validator(_objectSpread$h({
778
- kind: kind
779
- }, otherProps));
780
-
781
- // eslint-disable-next-line consistent-return, no-async-promise-executor
782
- return new Promise(/*#__PURE__*/function () {
783
- var _ref19 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve) {
784
- return _regeneratorRuntime.wrap(function _callee$(_context) {
785
- while (1) switch (_context.prev = _context.next) {
786
- case 0:
787
- _context.prev = 0;
788
- _context.next = 3;
789
- return schema.validate(value);
790
- case 3:
791
- resolve(undefined);
792
- _context.next = 9;
793
- break;
794
- case 6:
795
- _context.prev = 6;
796
- _context.t0 = _context["catch"](0);
797
- resolve(_context.t0.message);
798
- case 9:
799
- case "end":
800
- return _context.stop();
801
- }
802
- }, _callee, null, [[0, 6]]);
803
- }));
804
- return function (_x) {
805
- return _ref19.apply(this, arguments);
806
- };
807
- }());
808
- };
809
- };
810
- var validateVerificationCode = function validateVerificationCode(context) {
811
- return function (value) {
812
- var entity = t("neetoForm.emailVerification.verificationCode");
813
- var schema = yup.string().trim().when("$isVerificationEnabled", {
814
- is: true,
815
- then: function then(schema) {
816
- return schema.when("$isRequired", {
817
- is: true,
818
- then: function then(s) {
819
- return s.required(getRequiredFieldError(entity));
820
- }
821
- }).when("$email", function (email, s) {
822
- if (email !== null && email !== void 0 && email.trim()) {
823
- return s.required(getRequiredFieldError(entity));
824
- }
825
- return s;
826
- }).test("is-6-digit-number", t("neetoForm.error.mustBeASixDigitNumber", {
827
- entity: entity
828
- }), function (value) {
829
- return isNotPresent(value) || SIX_DIGIT_NUMBER_REGEX.test(value);
830
- }).test("verify code", t("neetoForm.error.emailNotVerified"), function () {
831
- var _this$options;
832
- return this === null || this === void 0 || (_this$options = this.options) === null || _this$options === void 0 || (_this$options = _this$options.context) === null || _this$options === void 0 ? void 0 : _this$options.isCodeVerified;
833
- });
834
- }
835
- });
836
-
837
- // eslint-disable-next-line no-async-promise-executor
838
- return new Promise(/*#__PURE__*/function () {
839
- var _ref20 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve) {
840
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
841
- while (1) switch (_context2.prev = _context2.next) {
842
- case 0:
843
- _context2.prev = 0;
844
- _context2.next = 3;
845
- return schema.validate(value, {
846
- context: context
847
- });
848
- case 3:
849
- resolve(undefined);
850
- _context2.next = 9;
851
- break;
852
- case 6:
853
- _context2.prev = 6;
854
- _context2.t0 = _context2["catch"](0);
855
- resolve(_context2.t0.message);
856
- case 9:
857
- case "end":
858
- return _context2.stop();
859
- }
860
- }, _callee2, null, [[0, 6]]);
861
- }));
862
- return function (_x2) {
863
- return _ref20.apply(this, arguments);
864
- };
865
- }());
866
- };
867
- };
868
-
869
- var MultipleEmailInput = function MultipleEmailInput(_ref) {
870
- var question = _ref.question,
871
- customValidator = _ref.customValidator;
872
- var name = question.id,
873
- kind = question.kind,
874
- isRequired = question.isRequired,
875
- nodeId = question.nodeId,
876
- isReadOnly = question.isReadOnly;
877
- var label = fieldWithFallback(question, "label");
878
- var _useFormikContext = useFormikContext(),
879
- submitCount = _useFormikContext.submitCount;
880
- var _useTranslation = useTranslation(),
881
- t = _useTranslation.t;
882
- var _useField = useField({
883
- name: name || nodeId,
884
- validate: validateFieldValue({
885
- kind: kind,
886
- label: label,
887
- isRequired: isRequired,
888
- customValidator: customValidator
889
- })
890
- }),
891
- _useField2 = _slicedToArray(_useField, 3),
892
- field = _useField2[0],
893
- meta = _useField2[1],
894
- _useField2$ = _useField2[2],
895
- setValue = _useField2$.setValue,
896
- setTouched = _useField2$.setTouched;
897
- var _useState = useState(isPresent(field.value)),
898
- _useState2 = _slicedToArray(_useState, 2),
899
- isInputVisible = _useState2[0],
900
- setIsInputVisible = _useState2[1];
901
- return /*#__PURE__*/jsx("div", {
902
- className: "neeto-form-engine-input__wrapper",
903
- children: /*#__PURE__*/jsx("div", {
904
- className: "neeto-ui-w-full",
905
- children: isInputVisible ? /*#__PURE__*/jsx(NeetoUIMultiEmailInput, {
906
- isRequired: isRequired,
907
- label: label,
908
- disabled: isReadOnly,
909
- error: meta.touched ? meta.error : "",
910
- helpText: t("neetoForm.common.addGuestsHelper"),
911
- name: field.name,
912
- placeholder: fieldWithFallback(question, "placeholder"),
913
- value: field.value,
914
- onBlur: function onBlur() {
915
- return setTouched(true);
916
- },
917
- onChange: setValue
918
- }) : /*#__PURE__*/jsxs("div", {
919
- className: "flex flex-col gap-2 items-end",
920
- children: [/*#__PURE__*/jsx(Button, _defineProperty(_defineProperty(_defineProperty({
921
- label: label,
922
- "data-testid": "add-guest-button",
923
- disabled: isReadOnly,
924
- icon: Plus,
925
- iconPosition: "left"
926
- }, "label", t("neetoForm.common.addGuests")), "style", "link"), "onClick", function onClick() {
927
- return setIsInputVisible(true);
928
- })), (meta === null || meta === void 0 ? void 0 : meta.error) && submitCount > 0 && /*#__PURE__*/jsx("span", {
929
- className: "neeto-ui-text-error-500",
930
- children: meta.error
931
- })]
932
- })
933
- })
934
- });
935
- };
936
-
937
- function ownKeys$g(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
938
- function _objectSpread$g(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$g(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$g(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
939
- var AddressField = function AddressField(_ref) {
940
- var question = _ref.question,
941
- customValidator = _ref.customValidator;
942
- var name = question.id,
943
- kind = question.kind,
944
- isAddressRequired = question.isRequired,
945
- isReadOnly = question.isReadOnly,
946
- _question$fields = question.fields,
947
- fields = _question$fields === void 0 ? [] : _question$fields;
948
- var label = fieldWithFallback(question, "label");
949
- var transformedFields = fields.map(function (field) {
950
- return _objectSpread$g(_objectSpread$g({}, field), {}, {
951
- label: fieldWithFallback(field, "label")
952
- });
953
- });
954
- return /*#__PURE__*/jsxs("div", {
955
- className: "neeto-form-engine-address-wrapper",
956
- children: [/*#__PURE__*/jsx("div", {
957
- className: "neeto-form-engine-input__label-wrapper",
958
- children: label && /*#__PURE__*/jsx("label", {
959
- className: "neeto-form-engine-label",
960
- "data-testid": "".concat(hyphenate(label), "-input-label"),
961
- children: label
962
- })
963
- }), /*#__PURE__*/jsx("div", {
964
- className: "neeto-form-engine-address pb-1",
965
- children: getVisibleOptions(transformedFields).map(function (_ref2) {
966
- var id = _ref2.id,
967
- label = _ref2.label,
968
- width = _ref2.width,
969
- fieldType = _ref2.fieldType,
970
- properties = _ref2.properties,
971
- isRequired = _ref2.isRequired;
972
- return /*#__PURE__*/jsx("div", {
973
- "data-testid": "neeto-form-engine-address-fields",
974
- className: classnames("neeto-form-engine-address__field", {
975
- "neeto-form-engine-address__field--width-full": width === ADDRESS_FIELD_WIDTHS.FULL,
976
- "neeto-form-engine-address__field--width-half": width === ADDRESS_FIELD_WIDTHS.HALF,
977
- "neeto-form-engine-address__field--width-one-forth": width === ADDRESS_FIELD_WIDTHS.ONE_FOURTH,
978
- "neeto-form-engine-address__field--width-three-forth": width === ADDRESS_FIELD_WIDTHS.THREE_FOURTH
979
- }),
980
- children: /*#__PURE__*/jsx(Field$1, {
981
- name: "".concat(name, ".").concat(id),
982
- validate: isAddressRequired ? validateFieldValue({
983
- kind: kind,
984
- label: label,
985
- isRequired: isRequired,
986
- customValidator: customValidator
987
- }) : noop,
988
- children: function children(_ref3) {
989
- var _properties$options;
990
- var field = _ref3.field,
991
- meta = _ref3.meta,
992
- form = _ref3.form;
993
- return fieldType === ADDRESS_FIELD_TYPES.SELECT ? /*#__PURE__*/jsx(Select, _objectSpread$g(_objectSpread$g({
994
- label: label,
995
- size: "large"
996
- }, field), {}, {
997
- error: meta.touched && meta.error,
998
- isDisabled: isReadOnly,
999
- menuPosition: "absolute",
1000
- required: isRequired,
1001
- value: toLabelAndValue(field.value),
1002
- options: properties === null || properties === void 0 || (_properties$options = properties.options) === null || _properties$options === void 0 ? void 0 : _properties$options.map(function (_ref4) {
1003
- var label = _ref4.label;
1004
- return toLabelAndValue(label);
1005
- }),
1006
- onChange: function onChange(_ref5) {
1007
- var value = _ref5.value;
1008
- return !isReadOnly && form.setFieldValue("".concat(name, ".").concat(id), value);
1009
- }
1010
- })) : /*#__PURE__*/jsx(Input, _objectSpread$g(_objectSpread$g({}, _objectSpread$g(_objectSpread$g({}, field), {}, {
1011
- label: label
1012
- })), {}, {
1013
- disabled: isReadOnly,
1014
- error: meta.touched && meta.error,
1015
- required: isRequired
1016
- }));
1017
- }
1018
- })
1019
- }, id);
1020
- })
1021
- })]
1022
- });
1023
- };
1024
-
1025
- var CaptchaField = function CaptchaField(_ref) {
1026
- var question = _ref.question,
1027
- preview = _ref.preview,
1028
- customValidator = _ref.customValidator,
1029
- captchaRef = _ref.captchaRef;
1030
- var name = question.id,
1031
- kind = question.kind,
1032
- isRequired = question.isRequired,
1033
- variant = question.variant,
1034
- nodeId = question.nodeId;
1035
- var label = fieldWithFallback(question, "label");
1036
- var _useField = useField({
1037
- name: name || nodeId,
1038
- validate: validateFieldValue({
1039
- kind: kind,
1040
- label: label,
1041
- isRequired: isRequired,
1042
- customValidator: customValidator,
1043
- variant: variant
1044
- })
1045
- }),
1046
- _useField2 = _slicedToArray(_useField, 3);
1047
- _useField2[0];
1048
- var _useField2$ = _useField2[1],
1049
- touched = _useField2$.touched,
1050
- error = _useField2$.error,
1051
- _useField2$2 = _useField2[2],
1052
- setValue = _useField2$2.setValue,
1053
- setTouched = _useField2$2.setTouched;
1054
- var handleVerifyCaptcha = function handleVerifyCaptcha(response) {
1055
- setTouched(true);
1056
- setValue(response);
1057
- };
1058
- var Component = CAPTCHA_COMPONENT_MAP[variant];
1059
- return /*#__PURE__*/jsxs("div", {
1060
- className: "neeto-form-engine-input__wrapper",
1061
- children: [/*#__PURE__*/jsx("div", {
1062
- className: "neeto-form-engine-input__label-wrapper",
1063
- children: label && /*#__PURE__*/jsx("label", {
1064
- className: "neeto-form-engine-label",
1065
- children: getLabel(label, isRequired)
1066
- })
1067
- }), /*#__PURE__*/jsx("div", {
1068
- className: classnames({
1069
- "pointer-events-none": preview
1070
- }),
1071
- children: /*#__PURE__*/jsx(Component, {
1072
- captchaRef: captchaRef,
1073
- handleVerifyCaptcha: handleVerifyCaptcha,
1074
- handleBlur: function handleBlur() {
1075
- return setTouched(true);
1076
- }
1077
- })
1078
- }), touched && error && /*#__PURE__*/jsx("p", {
1079
- className: "neeto-form-engine-input__error",
1080
- "data-testid": "neeto-form-engine-captcha-error",
1081
- children: error
1082
- })]
1083
- });
1084
- };
1085
-
1086
- var MATH_OPERATORS = {
1087
- PLUS: "+",
1088
- MINUS: "-"
1089
- };
1090
-
1091
- var generateRandomOperation = function generateRandomOperation() {
1092
- var firstNumber = getRandomInt(1, 50);
1093
- var secondNumber = getRandomInt(1, 50);
1094
- var operator = randomPick.apply(void 0, _toConsumableArray(values(MATH_OPERATORS)));
1095
- return {
1096
- firstNumber: firstNumber,
1097
- secondNumber: secondNumber,
1098
- operator: operator
1099
- };
1100
- };
1101
-
1102
- var MathCaptcha = function MathCaptcha(_ref) {
1103
- var captchaRef = _ref.captchaRef,
1104
- handleVerifyCaptcha = _ref.handleVerifyCaptcha,
1105
- handleBlur = _ref.handleBlur;
1106
- var _useState = useState(generateRandomOperation()),
1107
- _useState2 = _slicedToArray(_useState, 2),
1108
- operation = _useState2[0],
1109
- setOperation = _useState2[1];
1110
- var _useState3 = useState(""),
1111
- _useState4 = _slicedToArray(_useState3, 2),
1112
- userInput = _useState4[0],
1113
- setUserInput = _useState4[1];
1114
- var firstNumber = operation.firstNumber,
1115
- secondNumber = operation.secondNumber,
1116
- operator = operation.operator;
1117
- var resetCaptcha = function resetCaptcha() {
1118
- setOperation(generateRandomOperation());
1119
- setUserInput("");
1120
- };
1121
- useImperativeHandle(captchaRef, function () {
1122
- return {
1123
- reset: resetCaptcha
1124
- };
1125
- });
1126
- var calculateResult = function calculateResult() {
1127
- switch (operator) {
1128
- case MATH_OPERATORS.PLUS:
1129
- return firstNumber + secondNumber;
1130
- case MATH_OPERATORS.MINUS:
1131
- return firstNumber - secondNumber;
1132
- default:
1133
- return null;
1134
- }
1135
- };
1136
- var verifyCaptcha = function verifyCaptcha() {
1137
- var result = calculateResult();
1138
- if (result === null) return;
1139
- handleVerifyCaptcha(result === Number(userInput));
1140
- };
1141
- useUpdateEffect(function () {
1142
- verifyCaptcha();
1143
- }, [userInput]);
1144
- return /*#__PURE__*/jsxs("div", {
1145
- className: "neeto-form-nano-math-captcha",
1146
- "data-testid": "math-captcha",
1147
- ref: captchaRef,
1148
- children: [/*#__PURE__*/jsx("button", {
1149
- className: "neeto-form-nano-math-captcha__button",
1150
- type: "button",
1151
- onClick: resetCaptcha,
1152
- children: /*#__PURE__*/jsx(Refresh, {})
1153
- }), /*#__PURE__*/jsxs("div", {
1154
- className: "neeto-form-nano-math-captcha__equation",
1155
- children: [/*#__PURE__*/jsx("span", {
1156
- "data-testid": "first-number",
1157
- children: firstNumber
1158
- }), /*#__PURE__*/jsx("span", {
1159
- "data-testid": "operator",
1160
- children: operator
1161
- }), /*#__PURE__*/jsx("span", {
1162
- "data-testid": "second-number",
1163
- children: secondNumber
1164
- }), /*#__PURE__*/jsx("span", {
1165
- children: "="
1166
- })]
1167
- }), /*#__PURE__*/jsx(Input, {
1168
- required: true,
1169
- className: "neeto-form-nano-math-captcha__input",
1170
- "data-testid": "math-captcha-input",
1171
- value: userInput,
1172
- onBlur: handleBlur,
1173
- onChange: withEventTargetValue(setUserInput)
1174
- })]
1175
- });
1176
- };
1177
-
1178
- var Recaptcha = function Recaptcha(_ref) {
1179
- var captchaRef = _ref.captchaRef,
1180
- handleVerifyCaptcha = _ref.handleVerifyCaptcha;
1181
- var verifyRecaptcha = function verifyRecaptcha(response) {
1182
- if (response === null) {
1183
- return;
1184
- }
1185
- handleVerifyCaptcha(response);
1186
- };
1187
- var expiredRecaptcha = function expiredRecaptcha() {
1188
- var _captchaRef$current;
1189
- captchaRef === null || captchaRef === void 0 || (_captchaRef$current = captchaRef.current) === null || _captchaRef$current === void 0 || _captchaRef$current.reset();
1190
- handleVerifyCaptcha("");
1191
- };
1192
- return /*#__PURE__*/jsx(ReCAPTCHA, {
1193
- hl: clientI18nInstance.language,
1194
- ref: captchaRef,
1195
- sitekey: globalProps.formNanoRecaptchaV2SiteKey,
1196
- onChange: verifyRecaptcha,
1197
- onErrored: noop,
1198
- onExpired: expiredRecaptcha
1199
- }, clientI18nInstance.language);
1200
- };
1201
-
1202
- function ownKeys$f(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1203
- function _objectSpread$f(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$f(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$f(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1204
- var ConditionField = function ConditionField(_ref) {
1205
- var question = _ref.question,
1206
- customValidator = _ref.customValidator;
1207
- var name = question.id,
1208
- kind = question.kind,
1209
- isRequired = question.isRequired,
1210
- nodeId = question.nodeId;
1211
- var label = fieldWithFallback(question, "label");
1212
- return /*#__PURE__*/jsx(Field$1, {
1213
- name: name || nodeId,
1214
- validate: validateFieldValue({
1215
- kind: kind,
1216
- label: label,
1217
- isRequired: isRequired,
1218
- customValidator: customValidator
1219
- }),
1220
- children: function children(_ref2) {
1221
- var meta = _ref2.meta,
1222
- field = _ref2.field;
1223
- return /*#__PURE__*/jsx(Checkbox, _objectSpread$f(_objectSpread$f({}, _objectSpread$f(_objectSpread$f({}, field), {}, {
1224
- label: label,
1225
- name: name
1226
- })), {}, {
1227
- checked: field.value,
1228
- error: meta.touched ? meta.error : "",
1229
- required: isRequired
1230
- }));
1231
- }
1232
- });
1233
- };
1234
-
1235
- var _excluded$3 = ["value"];
1236
- function ownKeys$e(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1237
- function _objectSpread$e(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$e(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$e(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1238
- var DateField = function DateField(_ref) {
1239
- var question = _ref.question,
1240
- customValidator = _ref.customValidator;
1241
- var name = question.id,
1242
- kind = question.kind,
1243
- isRequired = question.isRequired,
1244
- nodeId = question.nodeId,
1245
- isReadOnly = question.isReadOnly;
1246
- var label = fieldWithFallback(question, "label");
1247
- var _QUESTION_KIND$kind$t = QUESTION_KIND[kind.toUpperCase()].type,
1248
- type = _QUESTION_KIND$kind$t === void 0 ? "date" : _QUESTION_KIND$kind$t;
1249
- return /*#__PURE__*/jsxs("div", {
1250
- className: "neeto-form-engine-input__wrapper",
1251
- children: [/*#__PURE__*/jsx("div", {
1252
- className: "neeto-form-engine-input__label-wrapper",
1253
- children: label && /*#__PURE__*/jsx("label", {
1254
- className: "neeto-form-engine-label",
1255
- "data-testid": "".concat(hyphenate(label), "-input-label"),
1256
- children: getLabel(label, isRequired)
1257
- })
1258
- }), /*#__PURE__*/jsx("div", {
1259
- className: "neeto-form-engine-date-picker",
1260
- children: /*#__PURE__*/jsx(Field$1, {
1261
- name: name || nodeId,
1262
- validate: validateFieldValue({
1263
- kind: kind,
1264
- label: label,
1265
- isRequired: isRequired,
1266
- customValidator: customValidator
1267
- }),
1268
- children: function children(_ref2) {
1269
- var meta = _ref2.meta,
1270
- _ref2$field = _ref2.field,
1271
- value = _ref2$field.value,
1272
- field = _objectWithoutProperties(_ref2$field, _excluded$3),
1273
- form = _ref2.form;
1274
- return /*#__PURE__*/jsx(DatePicker, _objectSpread$e(_objectSpread$e({}, _objectSpread$e(_objectSpread$e({}, field), {}, {
1275
- type: type
1276
- })), {}, {
1277
- "data-testid": "".concat(hyphenate(label), "-input-field"),
1278
- dateFormat: "MMM D, YYYY",
1279
- disabled: isReadOnly,
1280
- error: meta.touched ? meta.error : "",
1281
- placeholder: fieldWithFallback(question, "placeholder"),
1282
- popupClassName: "neeto-form-engine-date-picker-popup",
1283
- required: isRequired,
1284
- size: "small",
1285
- value: getValidDate(value),
1286
- onCalendarChange: function onCalendarChange(date) {
1287
- if (date) {
1288
- form.setFieldValue(name, date.toISOString());
1289
- }
1290
- },
1291
- onChange: function onChange(date) {
1292
- form.setFieldValue(name, date ? date.toISOString() : "");
1293
- }
1294
- }));
1295
- }
1296
- })
1297
- })]
1298
- });
1299
- };
1300
-
1301
- var create = function create(_ref) {
1302
- var formId = _ref.formId,
1303
- questionId = _ref.questionId,
1304
- payload = _ref.payload;
1305
- return axios.post(buildUrl(EMAIL_VERIFICATIONS_CREATE_URL, {
1306
- formId: formId,
1307
- questionId: questionId
1308
- }), payload, {
1309
- showToastr: false
1310
- });
1311
- };
1312
- var verify = function verify(_ref2) {
1313
- var formId = _ref2.formId,
1314
- questionId = _ref2.questionId,
1315
- payload = _ref2.payload;
1316
- return axios.post(buildUrl(EMAIL_VERIFICATIONS_VERIFY_URL, {
1317
- formId: formId,
1318
- questionId: questionId
1319
- }), payload, {
1320
- showToastr: false
1321
- });
1322
- };
1323
- var emailVerificationsApi = {
1324
- create: create,
1325
- verify: verify
1326
- };
1327
-
1328
- function ownKeys$d(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1329
- function _objectSpread$d(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$d(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$d(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1330
- var getMutationCallbacks = function getMutationCallbacks(options) {
1331
- return {
1332
- onSuccess: function onSuccess() {
1333
- var _options$onSuccess;
1334
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1335
- args[_key] = arguments[_key];
1336
- }
1337
- return (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 ? void 0 : _options$onSuccess.call.apply(_options$onSuccess, [options].concat(args));
1338
- },
1339
- onError: function onError() {
1340
- var _options$onError;
1341
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1342
- args[_key2] = arguments[_key2];
1343
- }
1344
- return (_options$onError = options.onError) === null || _options$onError === void 0 ? void 0 : _options$onError.call.apply(_options$onError, [options].concat(args));
1345
- }
1346
- };
1347
- };
1348
- var useSendEmailVerificationCode = function useSendEmailVerificationCode(formId, questionId) {
1349
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1350
- return useMutation(_objectSpread$d(_objectSpread$d({
1351
- mutationFn: function mutationFn(payload) {
1352
- return emailVerificationsApi.create({
1353
- formId: formId,
1354
- questionId: questionId,
1355
- payload: payload
1356
- });
1357
- }
1358
- }, options), getMutationCallbacks(options)));
1359
- };
1360
- var useVerifyEmailVerificationCode = function useVerifyEmailVerificationCode(formId, questionId) {
1361
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1362
- return useMutation(_objectSpread$d(_objectSpread$d({
1363
- mutationFn: function mutationFn(payload) {
1364
- return emailVerificationsApi.verify({
1365
- formId: formId,
1366
- questionId: questionId,
1367
- payload: payload
1368
- });
1369
- }
1370
- }, options), getMutationCallbacks(options)));
1371
- };
1372
-
1373
- var SendCodeButton = function SendCodeButton(_ref) {
1374
- var isCodeVerified = _ref.isCodeVerified,
1375
- isSendingVerificationCode = _ref.isSendingVerificationCode,
1376
- handleClick = _ref.handleClick,
1377
- isDisabled = _ref.isDisabled;
1378
- var _useTranslation = useTranslation(),
1379
- t = _useTranslation.t;
1380
- if (isCodeVerified) {
1381
- return /*#__PURE__*/jsx(CheckCircle, {});
1382
- }
1383
- return /*#__PURE__*/jsx(Button, {
1384
- "data-testid": "send-code-button",
1385
- disabled: isDisabled,
1386
- size: "small",
1387
- style: "secondary",
1388
- onClick: handleClick,
1389
- children: isSendingVerificationCode ? /*#__PURE__*/jsx(Spinner, {
1390
- size: "16"
1391
- }) : t("neetoForm.emailVerification.sendCode")
1392
- });
1393
- };
1394
-
1395
- var ResendVerificationCode = function ResendVerificationCode(_ref) {
1396
- var formId = _ref.formId,
1397
- questionId = _ref.questionId,
1398
- sendVerificationCode = _ref.sendVerificationCode,
1399
- isResendDisabled = _ref.isResendDisabled;
1400
- var _useState = useState(getRemainingTime(formId, questionId)),
1401
- _useState2 = _slicedToArray(_useState, 2),
1402
- secondsLeft = _useState2[0],
1403
- setSecondsLeft = _useState2[1];
1404
- var _useTranslation = useTranslation(),
1405
- t = _useTranslation.t;
1406
- useEffect(function () {
1407
- if (secondsLeft <= 0) return undefined;
1408
- var interval = setTimeout(function () {
1409
- setSecondsLeft(pipe(dec, max(0)));
1410
- }, ONE_SECOND);
1411
- return function () {
1412
- return clearTimeout(interval);
1413
- };
1414
- }, [secondsLeft]);
1415
- var handleResendClick = function handleResendClick() {
1416
- if (secondsLeft !== 0) return;
1417
- sendVerificationCode();
1418
- setSecondsLeft(RESEND_DELAY);
1419
- storeLastVerificationCodeSentAt(formId, questionId);
1420
- };
1421
- return /*#__PURE__*/jsx("p", {
1422
- children: !isResendDisabled && secondsLeft > 0 ? t("neetoForm.emailVerification.resendInSeconds", {
1423
- secondsLeft: secondsLeft
1424
- }) : /*#__PURE__*/jsx(Trans, {
1425
- i18nKey: "neetoForm.emailVerification.resendCode",
1426
- components: {
1427
- button: /*#__PURE__*/jsx(Button, {
1428
- "data-testid": "otp-resend-button",
1429
- disabled: isResendDisabled,
1430
- size: "small",
1431
- style: "link",
1432
- onClick: handleResendClick
1433
- })
1434
- }
1435
- })
1436
- });
1437
- };
1438
-
1439
- function ownKeys$c(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1440
- function _objectSpread$c(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$c(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$c(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1441
- var VerifyCode = function VerifyCode(_ref) {
1442
- var formId = _ref.formId,
1443
- questionId = _ref.questionId,
1444
- email = _ref.email,
1445
- emailVerificationToken = _ref.emailVerificationToken,
1446
- isCodeVerified = _ref.isCodeVerified,
1447
- setIsCodeVerified = _ref.setIsCodeVerified,
1448
- handleResponseError = _ref.handleResponseError,
1449
- hasSentVerificationCode = _ref.hasSentVerificationCode,
1450
- calloutDetails = _ref.calloutDetails,
1451
- handleSendVerificationCode = _ref.handleSendVerificationCode,
1452
- isRequired = _ref.isRequired,
1453
- isVerificationEnabled = _ref.isVerificationEnabled;
1454
- var _useTranslation = useTranslation(),
1455
- t = _useTranslation.t;
1456
- var verificationFieldName = buildVerificationFieldName(questionId);
1457
- var _useField = useField({
1458
- name: verificationFieldName,
1459
- validate: validateVerificationCode({
1460
- isVerificationEnabled: isVerificationEnabled,
1461
- isRequired: isRequired,
1462
- email: email,
1463
- isCodeVerified: isCodeVerified
1464
- })
1465
- }),
1466
- _useField2 = _slicedToArray(_useField, 3),
1467
- field = _useField2[0],
1468
- _useField2$ = _useField2[1],
1469
- touched = _useField2$.touched,
1470
- error = _useField2$.error,
1471
- _useField2$2 = _useField2[2],
1472
- setValue = _useField2$2.setValue,
1473
- setTouched = _useField2$2.setTouched;
1474
- var code = field.value;
1475
- var _useState = useState(code),
1476
- _useState2 = _slicedToArray(_useState, 2),
1477
- previousCode = _useState2[0],
1478
- setPreviousCode = _useState2[1];
1479
- var _useVerifyEmailVerifi = useVerifyEmailVerificationCode(formId, questionId, {
1480
- onSuccess: function onSuccess(_, _ref2) {
1481
- var emailVerifications = _ref2.emailVerifications;
1482
- setIsCodeVerified(true);
1483
- setPreviousCode(emailVerifications.otp);
1484
- setEmailVerificationDetail(formId, questionId, _defineProperty(_defineProperty(_defineProperty({}, EMAIL_VERIFICATION_KEYS.EMAIL, emailVerifications.email), EMAIL_VERIFICATION_KEYS.CODE, emailVerifications.otp), EMAIL_VERIFICATION_KEYS.VERIFIED, true));
1485
- },
1486
- onError: handleResponseError
1487
- }),
1488
- verifyCode = _useVerifyEmailVerifi.mutate,
1489
- isVerifyingCode = _useVerifyEmailVerifi.isPending;
1490
- var hasError = isPresent(error);
1491
- useEffect(function () {
1492
- var handleVerifyCode = function handleVerifyCode() {
1493
- if (equals(code, previousCode) || hasError || (code === null || code === void 0 ? void 0 : code.length) !== 6) {
1494
- return;
1495
- }
1496
- verifyCode({
1497
- emailVerifications: {
1498
- email: email,
1499
- token: emailVerificationToken,
1500
- otp: code
1501
- }
1502
- });
1503
- };
1504
- handleVerifyCode();
1505
- }, [code, hasError]);
1506
- return /*#__PURE__*/jsxs(Fragment, {
1507
- children: [/*#__PURE__*/jsx(Input, _objectSpread$c(_objectSpread$c({}, _objectSpread$c({}, field)), {}, {
1508
- "data-testid": "otp-input-field",
1509
- disabled: isVerifyingCode,
1510
- error: touched ? error : "",
1511
- loading: isVerifyingCode,
1512
- name: verificationFieldName,
1513
- placeholder: t("neetoForm.emailVerification.verificationCode"),
1514
- size: "small",
1515
- onBlur: function onBlur() {
1516
- return setTouched(true);
1517
- },
1518
- onChange: withEventTargetValue(setValue)
1519
- })), hasSentVerificationCode && /*#__PURE__*/jsx(ResendVerificationCode, {
1520
- formId: formId,
1521
- questionId: questionId,
1522
- isResendDisabled: calloutDetails.style === CALLOUT_STYLES.ERROR,
1523
- sendVerificationCode: handleSendVerificationCode
1524
- }), calloutDetails.message && /*#__PURE__*/jsx(NeetoUICallout, {
1525
- style: calloutDetails.style,
1526
- children: calloutDetails.message
1527
- })]
1528
- });
1529
- };
1530
-
1531
- function ownKeys$b(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1532
- function _objectSpread$b(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$b(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$b(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1533
- var EmailField = function EmailField(_ref) {
1534
- var question = _ref.question,
1535
- customValidator = _ref.customValidator,
1536
- autoComplete = _ref.autoComplete,
1537
- isFormPreview = _ref.preview,
1538
- isUrlBuilderPreview = _ref.isUrlBuilderPreview;
1539
- var questionId = question.id,
1540
- kind = question.kind,
1541
- isRequired = question.isRequired,
1542
- isReadOnly = question.isReadOnly,
1543
- isDomainWhitelistingEnabled = question.isDomainWhitelistingEnabled,
1544
- whitelistedDomains = question.whitelistedDomains,
1545
- isDomainBlacklistingEnabled = question.isDomainBlacklistingEnabled,
1546
- blacklistedDomains = question.blacklistedDomains,
1547
- isVerificationEnabled = question.isVerificationEnabled,
1548
- nodeId = question.nodeId,
1549
- formId = question.formId;
1550
- var label = fieldWithFallback(question, "label");
1551
- var _useState = useState(DEFAULT_CALLOUT_DETAILS),
1552
- _useState2 = _slicedToArray(_useState, 2),
1553
- calloutDetails = _useState2[0],
1554
- setCalloutDetails = _useState2[1];
1555
- var type = QUESTION_KIND[kind.toUpperCase()].type;
1556
- var _useState3 = useState(getLastVerificationCodeSentAt(questionId) > 0),
1557
- _useState4 = _slicedToArray(_useState3, 2),
1558
- hasSentVerificationCode = _useState4[0],
1559
- setHasSentVerificationCode = _useState4[1];
1560
- var verificationStatus = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.VERIFIED);
1561
- var _useStateWithDependen = useStateWithDependency(verificationStatus, [verificationStatus]),
1562
- _useStateWithDependen2 = _slicedToArray(_useStateWithDependen, 2),
1563
- isCodeVerified = _useStateWithDependen2[0],
1564
- setIsCodeVerified = _useStateWithDependen2[1];
1565
- var _useField = useField({
1566
- name: questionId || nodeId,
1567
- validate: validateFieldValue({
1568
- kind: kind,
1569
- label: label,
1570
- isRequired: isRequired,
1571
- customValidator: customValidator,
1572
- whitelistedDomains: isDomainWhitelistingEnabled ? whitelistedDomains : [],
1573
- blacklistedDomains: isDomainBlacklistingEnabled ? blacklistedDomains : []
1574
- })
1575
- }),
1576
- _useField2 = _slicedToArray(_useField, 3),
1577
- field = _useField2[0],
1578
- _useField2$ = _useField2[1],
1579
- touched = _useField2$.touched,
1580
- error = _useField2$.error,
1581
- _useField2$2 = _useField2[2],
1582
- setValue = _useField2$2.setValue,
1583
- setTouched = _useField2$2.setTouched;
1584
- var _useFormikContext = useFormikContext(),
1585
- setFieldValue = _useFormikContext.setFieldValue;
1586
- var email = field.value;
1587
- var emailVerificationToken = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.TOKEN);
1588
- var handleResponseError = function handleResponseError(error) {
1589
- var _error$response;
1590
- var message = error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 || (_error$response = _error$response.data) === null || _error$response === void 0 ? void 0 : _error$response.error;
1591
- if ((error === null || error === void 0 ? void 0 : error.status) === 429) {
1592
- setCalloutDetails({
1593
- message: message,
1594
- style: CALLOUT_STYLES.ERROR
1595
- });
1596
- storeLastVerificationCodeSentAt(formId, questionId, RESEND_DELAY * ONE_SECOND);
1597
- } else {
1598
- Toastr.error(message);
1599
- }
1600
- };
1601
-
1602
- // TODO backend validation
1603
- var _useSendEmailVerifica = useSendEmailVerificationCode(formId, questionId, {
1604
- onSuccess: function onSuccess(_ref2) {
1605
- var token = _ref2.token,
1606
- message = _ref2.message;
1607
- setHasSentVerificationCode(true);
1608
- storeLastVerificationCodeSentAt(formId, questionId);
1609
- if (!emailVerificationToken) {
1610
- setEmailVerificationDetail(formId, questionId, _defineProperty({}, EMAIL_VERIFICATION_KEYS.TOKEN, token));
1611
- }
1612
- if (message) {
1613
- setCalloutDetails({
1614
- message: message,
1615
- style: CALLOUT_STYLES.WARNING
1616
- });
1617
- }
1618
- },
1619
- onError: handleResponseError
1620
- }),
1621
- sendVerificationCode = _useSendEmailVerifica.mutate,
1622
- isSendingVerificationCode = _useSendEmailVerifica.isPending;
1623
- var resetVerifiedData = function resetVerifiedData(email) {
1624
- var verifiedEmail = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.EMAIL);
1625
- if (email !== verifiedEmail) {
1626
- removeEmailVerificationDetail(formId, questionId, values(omit(["TOKEN"], EMAIL_VERIFICATION_KEYS)));
1627
- setIsCodeVerified(false);
1628
- setFieldValue(buildVerificationFieldName(questionId), "");
1629
- setHasSentVerificationCode(false);
1630
- setCalloutDetails(DEFAULT_CALLOUT_DETAILS);
1631
- }
1632
- };
1633
- var handleFieldChange = withEventTargetValue(setValue);
1634
- var handleSendVerificationCode = function handleSendVerificationCode() {
1635
- return sendVerificationCode({
1636
- emailVerifications: {
1637
- email: email,
1638
- token: emailVerificationToken
1639
- }
1640
- });
1641
- };
1642
- var shouldShowVerifyButton = isVerificationEnabled && !isUrlBuilderPreview && (isFormPreview || isPresent(email) && isNotPresent(error));
1643
- var shouldShowVerificationCodeInput = shouldShowVerifyButton && !isFormPreview && !isCodeVerified;
1644
- return /*#__PURE__*/jsxs("div", {
1645
- className: "flex-col space-y-2",
1646
- children: [/*#__PURE__*/jsx(Input, _objectSpread$b(_objectSpread$b({}, _objectSpread$b(_objectSpread$b({
1647
- type: type
1648
- }, field), {}, {
1649
- autoComplete: autoComplete,
1650
- label: label
1651
- }, shouldShowVerifyButton && {
1652
- suffix: /*#__PURE__*/jsx(SendCodeButton, {
1653
- isCodeVerified: isCodeVerified,
1654
- isSendingVerificationCode: isSendingVerificationCode,
1655
- handleClick: isFormPreview ? noop : handleSendVerificationCode,
1656
- isDisabled: isCodeVerified || hasSentVerificationCode
1657
- })
1658
- })), {}, {
1659
- disabled: isReadOnly,
1660
- error: touched && !isCodeVerified ? error : "",
1661
- name: kind,
1662
- placeholder: fieldWithFallback(question, "placeholder"),
1663
- required: isRequired,
1664
- onBlur: function onBlur() {
1665
- return setTouched(true);
1666
- },
1667
- onBlurCapture: withEventTargetValue(resetVerifiedData),
1668
- onChange: handleFieldChange
1669
- })), shouldShowVerificationCodeInput && /*#__PURE__*/jsx(VerifyCode, {
1670
- calloutDetails: calloutDetails,
1671
- email: email,
1672
- emailVerificationToken: emailVerificationToken,
1673
- formId: formId,
1674
- handleResponseError: handleResponseError,
1675
- handleSendVerificationCode: handleSendVerificationCode,
1676
- hasSentVerificationCode: hasSentVerificationCode,
1677
- isCodeVerified: isCodeVerified,
1678
- isRequired: isRequired,
1679
- isVerificationEnabled: isVerificationEnabled,
1680
- questionId: questionId,
1681
- setIsCodeVerified: setIsCodeVerified
1682
- })]
1683
- });
1684
- };
1685
-
1686
- var FileUploadField = function FileUploadField(_ref) {
1687
- var question = _ref.question,
1688
- _ref$preview = _ref.preview,
1689
- preview = _ref$preview === void 0 ? false : _ref$preview,
1690
- customValidator = _ref.customValidator;
1691
- var name = question.id,
1692
- kind = question.kind,
1693
- isRequired = question.isRequired,
1694
- nodeId = question.nodeId,
1695
- allowedFileTypes = question.allowedFileTypes,
1696
- multipleFilesAllowed = question.multipleFilesAllowed,
1697
- maxFileSize = question.maxFileSize;
1698
- var label = fieldWithFallback(question, "label");
1699
- var _useField = useField({
1700
- name: name || nodeId,
1701
- validate: validateFieldValue({
1702
- kind: kind,
1703
- label: label,
1704
- isRequired: isRequired,
1705
- customValidator: customValidator,
1706
- multipleFilesAllowed: multipleFilesAllowed
1707
- })
1708
- }),
1709
- _useField2 = _slicedToArray(_useField, 3);
1710
- _useField2[0];
1711
- var _useField2$ = _useField2[1],
1712
- value = _useField2$.value,
1713
- touched = _useField2$.touched,
1714
- error = _useField2$.error,
1715
- _useField2$2 = _useField2[2],
1716
- setValue = _useField2$2.setValue,
1717
- setError = _useField2$2.setError,
1718
- setTouched = _useField2$2.setTouched;
1719
- var errorToDisplay = touched && error ? error : "";
1720
- return /*#__PURE__*/jsxs("div", {
1721
- className: "neeto-form-engine-input__wrapper",
1722
- children: [/*#__PURE__*/jsx("div", {
1723
- className: "neeto-form-engine-input__label-wrapper",
1724
- children: /*#__PURE__*/jsx(Label, {
1725
- className: "neeto-form-engine-label",
1726
- required: isRequired,
1727
- children: label
1728
- })
1729
- }), /*#__PURE__*/jsx(FileUpload, {
1730
- allowedFileTypes: allowedFileTypes,
1731
- maxFileSize: maxFileSize,
1732
- multipleFilesAllowed: multipleFilesAllowed,
1733
- setError: setError,
1734
- setTouched: setTouched,
1735
- error: errorToDisplay,
1736
- files: value === null || value === void 0 ? void 0 : value.files,
1737
- isPreview: preview,
1738
- onChange: function onChange(files) {
1739
- return setValue({
1740
- files: files
1741
- });
1742
- }
1743
- })]
1744
- });
1745
- };
1746
-
1747
- function ownKeys$a(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1748
- function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1749
- var Field = function Field(_ref) {
1750
- var question = _ref.question,
1751
- name = _ref.name,
1752
- labelField = _ref.labelField,
1753
- placeholderField = _ref.placeholderField,
1754
- customValidator = _ref.customValidator,
1755
- autoComplete = _ref.autoComplete;
1756
- var kind = question.kind,
1757
- isRequired = question.isRequired,
1758
- nodeId = question.nodeId,
1759
- isReadOnly = question.isReadOnly;
1760
- var label = fieldWithFallback(question, labelField);
1761
- var type = QUESTION_KIND.NAME.type;
1762
- var _useField = useField({
1763
- name: name || nodeId,
1764
- validate: validateFieldValue({
1765
- kind: kind,
1766
- label: label,
1767
- isRequired: isRequired,
1768
- customValidator: customValidator
1769
- })
1770
- }),
1771
- _useField2 = _slicedToArray(_useField, 3),
1772
- field = _useField2[0],
1773
- _useField2$ = _useField2[1],
1774
- touched = _useField2$.touched,
1775
- error = _useField2$.error,
1776
- _useField2$2 = _useField2[2],
1777
- setValue = _useField2$2.setValue,
1778
- setTouched = _useField2$2.setTouched;
1779
- return /*#__PURE__*/jsx(Input, _objectSpread$a(_objectSpread$a({}, _objectSpread$a(_objectSpread$a({
1780
- type: type
1781
- }, field), {}, {
1782
- autoComplete: autoComplete,
1783
- label: label,
1784
- name: name
1785
- })), {}, {
1786
- disabled: isReadOnly,
1787
- error: touched ? error : "",
1788
- placeholder: fieldWithFallback(question, placeholderField),
1789
- required: isRequired,
1790
- onBlur: function onBlur() {
1791
- return setTouched(true);
1792
- },
1793
- onChange: withEventTargetValue(setValue)
1794
- }));
1795
- };
1796
-
1797
- function ownKeys$9(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1798
- function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1799
- var NameField = function NameField(props) {
1800
- var _props$question = props.question,
1801
- id = _props$question.id,
1802
- isSplitMode = _props$question.isSplitMode;
1803
- if (isSplitMode) {
1804
- return /*#__PURE__*/jsxs("div", {
1805
- className: "flex w-full justify-between space-x-4",
1806
- children: [/*#__PURE__*/jsx(Field, _objectSpread$9(_objectSpread$9({}, props), {}, {
1807
- labelField: LABEL_FIELDS.FIRST_NAME,
1808
- name: "".concat(id, ".firstName"),
1809
- placeholderField: "firstNamePlaceholder"
1810
- })), /*#__PURE__*/jsx(Field, _objectSpread$9(_objectSpread$9({}, props), {}, {
1811
- labelField: LABEL_FIELDS.LAST_NAME,
1812
- name: "".concat(id, ".lastName"),
1813
- placeholderField: "lastNamePlaceholder"
1814
- }))]
1815
- });
1816
- }
1817
- return /*#__PURE__*/jsx(Field, _objectSpread$9(_objectSpread$9({}, props), {}, {
1818
- labelField: LABEL_FIELDS.FULL_NAME,
1819
- name: "".concat(id, ".fullName"),
1820
- placeholderField: "fullNamePlaceholder"
1821
- }));
1822
- };
1823
-
1824
- var OpinionScaleField = function OpinionScaleField(_ref) {
1825
- var question = _ref.question,
1826
- customValidator = _ref.customValidator;
1827
- var name = question.id,
1828
- kind = question.kind,
1829
- isRequired = question.isRequired,
1830
- minValue = question.minValue,
1831
- maxValue = question.maxValue,
1832
- isReadOnly = question.isReadOnly,
1833
- hasOpinionLabels = question.hasOpinionLabels;
1834
- var label = fieldWithFallback(question, "label");
1835
- var leftOpinionLabel = fieldWithFallback(question, "leftOpinionLabel");
1836
- var rightOpinionLabel = fieldWithFallback(question, "rightOpinionLabel");
1837
- var _useField = useField({
1838
- name: name,
1839
- validate: validateFieldValue({
1840
- kind: kind,
1841
- label: label,
1842
- isRequired: isRequired,
1843
- customValidator: customValidator
1844
- })
1845
- }),
1846
- _useField2 = _slicedToArray(_useField, 3),
1847
- field = _useField2[0],
1848
- _useField2$ = _useField2[1],
1849
- error = _useField2$.error,
1850
- touched = _useField2$.touched,
1851
- setValue = _useField2[2].setValue;
1852
- var handleClick = function handleClick(event, index) {
1853
- if (index !== parseInt(field.value)) return;
1854
- event.preventDefault();
1855
- setValue("");
1856
- };
1857
- var opinionScaleOptions = generateArray(minValue, maxValue);
1858
- return /*#__PURE__*/jsxs("div", {
1859
- className: "neeto-form-engine-input__wrapper neeto-form-engine-opinion-scale",
1860
- children: [/*#__PURE__*/jsx("div", {
1861
- className: "neeto-form-engine-input__label-wrapper",
1862
- children: /*#__PURE__*/jsx("label", {
1863
- className: "neeto-form-engine-label",
1864
- "data-testid": "opinion-scale-input-label",
1865
- children: getLabel(label, isRequired)
1866
- })
1867
- }), /*#__PURE__*/jsx("div", {
1868
- className: "neeto-form-nano-opinion-scale",
1869
- "data-testid": "form-opinion-scale",
1870
- children: /*#__PURE__*/jsxs("div", {
1871
- className: "neeto-form-nano-opinion-scale__group",
1872
- children: [hasOpinionLabels && /*#__PURE__*/jsx("div", {
1873
- className: "neeto-form-nano-opinion-scale__labels-wrap neeto-form-nano-opinion-scale__labels-wrap-mobile",
1874
- children: /*#__PURE__*/jsx("label", {
1875
- className: "neeto-form-nano-opinion-scale__label",
1876
- "data-testid": "opinion-scale-left-label",
1877
- children: leftOpinionLabel
1878
- })
1879
- }), /*#__PURE__*/jsx("ul", {
1880
- className: "neeto-form-nano-opinion-scale__list",
1881
- "data-testid": "opinion-scale-list",
1882
- children: opinionScaleOptions.map(function (step) {
1883
- return /*#__PURE__*/jsx("li", {
1884
- className: "neeto-form-nano-opinion-scale__item",
1885
- "data-testid": "opinion-scale-list-item",
1886
- children: /*#__PURE__*/jsxs("label", {
1887
- className: "neeto-form-nano-opinion-scale__item-label",
1888
- "data-testid": "opinion-scale-label",
1889
- onClick: function onClick(event) {
1890
- return handleClick(event, step);
1891
- },
1892
- children: [/*#__PURE__*/jsx(Field$1, {
1893
- name: name,
1894
- checked: parseInt(field.value) === step,
1895
- className: "neeto-form-nano-sr-only neeto-form-nano-opinion-scale__item-input",
1896
- "data-testid": "opinion-scale-input-".concat(step),
1897
- disabled: isReadOnly,
1898
- type: "radio",
1899
- value: step
1900
- }), /*#__PURE__*/jsx("span", {
1901
- className: "neeto-form-nano-opinion-scale__item-highlight",
1902
- "data-testid": "opinion-scale-item-".concat(step),
1903
- children: step
1904
- })]
1905
- })
1906
- }, step);
1907
- })
1908
- }), hasOpinionLabels && /*#__PURE__*/jsxs("div", {
1909
- className: "neeto-form-nano-opinion-scale__labels-wrap",
1910
- children: [/*#__PURE__*/jsx("label", {
1911
- className: "neeto-form-nano-opinion-scale__label neeto-form-nano-opinion-scale__label--start",
1912
- "data-testid": "opinion-scale-left-label",
1913
- children: leftOpinionLabel
1914
- }), /*#__PURE__*/jsx("label", {
1915
- className: "neeto-form-nano-opinion-scale__label neeto-form-nano-opinion-scale__label--end",
1916
- "data-testid": "opinion-scale-right-label",
1917
- children: rightOpinionLabel
1918
- })]
1919
- })]
1920
- })
1921
- }), touched && error && /*#__PURE__*/jsx("p", {
1922
- className: "neeto-form-engine-input__error",
1923
- "data-testid": "neeto-form-engine-opinion-scale-error",
1924
- children: error
1925
- })]
1926
- });
1927
- };
1928
-
1929
- var ChoiceImage = function ChoiceImage(_ref) {
1930
- var src = _ref.src,
1931
- alt = _ref.alt,
1932
- height = _ref.height,
1933
- shouldFitImages = _ref.shouldFitImages;
1934
- var _useState = useState(false),
1935
- _useState2 = _slicedToArray(_useState, 2),
1936
- hasError = _useState2[0],
1937
- setHasError = _useState2[1];
1938
- var _useState3 = useState(true),
1939
- _useState4 = _slicedToArray(_useState3, 2),
1940
- isLoading = _useState4[0],
1941
- setIsLoading = _useState4[1];
1942
- var handleLoad = function handleLoad() {
1943
- return setIsLoading(false);
1944
- };
1945
- var handleError = function handleError() {
1946
- setHasError(true);
1947
- setIsLoading(false);
1948
- };
1949
- if (hasError || !src) {
1950
- return /*#__PURE__*/jsx("div", {
1951
- className: "neeto-form-engine-choice__image-placeholder neeto-ui-bg-gray-100",
1952
- style: {
1953
- height: height
1954
- },
1955
- children: /*#__PURE__*/jsx(Image, {
1956
- size: 32
1957
- })
1958
- });
1959
- }
1960
- return /*#__PURE__*/jsx("div", {
1961
- style: {
1962
- height: height
1963
- },
1964
- className: classnames("neeto-form-engine-choice__image-wrapper", {
1965
- "neeto-form-engine-choice__image-wrapper--loading": isLoading
1966
- }),
1967
- children: /*#__PURE__*/jsx("img", {
1968
- alt: alt,
1969
- src: src,
1970
- draggable: false,
1971
- className: classnames("neeto-form-engine-choice__image", {
1972
- "neeto-form-engine-choice__image--fit": shouldFitImages
1973
- }),
1974
- onError: handleError,
1975
- onLoad: handleLoad
1976
- })
1977
- });
1978
- };
1979
-
1980
- var Choices$1 = function Choices(_ref) {
1981
- var label = _ref.label,
1982
- options = _ref.options,
1983
- type = _ref.type,
1984
- name = _ref.name,
1985
- value = _ref.value,
1986
- onChange = _ref.onChange,
1987
- onValueChange = _ref.onValueChange,
1988
- error = _ref.error,
1989
- disabled = _ref.isDisabled,
1990
- _ref$isPictureChoice = _ref.isPictureChoice,
1991
- isPictureChoice = _ref$isPictureChoice === void 0 ? DEFAULT_CHOICE_QUESTION_ATTRIBUTES.isPictureChoice : _ref$isPictureChoice,
1992
- _ref$imageHeight = _ref.imageHeight,
1993
- imageHeight = _ref$imageHeight === void 0 ? DEFAULT_CHOICE_QUESTION_ATTRIBUTES.imageHeight : _ref$imageHeight,
1994
- _ref$shouldFitImages = _ref.shouldFitImages,
1995
- shouldFitImages = _ref$shouldFitImages === void 0 ? DEFAULT_CHOICE_QUESTION_ATTRIBUTES.shouldFitImages : _ref$shouldFitImages;
1996
- var isCheckBox = type === "checkbox";
1997
- var ChoiceWrapper = isCheckBox ? "div" : Radio;
1998
- var Component = isCheckBox ? Checkbox : Radio.Item;
1999
- var handleChoiceValueChange = function handleChoiceValueChange(updatedValue) {
2000
- if (typeof onValueChange === "function") {
2001
- onValueChange(updatedValue);
2002
- return;
2003
- }
2004
- onChange({
2005
- target: {
2006
- name: name,
2007
- value: updatedValue
2008
- }
2009
- });
2010
- };
2011
- var shouldDeselectOption = function shouldDeselectOption(optionId) {
2012
- return !isCheckBox && !disabled && value === optionId;
2013
- };
2014
- var handleChoiceClick = function handleChoiceClick(event, optionId) {
2015
- if (!shouldDeselectOption(optionId)) return;
2016
- event.preventDefault();
2017
- handleChoiceValueChange("");
2018
- };
2019
- var handleChoiceKeyDown = function handleChoiceKeyDown(event, optionId) {
2020
- if (!shouldDeselectOption(optionId)) return;
2021
- if (!RADIO_DESELECT_KEYS.includes(event.key)) return;
2022
- event.preventDefault();
2023
- handleChoiceValueChange("");
2024
- };
2025
- return /*#__PURE__*/jsxs("div", {
2026
- className: "neeto-form-engine-choices__wrapper",
2027
- "data-testid": "".concat(hyphenate(label), "-select-container-wrapper"),
2028
- children: [/*#__PURE__*/jsx("label", {
2029
- className: "neeto-form-engine-label",
2030
- "data-testid": "".concat(hyphenate(label), "-input-label"),
2031
- children: label
2032
- }), /*#__PURE__*/jsx(ChoiceWrapper, {
2033
- stacked: !isCheckBox,
2034
- className: classnames("neeto-form-engine-choices", {
2035
- "neeto-form-engine-choices--picture": isPictureChoice
2036
- }),
2037
- children: options.map(function (option, index) {
2038
- var _value$index, _option$image;
2039
- var isChecked = isCheckBox ? (_value$index = value === null || value === void 0 ? void 0 : value[index]) !== null && _value$index !== void 0 ? _value$index : false : value === option.id;
2040
- return /*#__PURE__*/jsxs("label", {
2041
- htmlFor: option.id,
2042
- className: classnames("neeto-form-engine-choice", {
2043
- "neeto-form-engine-choice--picture": isPictureChoice,
2044
- "neeto-form-engine-choice--selected": isChecked,
2045
- "cursor-not-allowed": disabled
2046
- }),
2047
- onClick: function onClick(event) {
2048
- return handleChoiceClick(event, option.id);
2049
- },
2050
- children: [isPictureChoice && /*#__PURE__*/jsx(ChoiceImage, {
2051
- shouldFitImages: shouldFitImages,
2052
- alt: option.label,
2053
- height: imageHeight,
2054
- src: (_option$image = option.image) === null || _option$image === void 0 ? void 0 : _option$image.url
2055
- }), /*#__PURE__*/jsx(Component, {
2056
- disabled: disabled,
2057
- onChange: onChange,
2058
- type: type,
2059
- checked: isChecked,
2060
- className: classnames({
2061
- "cursor-not-allowed": disabled
2062
- }),
2063
- id: option.id,
2064
- label: option.label,
2065
- name: isCheckBox ? "".concat(name, ".").concat(index) : name,
2066
- value: option.id,
2067
- labelProps: {
2068
- className: classnames({
2069
- "cursor-not-allowed": disabled
2070
- })
2071
- },
2072
- onKeyDown: function onKeyDown(event) {
2073
- return handleChoiceKeyDown(event, option.id);
2074
- }
2075
- })]
2076
- }, option.id);
2077
- })
2078
- }), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
2079
- className: "neeto-form-engine-input__error",
2080
- "data-testid": "neeto-form-engine-".concat(type, "-error"),
2081
- children: error
2082
- })]
2083
- });
2084
- };
2085
- var Choices = /*#__PURE__*/memo(Choices$1);
2086
-
2087
- function ownKeys$8(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2088
- function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$8(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$8(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2089
- var OptionsField = function OptionsField(_ref) {
2090
- var question = _ref.question,
2091
- customValidator = _ref.customValidator,
2092
- isLastFewElements = _ref.isLastFewElements;
2093
- var _useFormikContext = useFormikContext(),
2094
- setFieldTouched = _useFormikContext.setFieldTouched,
2095
- setFieldValue = _useFormikContext.setFieldValue,
2096
- validateField = _useFormikContext.validateField;
2097
- var name = question.id,
2098
- kind = question.kind,
2099
- isRequired = question.isRequired,
2100
- isReadOnly = question.isReadOnly,
2101
- isPictureChoiceFromQuestion = question.isPictureChoice,
2102
- imageHeight = question.imageHeight,
2103
- shouldFitImages = question.shouldFitImages,
2104
- _question$optionsAttr = question.optionsAttributes,
2105
- options = _question$optionsAttr === void 0 ? [] : _question$optionsAttr;
2106
- var isPictureChoice = isPictureChoiceFromQuestion;
2107
- var isDropdown = kind === QUESTION_KIND.DROPDOWN.value;
2108
- var label = fieldWithFallback(question, "label");
2109
- var Component = isDropdown ? Select : Choices;
2110
- var transformedOptions = isDropdown ? options.map(function (option) {
2111
- return {
2112
- label: fieldWithFallback(option, "label"),
2113
- position: option.position,
2114
- value: option.id
2115
- };
2116
- }) : options.map(function (option) {
2117
- return _objectSpread$8(_objectSpread$8({}, option), {}, {
2118
- label: fieldWithFallback(option, "label")
2119
- });
2120
- });
2121
- var handleSelect = function handleSelect(option) {
2122
- setFieldValue(name, option === null || option === void 0 ? void 0 : option.value, false);
2123
- setFieldTouched(name, true, false);
2124
- setTimeout(function () {
2125
- return validateField(name);
2126
- });
2127
- };
2128
- var handleValueChange = function handleValueChange(updatedValue) {
2129
- setFieldValue(name, updatedValue, false);
2130
- setFieldTouched(name, true, false);
2131
- setTimeout(function () {
2132
- return validateField(name);
2133
- });
2134
- };
2135
- var customFilter = function customFilter(option, inputValue) {
2136
- if (!option) return false;
2137
- return containsIgnoreCase(option.label, inputValue);
2138
- };
2139
- return /*#__PURE__*/jsx(Field$1, {
2140
- name: name,
2141
- validate: validateFieldValue({
2142
- kind: kind,
2143
- label: label,
2144
- isRequired: isRequired,
2145
- customValidator: customValidator
2146
- }),
2147
- children: function children(_ref2) {
2148
- var meta = _ref2.meta,
2149
- field = _ref2.field;
2150
- var onChange = field.onChange,
2151
- value = field.value;
2152
- return /*#__PURE__*/jsx(Component, _objectSpread$8(_objectSpread$8({
2153
- error: getError(meta),
2154
- isDisabled: isReadOnly,
2155
- label: getLabel(label, isRequired),
2156
- options: transformedOptions,
2157
- strategy: "fixed",
2158
- type: kind
2159
- }, _objectSpread$8(_objectSpread$8({
2160
- isRequired: isRequired,
2161
- name: name
2162
- }, isDropdown && {
2163
- filterOption: customFilter
2164
- }), !isDropdown && {
2165
- imageHeight: imageHeight,
2166
- isPictureChoice: isPictureChoice,
2167
- shouldFitImages: shouldFitImages
2168
- })), {}, {
2169
- value: isDropdown ? findBy({
2170
- value: value
2171
- }, transformedOptions) || null : value,
2172
- onChange: isDropdown ? handleSelect : onChange,
2173
- onValueChange: !isDropdown ? handleValueChange : undefined
2174
- }, isDropdown && {
2175
- isClearable: true,
2176
- menuPlacement: isLastFewElements ? "top" : "auto",
2177
- menuPortalTarget: document.body,
2178
- menuPosition: "fixed"
2179
- }));
2180
- }
2181
- });
2182
- };
2183
-
2184
- var PhoneNumberField = function PhoneNumberField(_ref) {
2185
- var _getPhoneData;
2186
- var question = _ref.question,
2187
- autoComplete = _ref.autoComplete,
2188
- isLastFewElements = _ref.isLastFewElements;
2189
- var name = question.id,
2190
- kind = question.kind,
2191
- isRequired = question.isRequired,
2192
- nodeId = question.nodeId,
2193
- isReadOnly = question.isReadOnly;
2194
- var label = fieldWithFallback(question, "label");
2195
- var _useField = useField({
2196
- name: name || nodeId,
2197
- validate: validateFieldValue({
2198
- kind: kind,
2199
- label: label,
2200
- isRequired: isRequired
2201
- })
2202
- }),
2203
- _useField2 = _slicedToArray(_useField, 3),
2204
- value = _useField2[0].value,
2205
- _useField2$ = _useField2[1],
2206
- touched = _useField2$.touched,
2207
- error = _useField2$.error,
2208
- _useField2$2 = _useField2[2],
2209
- setValue = _useField2$2.setValue,
2210
- setTouched = _useField2$2.setTouched;
2211
- return /*#__PURE__*/jsx(PhoneNumberInput, {
2212
- autoComplete: autoComplete,
2213
- label: label,
2214
- value: value,
2215
- className: "neeto-form-engine-input__wrapper items-stretch",
2216
- disabled: isReadOnly,
2217
- error: touched ? error : "",
2218
- initialCountryCode: (_getPhoneData = getPhoneData(value)) === null || _getPhoneData === void 0 ? void 0 : _getPhoneData.country,
2219
- placeholder: fieldWithFallback(question, "placeholder"),
2220
- required: isRequired,
2221
- selectProps: {
2222
- isDisabled: isReadOnly,
2223
- menuPlacement: isLastFewElements ? "top" : "auto",
2224
- menuPortalTarget: document.body,
2225
- menuPosition: "fixed"
2226
- },
2227
- onBlur: function onBlur() {
2228
- return setTouched(true);
2229
- },
2230
- onChange: setValue
2231
- });
2232
- };
2233
-
2234
- var _excluded$2 = ["name", "label", "error", "lowestRatingLabel", "averageRatingLabel", "highestRatingLabel", "value", "disabled"];
2235
- function ownKeys$7(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2236
- function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2237
- var Rating$1 = function Rating(_ref) {
2238
- var name = _ref.name,
2239
- label = _ref.label,
2240
- error = _ref.error,
2241
- lowestRatingLabel = _ref.lowestRatingLabel,
2242
- averageRatingLabel = _ref.averageRatingLabel,
2243
- highestRatingLabel = _ref.highestRatingLabel,
2244
- value = _ref.value,
2245
- disabled = _ref.disabled,
2246
- other = _objectWithoutProperties(_ref, _excluded$2);
2247
- var handleClick = function handleClick(e) {
2248
- return e.currentTarget.nextElementSibling.click();
2249
- };
2250
- var render = function render() {
2251
- var labels = [highestRatingLabel, averageRatingLabel, lowestRatingLabel];
2252
- return RATING_OPTIONS.map(function (_ref2, index) {
2253
- var Icon = _ref2.icon,
2254
- modifier = _ref2.modifier,
2255
- rating = _ref2.value;
2256
- return /*#__PURE__*/jsxs(Fragment$1, {
2257
- children: [/*#__PURE__*/jsxs("button", {
2258
- disabled: disabled,
2259
- type: "button",
2260
- className: classnames("neeto-form-engine-rating__item neeto-form-engine-rating__item--".concat(modifier), {
2261
- active: rating === value
2262
- }),
2263
- onClick: handleClick,
2264
- children: [/*#__PURE__*/jsx(Icon, {}), /*#__PURE__*/jsx("label", {
2265
- className: "neeto-form-engine-label",
2266
- children: labels[index]
2267
- })]
2268
- }), /*#__PURE__*/jsx("input", _objectSpread$7({
2269
- name: name,
2270
- hidden: true,
2271
- checked: rating === value,
2272
- type: "radio",
2273
- value: rating
2274
- }, other))]
2275
- }, rating);
2276
- });
2277
- };
2278
- return /*#__PURE__*/jsxs("div", {
2279
- className: "neeto-form-engine-rating",
2280
- children: [/*#__PURE__*/jsx("label", {
2281
- className: "neeto-form-engine-label",
2282
- "data-testid": "rating-input-label",
2283
- children: label
2284
- }), /*#__PURE__*/jsx("div", {
2285
- className: "neeto-form-engine-rating__row",
2286
- "data-testid": "rating-input-field",
2287
- children: render()
2288
- }), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
2289
- className: "neeto-form-engine-input__error",
2290
- "data-testid": "neeto-form-engine-rating-error",
2291
- children: error
2292
- })]
2293
- });
2294
- };
2295
- var Rating = /*#__PURE__*/memo(Rating$1);
2296
-
2297
- function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2298
- function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2299
- var RatingField = function RatingField(_ref) {
2300
- var question = _ref.question,
2301
- customValidator = _ref.customValidator;
2302
- var name = question.id,
2303
- kind = question.kind,
2304
- isRequired = question.isRequired,
2305
- isReadOnly = question.isReadOnly;
2306
- var label = fieldWithFallback(question, "label");
2307
- return /*#__PURE__*/jsx(Field$1, {
2308
- name: name,
2309
- validate: validateFieldValue({
2310
- kind: kind,
2311
- label: label,
2312
- isRequired: isRequired,
2313
- customValidator: customValidator
2314
- }),
2315
- children: function children(_ref2) {
2316
- var meta = _ref2.meta,
2317
- field = _ref2.field;
2318
- return /*#__PURE__*/jsx(Rating, _objectSpread$6(_objectSpread$6({}, field), {}, {
2319
- disabled: isReadOnly,
2320
- error: meta.touched ? meta.error : "",
2321
- label: getLabel(label, isRequired),
2322
- averageRatingLabel: fieldWithFallback(question, "averageRatingLabel") || RATING_VALUES.AVERAGE.label,
2323
- highestRatingLabel: fieldWithFallback(question, "highestRatingLabel") || RATING_VALUES.GOOD.label,
2324
- lowestRatingLabel: fieldWithFallback(question, "lowestRatingLabel") || RATING_VALUES.BAD.label
2325
- }));
2326
- }
2327
- });
2328
- };
2329
-
2330
- function ownKeys$5(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2331
- function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2332
- var RichTextEditor = function RichTextEditor(_ref) {
2333
- var editorRef = _ref.editorRef,
2334
- question = _ref.question,
2335
- _ref$editorProps = _ref.editorProps,
2336
- editorProps = _ref$editorProps === void 0 ? {} : _ref$editorProps;
2337
- var _useFormikContext = useFormikContext(),
2338
- errors = _useFormikContext.errors,
2339
- touched = _useFormikContext.touched;
2340
- var name = question.id,
2341
- kind = question.kind,
2342
- isRequired = question.isRequired,
2343
- nodeId = question.nodeId,
2344
- isReadOnly = question.isReadOnly;
2345
- var label = fieldWithFallback(question, "label");
2346
- var debouncedPlaceholder = useDebounce(fieldWithFallback(question, "placeholder"), 300);
2347
- useEffect(function () {
2348
- var _editorRef$current, _editorRef$current$se;
2349
- editorRef === null || editorRef === void 0 || (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || (_editorRef$current = _editorRef$current.editor) === null || _editorRef$current === void 0 || (_editorRef$current$se = _editorRef$current.setEditable) === null || _editorRef$current$se === void 0 || _editorRef$current$se.call(_editorRef$current, !isReadOnly);
2350
- }, [editorRef === null || editorRef === void 0 ? void 0 : editorRef.current, isReadOnly]);
2351
- var propsToCompare = ["debouncedPlaceholder", "error", "touched", "isReadOnly"];
2352
- return /*#__PURE__*/jsxs("div", {
2353
- className: "neeto-form-engine-input__wrapper",
2354
- children: [/*#__PURE__*/jsx("div", {
2355
- className: "neeto-form-engine-input__label-wrapper",
2356
- children: label && /*#__PURE__*/jsx("label", {
2357
- className: "neeto-form-engine-label",
2358
- "data-testid": "".concat(hyphenate(label), "-input-label"),
2359
- children: getLabel(label, isRequired)
2360
- })
2361
- }), /*#__PURE__*/jsx(FastField, {
2362
- debouncedPlaceholder: debouncedPlaceholder,
2363
- isReadOnly: isReadOnly,
2364
- error: errors[name],
2365
- name: name || nodeId,
2366
- shouldUpdate: isPropsUnequal(propsToCompare),
2367
- touched: touched[name],
2368
- validate: validateFieldValue({
2369
- kind: kind,
2370
- label: label,
2371
- isRequired: isRequired
2372
- }),
2373
- children: function children(_ref2) {
2374
- var field = _ref2.field,
2375
- form = _ref2.form,
2376
- meta = _ref2.meta;
2377
- return /*#__PURE__*/jsx(NeetoEditor, _objectSpread$5({
2378
- editable: isReadOnly,
2379
- error: meta.touched ? meta.error : "",
2380
- initialValue: field.value,
2381
- menuType: isReadOnly ? "bubble" : "fixed",
2382
- placeholder: debouncedPlaceholder,
2383
- ref: editorRef,
2384
- addons: isReadOnly ? [] : ["attachments", "block-quote", "code-block", "image-upload"],
2385
- className: classnames("neeto-form-engine-rich-text-input", {
2386
- "cursor-not-allowed border": isReadOnly
2387
- }),
2388
- onBlur: function onBlur() {
2389
- return form.setFieldTouched(name, true);
2390
- },
2391
- onChange: function onChange(value) {
2392
- return form.setFieldValue(name, value);
2393
- }
2394
- }, editorProps), debouncedPlaceholder);
2395
- }
2396
- })]
2397
- });
2398
- };
2399
-
2400
- var _excluded$1 = ["value", "iconType", "label", "rating"];
2401
- function ownKeys$4(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2402
- function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2403
- var RatingButton$1 = function RatingButton(_ref) {
2404
- var _ref$value = _ref.value,
2405
- value = _ref$value === void 0 ? 0 : _ref$value,
2406
- iconType = _ref.iconType,
2407
- label = _ref.label,
2408
- rating = _ref.rating,
2409
- otherProps = _objectWithoutProperties(_ref, _excluded$1);
2410
- var handleClick = function handleClick(e) {
2411
- return e.currentTarget.nextElementSibling.click();
2412
- };
2413
- var Icon = ICONS_MAP[iconType];
2414
- var selectedRating = getSelectedRating(value);
2415
- return /*#__PURE__*/jsxs(Fragment, {
2416
- children: [/*#__PURE__*/jsxs("button", {
2417
- className: classnames({
2418
- active: rating === value
2419
- }),
2420
- disabled: otherProps === null || otherProps === void 0 ? void 0 : otherProps.disabled,
2421
- type: "button",
2422
- onClick: handleClick,
2423
- children: [/*#__PURE__*/jsx(Icon, {
2424
- size: 24,
2425
- className: classnames("neeto-form-engine-star-rating__icon", {
2426
- "neeto-form-engine-star-rating__icon--active": rating <= selectedRating
2427
- })
2428
- }), /*#__PURE__*/jsx("label", {
2429
- className: "neeto-form-engine-label",
2430
- children: label
2431
- })]
2432
- }), /*#__PURE__*/jsx("input", _objectSpread$4({
2433
- hidden: true,
2434
- checked: equals(rating, value),
2435
- type: "radio",
2436
- value: rating
2437
- }, otherProps))]
2438
- });
2439
- };
2440
- var RatingButton = /*#__PURE__*/memo(RatingButton$1);
2441
-
2442
- var _excluded = ["label", "minValue", "maxValue", "error"];
2443
- function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2444
- function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2445
- var StarRating$1 = function StarRating(_ref) {
2446
- var label = _ref.label,
2447
- minValue = _ref.minValue,
2448
- maxValue = _ref.maxValue,
2449
- error = _ref.error,
2450
- props = _objectWithoutProperties(_ref, _excluded);
2451
- return /*#__PURE__*/jsxs("div", {
2452
- className: "neeto-form-engine-input__wrapper neeto-form-engine-star-rating",
2453
- children: [/*#__PURE__*/jsx("div", {
2454
- className: "neeto-form-engine-input__label-wrapper",
2455
- children: /*#__PURE__*/jsx("label", {
2456
- className: "neeto-form-engine-label",
2457
- "data-testid": "star-rating-input-label",
2458
- children: label
2459
- })
2460
- }), /*#__PURE__*/jsx("div", {
2461
- className: "neeto-form-engine-star-rating__row",
2462
- "data-testid": "star-rating-input-field",
2463
- children: generateArray(minValue, maxValue).map(function (index) {
2464
- return /*#__PURE__*/jsx(RatingButton, _objectSpread$3({
2465
- label: index,
2466
- rating: index
2467
- }, props), index);
2468
- })
2469
- }), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
2470
- className: "neeto-form-engine-input__error",
2471
- "data-testid": "neeto-form-engine-star-rating-error",
2472
- children: error
2473
- })]
2474
- });
2475
- };
2476
- var StarRating = /*#__PURE__*/memo(StarRating$1);
2477
-
2478
- function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2479
- function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2480
- var StarRatingField = function StarRatingField(_ref) {
2481
- var question = _ref.question,
2482
- customValidator = _ref.customValidator;
2483
- var name = question.id,
2484
- kind = question.kind,
2485
- isRequired = question.isRequired,
2486
- minValue = question.minValue,
2487
- maxValue = question.maxValue,
2488
- iconType = question.iconType,
2489
- isReadOnly = question.isReadOnly;
2490
- var label = fieldWithFallback(question, "label");
2491
- return /*#__PURE__*/jsx(Field$1, {
2492
- name: name,
2493
- validate: validateFieldValue({
2494
- kind: kind,
2495
- label: label,
2496
- isRequired: isRequired,
2497
- customValidator: customValidator
2498
- }),
2499
- children: function children(_ref2) {
2500
- var meta = _ref2.meta,
2501
- field = _ref2.field;
2502
- return /*#__PURE__*/jsx(StarRating, _objectSpread$2({
2503
- iconType: iconType,
2504
- maxValue: maxValue,
2505
- minValue: minValue,
2506
- name: name,
2507
- disabled: isReadOnly,
2508
- error: meta.touched ? meta.error : "",
2509
- label: getLabel(label, isRequired)
2510
- }, field));
2511
- }
2512
- });
2513
- };
2514
-
2515
- function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2516
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2517
- var TermsField = function TermsField(_ref) {
2518
- var question = _ref.question,
2519
- customValidator = _ref.customValidator;
2520
- var name = question.id,
2521
- kind = question.kind,
2522
- isRequired = question.isRequired,
2523
- nodeId = question.nodeId;
2524
- var label = fieldWithFallback(question, "label", true);
2525
- return /*#__PURE__*/jsx(Field$1, {
2526
- name: name || nodeId,
2527
- validate: validateFieldValue({
2528
- kind: kind,
2529
- label: label,
2530
- isRequired: isRequired,
2531
- customValidator: customValidator
2532
- }),
2533
- children: function children(_ref2) {
2534
- var meta = _ref2.meta,
2535
- field = _ref2.field;
2536
- return /*#__PURE__*/jsx("div", {
2537
- className: "neeto-form-engine-terms",
2538
- children: /*#__PURE__*/jsx(Checkbox, _objectSpread$1(_objectSpread$1({}, _objectSpread$1(_objectSpread$1({}, field), {}, {
2539
- name: name
2540
- })), {}, {
2541
- checked: field.value,
2542
- error: meta.touched ? meta.error : "",
2543
- children: /*#__PURE__*/jsx(EditorContent, {
2544
- content: label
2545
- })
2546
- }))
2547
- });
2548
- }
2549
- });
2550
- };
2551
-
2552
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2553
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2554
- var TextField = function TextField(_ref) {
2555
- var _otherProps$onChange;
2556
- var question = _ref.question,
2557
- customValidator = _ref.customValidator,
2558
- autoComplete = _ref.autoComplete;
2559
- var name = question.id,
2560
- kind = question.kind,
2561
- isRequired = question.isRequired,
2562
- isReadOnly = question.isReadOnly,
2563
- nodeId = question.nodeId;
2564
- var label = fieldWithFallback(question, "label");
2565
- var _QUESTION_KIND$kind$t = QUESTION_KIND[kind.toUpperCase()],
2566
- _QUESTION_KIND$kind$t2 = _QUESTION_KIND$kind$t.type,
2567
- type = _QUESTION_KIND$kind$t2 === void 0 ? "text" : _QUESTION_KIND$kind$t2,
2568
- onKeyDown = _QUESTION_KIND$kind$t.onKeyDown,
2569
- otherProps = _QUESTION_KIND$kind$t.otherProps;
2570
- var Component = kind === QUESTION_KIND.TEXTAREA.value ? Textarea : Input;
2571
- var _useField = useField({
2572
- name: name || nodeId,
2573
- validate: validateFieldValue({
2574
- kind: kind,
2575
- label: label,
2576
- isRequired: isRequired,
2577
- customValidator: customValidator
2578
- })
2579
- }),
2580
- _useField2 = _slicedToArray(_useField, 3),
2581
- field = _useField2[0],
2582
- _useField2$ = _useField2[1],
2583
- touched = _useField2$.touched,
2584
- error = _useField2$.error,
2585
- _useField2$2 = _useField2[2],
2586
- setValue = _useField2$2.setValue,
2587
- setTouched = _useField2$2.setTouched;
2588
- var handleFieldChange = withEventTargetValue(setValue);
2589
- return /*#__PURE__*/jsx(Component, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({
2590
- type: type
2591
- }, field), {}, {
2592
- autoComplete: autoComplete,
2593
- label: label,
2594
- onKeyDown: onKeyDown
2595
- })), {}, {
2596
- disabled: isReadOnly,
2597
- error: touched ? error : "",
2598
- name: slugify(label),
2599
- placeholder: fieldWithFallback(question, "placeholder"),
2600
- required: isRequired,
2601
- onBlur: function onBlur() {
2602
- return setTouched(true);
2603
- },
2604
- onChange: (_otherProps$onChange = otherProps === null || otherProps === void 0 ? void 0 : otherProps.onChange(handleFieldChange)) !== null && _otherProps$onChange !== void 0 ? _otherProps$onChange : handleFieldChange
2605
- }));
2606
- };
2607
-
2608
- var _QUESTION_TO_COMPONEN;
2609
- var QUESTION_TO_COMPONENT_MAP = (_QUESTION_TO_COMPONEN = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.TEXT.value, TextField), QUESTION_KIND.NAME.value, NameField), QUESTION_KIND.EMAIL.value, EmailField), QUESTION_KIND.INTEGER.value, TextField), QUESTION_KIND.DECIMAL.value, TextField), QUESTION_KIND.PHONE.value, PhoneNumberField), QUESTION_KIND.QUESTION.value, TextField), QUESTION_KIND.TEXTAREA.value, TextField), QUESTION_KIND.CHECKBOX.value, OptionsField), QUESTION_KIND.RADIO.value, OptionsField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.DROPDOWN.value, OptionsField), QUESTION_KIND.RATING.value, RatingField), QUESTION_KIND.PARAGRAPH.value, function (_ref) {
2610
- var question = _ref.question;
2611
- return /*#__PURE__*/jsx(EditorContent, {
2612
- content: fieldWithFallback(question, "label", true)
2613
- });
2614
- }), QUESTION_KIND.TERMS.value, TermsField), QUESTION_KIND.DATE.value, DateField), QUESTION_KIND.STAR_RATING.value, StarRatingField), QUESTION_KIND.OPINION_SCALE.value, OpinionScaleField), QUESTION_KIND.ADDITIONAL_GUESTS.value, MultipleEmailInput), QUESTION_KIND.RICH_TEXT.value, RichTextEditor), QUESTION_KIND.CONDITION.value, ConditionField), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.FILE_UPLOAD.value, FileUploadField), QUESTION_KIND.CAPTCHA.value, CaptchaField), QUESTION_KIND.SMS_REMINDER.value, PhoneNumberField), QUESTION_KIND.ADDRESS.value, AddressField));
2615
- var CAPTCHA_COMPONENT_MAP = _defineProperty(_defineProperty({}, CAPTCHA_TYPES.RECAPTCHA_V2, Recaptcha), CAPTCHA_TYPES.MATH_CAPTCHA, MathCaptcha);
2616
-
2617
- var getFieldComponent = function getFieldComponent(_ref) {
2618
- var kind = _ref.kind;
2619
- if (kind in QUESTION_TO_COMPONENT_MAP) return QUESTION_TO_COMPONENT_MAP[kind];
2620
- return function () {
2621
- return null;
2622
- };
2623
- };
2624
- var isPropsUnequal = function isPropsUnequal(props) {
2625
- return function (nextProps, prevProps) {
2626
- return notEqualsDeep(pick(props, nextProps), pick(props, prevProps));
2627
- };
2628
- };
2629
- var getValidDate = function getValidDate(date) {
2630
- if (!date) return "";
2631
- return dayjs(date).isValid() ? dayjs(date) : "";
2632
- };
2633
- var getPhoneData = function getPhoneData(value, countryCode) {
2634
- try {
2635
- return parsePhoneNumber(value, countryCode);
2636
- } catch (_unused) {
2637
- return undefined;
2638
- }
2639
- };
2640
- var containsIgnoreCase = function containsIgnoreCase(string, substring) {
2641
- return string.toLowerCase().includes(substring.toLowerCase());
2642
- };
2643
- var getVisibleOptions = function getVisibleOptions(options) {
2644
- return Array.isArray(options) ? options.filter(function (option) {
2645
- return !option.deleted;
2646
- }).sort(function (a, b) {
2647
- return a.position - b.position;
2648
- }) : [];
2649
- };
2650
-
2651
- export { FormikWrap as F, generateInitValues as a, buildAutoCompleteAttribute as b, clientI18nInstance as c, getWithExpiry as d, clearEmailVerificationDetails as e, generateFormResponse as f, getFieldComponent as g, clearLocalStorageValues as h, mergeRefs as m, renderButtonsInOrder as r };
2652
- //# sourceMappingURL=utils-C9nDMm4c.js.map