@bigbinary/neeto-form-frontend 4.4.9 → 4.4.11

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