@bigbinary/neeto-form-frontend 4.4.27 → 4.4.29

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