@bigbinary/neeto-form-frontend 4.4.9 → 4.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +2 -4
  2. package/app/javascript/src/translations/en.json +9 -1
  3. package/dist/.ready +1 -0
  4. package/dist/BuildForm.js +3127 -0
  5. package/dist/BuildForm.js.map +1 -0
  6. package/dist/ExternalForm.js +647 -0
  7. package/dist/ExternalForm.js.map +1 -0
  8. package/dist/NeetoFormProvider.js +11 -0
  9. package/dist/NeetoFormProvider.js.map +1 -0
  10. package/dist/Submission.js +2832 -0
  11. package/dist/Submission.js.map +1 -0
  12. package/dist/UrlBuilder.js +317 -0
  13. package/dist/UrlBuilder.js.map +1 -0
  14. package/dist/buildForm-CrOWLvLE.js +35 -0
  15. package/dist/buildForm-CrOWLvLE.js.map +1 -0
  16. package/dist/buildForm-DfMpfuSp.js +38 -0
  17. package/dist/buildForm-DfMpfuSp.js.map +1 -0
  18. package/dist/cjs/BuildForm.js +3148 -0
  19. package/dist/cjs/BuildForm.js.map +1 -0
  20. package/dist/cjs/ExternalForm.js +649 -0
  21. package/dist/cjs/ExternalForm.js.map +1 -0
  22. package/dist/cjs/NeetoFormProvider.js +13 -0
  23. package/dist/cjs/NeetoFormProvider.js.map +1 -0
  24. package/dist/cjs/Submission.js +2834 -0
  25. package/dist/cjs/Submission.js.map +1 -0
  26. package/dist/cjs/UrlBuilder.js +319 -0
  27. package/dist/cjs/UrlBuilder.js.map +1 -0
  28. package/dist/cjs/hooks.js +33 -0
  29. package/dist/cjs/hooks.js.map +1 -0
  30. package/dist/cjs/index.js +114 -0
  31. package/dist/cjs/index.js.map +1 -0
  32. package/dist/constants-Cj0XxE8a.js +494 -0
  33. package/dist/constants-Cj0XxE8a.js.map +1 -0
  34. package/dist/constants-D5JlvWws.js +513 -0
  35. package/dist/constants-D5JlvWws.js.map +1 -0
  36. package/dist/hooks.js +20 -0
  37. package/dist/hooks.js.map +1 -0
  38. package/dist/index-Beo6ztaM.js +51 -0
  39. package/dist/index-Beo6ztaM.js.map +1 -0
  40. package/dist/index-DhtQJpD_.js +43 -0
  41. package/dist/index-DhtQJpD_.js.map +1 -0
  42. package/dist/index.js +96 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/main.css +2 -0
  45. package/dist/main.css.map +1 -0
  46. package/dist/useFormSubmission-D3O7sDHp.js +24 -0
  47. package/dist/useFormSubmission-D3O7sDHp.js.map +1 -0
  48. package/dist/useFormSubmission-PLRMfzJ3.js +22 -0
  49. package/dist/useFormSubmission-PLRMfzJ3.js.map +1 -0
  50. package/dist/utils-H7u9B9Jq.js +2731 -0
  51. package/dist/utils-H7u9B9Jq.js.map +1 -0
  52. package/dist/utils-QSMxxdQN.js +2762 -0
  53. package/dist/utils-QSMxxdQN.js.map +1 -0
  54. package/dist/yup-B3JGBWm7.js +1029 -0
  55. package/dist/yup-B3JGBWm7.js.map +1 -0
  56. package/dist/yup-DfKhsn0t.js +1114 -0
  57. package/dist/yup-DfKhsn0t.js.map +1 -0
  58. package/package.json +8 -8
  59. package/types.d.ts +1 -0
@@ -0,0 +1,2762 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var formik = require('formik');
5
+ var neetoCist = require('@bigbinary/neeto-cist');
6
+ var index = require('./index-Beo6ztaM.js');
7
+ var utils = require('@bigbinary/neeto-commons-frontend/utils');
8
+ var libphonenumberJs = require('libphonenumber-js');
9
+ var ramda = require('ramda');
10
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
11
+ var EditorContent = require('@bigbinary/neeto-editor/EditorContent');
12
+ var constants = require('./constants-D5JlvWws.js');
13
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
14
+ var Plus = require('@bigbinary/neeto-icons/Plus');
15
+ var Button = require('@bigbinary/neetoui/Button');
16
+ var NeetoUIMultiEmailInput = require('@bigbinary/neetoui/MultiEmailInput');
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$1 = require('@bigbinary/neeto-editor/utils');
22
+ var PhoneNumber = require('@bigbinary/neeto-molecules/PhoneNumber');
23
+ var i18next = require('i18next');
24
+ var jsxRuntime = require('react/jsx-runtime');
25
+ var yup = require('./yup-DfKhsn0t.js');
26
+ var _toArray = require('@babel/runtime/helpers/toArray');
27
+ var yup$1 = require('yup');
28
+ var classnames = require('classnames');
29
+ var Select = require('@bigbinary/neetoui/Select');
30
+ var Input = require('@bigbinary/neetoui/Input');
31
+ var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
32
+ var Refresh = require('@bigbinary/neeto-icons/Refresh');
33
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
34
+ var initializers = require('@bigbinary/neeto-commons-frontend/initializers');
35
+ var ReCAPTCHA = require('react-google-recaptcha');
36
+ var Checkbox = require('@bigbinary/neetoui/Checkbox');
37
+ var DatePicker = require('@bigbinary/neetoui/DatePicker');
38
+ var Toastr = require('@bigbinary/neetoui/Toastr');
39
+ var reactQuery = require('@tanstack/react-query');
40
+ var axios = require('axios');
41
+ var CheckCircle = require('@bigbinary/neeto-icons/CheckCircle');
42
+ var Spinner = require('@bigbinary/neetoui/Spinner');
43
+ var NeetoUICallout = require('@bigbinary/neetoui/Callout');
44
+ var FileUpload = require('@bigbinary/neeto-molecules/FileUpload');
45
+ var Label = require('@bigbinary/neetoui/Label');
46
+ var Radio = require('@bigbinary/neetoui/Radio');
47
+ var Image = require('@bigbinary/neeto-icons/Image');
48
+ var NeetoEditor = require('@bigbinary/neeto-editor/Editor');
49
+ var Info = require('@bigbinary/neeto-icons/Info');
50
+ var Textarea = require('@bigbinary/neetoui/Textarea');
51
+ var Tag = require('@bigbinary/neetoui/Tag');
52
+
53
+ function _interopNamespaceDefault(e) {
54
+ var n = Object.create(null);
55
+ if (e) {
56
+ Object.keys(e).forEach(function (k) {
57
+ if (k !== 'default') {
58
+ var d = Object.getOwnPropertyDescriptor(e, k);
59
+ Object.defineProperty(n, k, d.get ? d : {
60
+ enumerable: true,
61
+ get: function () { return e[k]; }
62
+ });
63
+ }
64
+ });
65
+ }
66
+ n.default = e;
67
+ return Object.freeze(n);
68
+ }
69
+
70
+ var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup$1);
71
+
72
+ var clientI18nInstance = i18next.cloneInstance();
73
+
74
+ var clearLocalStorageValues = function clearLocalStorageValues(key) {
75
+ try {
76
+ localStorage.removeItem(key);
77
+ } catch (error) {
78
+ // eslint-disable-next-line no-console
79
+ console.error(error);
80
+ }
81
+ };
82
+ var setWithExpiry = function setWithExpiry(key, value) {
83
+ var expireInDays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
84
+ var expiryDate = utils.dayjs().add(expireInDays, "day").toDate();
85
+ var item = {
86
+ value: value,
87
+ localStorageExpiry: expiryDate.getTime()
88
+ };
89
+ try {
90
+ localStorage.setItem(key, JSON.stringify(item));
91
+ } catch (error) {
92
+ // eslint-disable-next-line no-console
93
+ console.error(error);
94
+ }
95
+ };
96
+ var getWithExpiry = function getWithExpiry(key) {
97
+ try {
98
+ var itemStr = localStorage.getItem(key);
99
+ if (!itemStr) {
100
+ return null;
101
+ }
102
+ var item = JSON.parse(itemStr);
103
+ var now = new Date();
104
+ if (now.getTime() > item.localStorageExpiry) {
105
+ localStorage.removeItem(key);
106
+ return null;
107
+ }
108
+ return item.value;
109
+ } catch (error) {
110
+ // eslint-disable-next-line no-console
111
+ console.error(error);
112
+ return null;
113
+ }
114
+ };
115
+
116
+ var FormikWrap = function FormikWrap(_ref) {
117
+ var onError = _ref.onError,
118
+ children = _ref.children,
119
+ formId = _ref.formId,
120
+ preserveValues = _ref.preserveValues,
121
+ onValuesChange = _ref.onValuesChange,
122
+ dataUpdateCount = _ref.dataUpdateCount;
123
+ var _useFormikContext = formik.useFormikContext(),
124
+ errors = _useFormikContext.errors,
125
+ touched = _useFormikContext.touched,
126
+ isValid = _useFormikContext.isValid,
127
+ isSubmitting = _useFormikContext.isSubmitting,
128
+ values = _useFormikContext.values,
129
+ validateForm = _useFormikContext.validateForm;
130
+ var revalidate = function revalidate() {
131
+ return neetoCist.isPresent(errors) && validateForm();
132
+ };
133
+ React.useEffect(function () {
134
+ revalidate();
135
+ }, [clientI18nInstance.language, dataUpdateCount]);
136
+ var syncValuesWithLocalStorage = function syncValuesWithLocalStorage() {
137
+ return preserveValues && !index.isEmptyValues(values) && setWithExpiry("".concat(formId, "/values"), values);
138
+ };
139
+ React.useEffect(function () {
140
+ syncValuesWithLocalStorage();
141
+ onValuesChange && onValuesChange(values);
142
+ }, [values, formId, preserveValues]);
143
+ React.useEffect(function () {
144
+ if (isSubmitting || isValid) return;
145
+
146
+ // include only touched fields
147
+ var touchedErrors = Object.keys(errors).filter(function (key) {
148
+ return touched[key];
149
+ }).reduce(function (obj, key) {
150
+ obj[key] = errors[key];
151
+ return obj;
152
+ }, {});
153
+ if (index.isFunction(onError)) onError(touchedErrors);
154
+ }, [isValid, isSubmitting]);
155
+ return children;
156
+ };
157
+
158
+ var RESEND_DELAY = 120;
159
+ var ONE_SECOND = 1000;
160
+ var EMAIL_VERIFICATION_FIELD_NAME_PREFIX = "verificationCode";
161
+ var EMAIL_VERIFICATION_PREFIX = "neeto_form_nano_email_verification_details_";
162
+ var EMAIL_VERIFICATION_KEYS = {
163
+ EMAIL: "email",
164
+ TOKEN: "token",
165
+ VERIFIED: "verified",
166
+ CODE: "code",
167
+ CODE_SENT_AT: "code-sent-at"
168
+ };
169
+ var CALLOUT_STYLES = {
170
+ WARNING: "warning",
171
+ ERROR: "danger"
172
+ };
173
+ var DEFAULT_CALLOUT_DETAILS = {
174
+ message: "",
175
+ style: ""
176
+ };
177
+
178
+ var getEmailVerificationKey = function getEmailVerificationKey(formId) {
179
+ return "".concat(EMAIL_VERIFICATION_PREFIX, "-").concat(formId);
180
+ };
181
+ var getEmailVerificationDetails = function getEmailVerificationDetails(formId) {
182
+ return utils.getFromLocalStorage(getEmailVerificationKey(formId)) || {};
183
+ };
184
+ var buildVerificationFieldName = function buildVerificationFieldName(questionId) {
185
+ return "".concat(EMAIL_VERIFICATION_FIELD_NAME_PREFIX, "-").concat(questionId);
186
+ };
187
+ var getLastVerificationCodeSentAt = function getLastVerificationCodeSentAt(formId, questionId) {
188
+ var codeSentAt = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.CODE_SENT_AT);
189
+ return Number(codeSentAt) || 0;
190
+ };
191
+ var storeLastVerificationCodeSentAt = function storeLastVerificationCodeSentAt(formId, questionId) {
192
+ var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
193
+ return setEmailVerificationDetail(formId, questionId, _defineProperty({}, EMAIL_VERIFICATION_KEYS.CODE_SENT_AT, Date.now() - offset));
194
+ };
195
+ var getRemainingTime = function getRemainingTime(formId, questionId) {
196
+ var elapsedTime = Math.floor((Date.now() - getLastVerificationCodeSentAt(formId, questionId)) / ONE_SECOND);
197
+ return ramda.max(RESEND_DELAY - elapsedTime, 0);
198
+ };
199
+ var getEmailVerificationDetail = function getEmailVerificationDetail(formId, questionId) {
200
+ var _questionDetails$keys;
201
+ var allDetails = getEmailVerificationDetails(formId);
202
+ var questionDetails = allDetails[questionId] || {};
203
+ for (var _len = arguments.length, keys = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
204
+ keys[_key - 2] = arguments[_key];
205
+ }
206
+ return keys.length === 1 ? (_questionDetails$keys = questionDetails[keys[0]]) !== null && _questionDetails$keys !== void 0 ? _questionDetails$keys : "" : ramda.pick(keys, allDetails);
207
+ };
208
+ var setEmailVerificationDetail = function setEmailVerificationDetail(formId, questionId, data) {
209
+ var storageKey = getEmailVerificationKey(formId);
210
+ var allDetails = getEmailVerificationDetails(formId);
211
+ allDetails[questionId] = ramda.mergeRight(allDetails[questionId] || {}, data);
212
+ utils.setToLocalStorage(storageKey, allDetails);
213
+ };
214
+ var removeEmailVerificationDetail = function removeEmailVerificationDetail(formId, questionId) {
215
+ var storageKey = getEmailVerificationKey(formId);
216
+ var allDetails = getEmailVerificationDetails(formId);
217
+ for (var _len2 = arguments.length, keys = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
218
+ keys[_key2 - 2] = arguments[_key2];
219
+ }
220
+ allDetails[questionId] = ramda.omit(keys, allDetails[questionId]);
221
+ if (ramda.isEmpty(allDetails[questionId])) delete allDetails[questionId];
222
+ ramda.isEmpty(allDetails) ? utils.removeFromLocalStorage(storageKey) : utils.setToLocalStorage(storageKey, allDetails);
223
+ };
224
+ var clearEmailVerificationDetails = function clearEmailVerificationDetails(formId) {
225
+ utils.removeFromLocalStorage(getEmailVerificationKey(formId));
226
+ };
227
+
228
+ var t$1 = clientI18nInstance.t;
229
+ var getInvalidFieldError = function getInvalidFieldError(label) {
230
+ return t$1("neetoForm.error.invalidField", {
231
+ label: label
232
+ });
233
+ };
234
+ var getRequiredFieldError = function getRequiredFieldError(label) {
235
+ return t$1("neetoForm.error.requiredField", {
236
+ label: label
237
+ });
238
+ };
239
+ var getSelectMinError = function getSelectMinError() {
240
+ var entity = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : t$1("neetoForm.common.option");
241
+ return t$1("neetoForm.error.minOneEntity", {
242
+ entity: entity
243
+ });
244
+ };
245
+ var getInvalidTypeError = function getInvalidTypeError(label, type) {
246
+ return t$1("neetoForm.error.invalidType", {
247
+ label: label,
248
+ type: type
249
+ });
250
+ };
251
+
252
+ 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; }
253
+ 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; }
254
+ var resolveQueryParamValue = ramda.when(ramda.is(Array), ramda.last);
255
+ var toEmailValues = function toEmailValues() {
256
+ var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
257
+ return values.map(function (value) {
258
+ return {
259
+ label: value,
260
+ value: value,
261
+ valid: true
262
+ };
263
+ });
264
+ };
265
+ var getPhoneNumberFromUrl = function getPhoneNumberFromUrl(fieldCodes, fieldCode) {
266
+ var _resolveQueryParamVal;
267
+ var countryCode = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".country")]);
268
+ var phoneNumber = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".number")]);
269
+ var phoneNumberWithCountryCode = (_resolveQueryParamVal = resolveQueryParamValue(fieldCodes[fieldCode])) === null || _resolveQueryParamVal === void 0 ? void 0 : _resolveQueryParamVal.replace(yup.PARENTHESES_REGEX, "");
270
+ if (phoneNumberWithCountryCode) return phoneNumberWithCountryCode;
271
+ if (!countryCode || !phoneNumber) return undefined;
272
+ var formattedValue = getPhoneData(phoneNumber, countryCode);
273
+ if (!formattedValue) return undefined;
274
+ return formattedValue.formatInternational();
275
+ };
276
+ var getOptionFromURL = function getOptionFromURL(_ref) {
277
+ var _findBy;
278
+ var optionsAttributes = _ref.optionsAttributes,
279
+ fieldCodes = _ref.fieldCodes,
280
+ fieldCode = _ref.fieldCode;
281
+ var preFillOption = resolveQueryParamValue(fieldCodes[fieldCode]);
282
+ return (_findBy = neetoCist.findBy({
283
+ label: preFillOption
284
+ }, optionsAttributes)) === null || _findBy === void 0 ? void 0 : _findBy.id;
285
+ };
286
+ var getMultipleOptionsFromURL = function getMultipleOptionsFromURL(_ref2) {
287
+ var optionsAttributes = _ref2.optionsAttributes,
288
+ fieldCodes = _ref2.fieldCodes,
289
+ fieldCode = _ref2.fieldCode;
290
+ var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
291
+ if (!fieldCodeValue) return new Array(optionsAttributes.length).fill(false);
292
+ var allOptions = fieldCodeValue.split(",").map(ramda.trim);
293
+ return optionsAttributes.map(function (option) {
294
+ return allOptions.includes(option.label);
295
+ });
296
+ };
297
+ var getStarRatingOrOpinionScaleFromUrl = function getStarRatingOrOpinionScaleFromUrl(_ref3) {
298
+ var minValue = _ref3.minValue,
299
+ maxValue = _ref3.maxValue,
300
+ fieldCodes = _ref3.fieldCodes,
301
+ fieldCode = _ref3.fieldCode;
302
+ var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
303
+ var rating = parseInt(fieldCodeValue);
304
+ return ramda.isNil(rating) || isNaN(rating) ? "" : ramda.clamp(minValue, maxValue, rating);
305
+ };
306
+ var getAdditionalGuestsFromUrl = function getAdditionalGuestsFromUrl(_ref4) {
307
+ var fieldCodes = _ref4.fieldCodes,
308
+ fieldCode = _ref4.fieldCode;
309
+ var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
310
+ var allEmails = fieldCodeValue === null || fieldCodeValue === void 0 ? void 0 : fieldCodeValue.split(",");
311
+ if (!allEmails) return [];
312
+ return allEmails.map(function (email) {
313
+ return {
314
+ label: email.trim(),
315
+ value: email.trim(),
316
+ valid: yup.EMAIL_REGEX.test(email.trim())
317
+ };
318
+ });
319
+ };
320
+ var getRatingFromUrl = function getRatingFromUrl(_ref5) {
321
+ var fieldCodes = _ref5.fieldCodes,
322
+ fieldCode = _ref5.fieldCode;
323
+ var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
324
+ var allowedValues = Object.values(yup.RATING_VALUES).map(ramda.prop("value"));
325
+ return allowedValues.includes(fieldCodeValue) ? fieldCodeValue : "";
326
+ };
327
+ var getNumberFromUrl = function getNumberFromUrl(_ref6) {
328
+ var fieldCodes = _ref6.fieldCodes,
329
+ fieldCode = _ref6.fieldCode,
330
+ kind = _ref6.kind;
331
+ var fieldCodeValue = resolveQueryParamValue(fieldCodes[fieldCode]);
332
+ var parsedValue = kind === yup.QUESTION_KIND.INTEGER.value ? parseInt(fieldCodeValue) : parseFloat(fieldCodeValue);
333
+ return parsedValue || "";
334
+ };
335
+ var getNameFromUrl = function getNameFromUrl(_ref7, fieldCodes) {
336
+ var isSplitMode = _ref7.isSplitMode,
337
+ fieldCode = _ref7.fieldCode;
338
+ var fullName = resolveQueryParamValue(fieldCodes[fieldCode]) || "";
339
+ if (!isSplitMode) return {
340
+ fullName: fullName
341
+ };
342
+ var firstName = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".first_name")]) || "";
343
+ var lastName = resolveQueryParamValue(fieldCodes["".concat(fieldCode, ".last_name")]) || "";
344
+ if (neetoCist.isPresent(firstName) || neetoCist.isPresent(lastName)) {
345
+ return {
346
+ firstName: firstName,
347
+ lastName: lastName
348
+ };
349
+ }
350
+ if (neetoCist.isPresent(fullName)) {
351
+ var _fullName$trim$split = fullName.trim().split(/\s+/),
352
+ _fullName$trim$split2 = _toArray(_fullName$trim$split),
353
+ computedFirstName = _fullName$trim$split2[0],
354
+ remainingParts = _fullName$trim$split2.slice(1);
355
+ return {
356
+ firstName: computedFirstName,
357
+ lastName: remainingParts.join(" ")
358
+ };
359
+ }
360
+ return {
361
+ firstName: firstName,
362
+ lastName: lastName
363
+ };
364
+ };
365
+ var isValidSpotValue = function isValidSpotValue(value, remainingSlotsCount) {
366
+ var num = Number(value);
367
+ if (!Number.isInteger(num) || num <= 0) return false;
368
+ return !(typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0 && num > remainingSlotsCount);
369
+ };
370
+ var buildEmailVerificationEntries = function buildEmailVerificationEntries() {
371
+ var questions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
372
+ var emailQuestionsRequiringVerification = neetoCist.filterBy({
373
+ kind: constants.QUESTION_TYPES.EMAIL,
374
+ isVerificationEnabled: true
375
+ }, questions);
376
+ var fieldNames = ramda.map(function (_ref8) {
377
+ var id = _ref8.id;
378
+ return buildVerificationFieldName(id);
379
+ }, emailQuestionsRequiringVerification);
380
+ return ramda.zipObj(fieldNames, Array(fieldNames.length).fill(""));
381
+ };
382
+ var getLabel = function getLabel(label, isRequired) {
383
+ return isRequired ? "".concat(label, "*") : label;
384
+ };
385
+ var generateInitValues = function generateInitValues(_ref9) {
386
+ var questions = _ref9.questions,
387
+ _ref9$initialValues = _ref9.initialValues,
388
+ initialValues = _ref9$initialValues === void 0 ? [] : _ref9$initialValues,
389
+ _ref9$localValues = _ref9.localValues,
390
+ localValues = _ref9$localValues === void 0 ? {} : _ref9$localValues,
391
+ _ref9$fieldCodes = _ref9.fieldCodes,
392
+ fieldCodes = _ref9$fieldCodes === void 0 ? {} : _ref9$fieldCodes,
393
+ remainingSlotsCount = _ref9.remainingSlotsCount;
394
+ var initValues = {};
395
+ var valuesMap = {};
396
+ if (initialValues) {
397
+ valuesMap = initialValues.reduce(function (acc, answer) {
398
+ return _objectSpread$i(_objectSpread$i({}, acc), {}, _defineProperty({}, answer.questionId, {
399
+ value: answer.value,
400
+ optionIds: answer.optionIds
401
+ }));
402
+ }, {});
403
+ }
404
+ questions.forEach(function (question) {
405
+ var id = question.id,
406
+ kind = question.kind,
407
+ optionsAttributes = question.optionsAttributes,
408
+ fieldCode = question.fieldCode,
409
+ minValue = question.minValue,
410
+ maxValue = question.maxValue,
411
+ fields = question.fields;
412
+ switch (kind) {
413
+ case yup.QUESTION_KIND.CONDITION.value:
414
+ {
415
+ var _valuesMap$id$value, _valuesMap;
416
+ 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;
417
+ return;
418
+ }
419
+ case yup.QUESTION_KIND.ADDITIONAL_GUESTS.value:
420
+ {
421
+ var _valuesMap2;
422
+ var emailsFromSubmission = toEmailValues((_valuesMap2 = valuesMap) === null || _valuesMap2 === void 0 || (_valuesMap2 = _valuesMap2[id]) === null || _valuesMap2 === void 0 ? void 0 : _valuesMap2.value);
423
+ initValues[id] = neetoCist.isNotEmpty(emailsFromSubmission) ? emailsFromSubmission : getAdditionalGuestsFromUrl({
424
+ fieldCodes: fieldCodes,
425
+ fieldCode: fieldCode
426
+ });
427
+ return;
428
+ }
429
+ case yup.QUESTION_KIND.CHECKBOX.value:
430
+ {
431
+ var _valuesMap$id;
432
+ 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) {
433
+ var _valuesMap$id2;
434
+ 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);
435
+ }) : getMultipleOptionsFromURL({
436
+ optionsAttributes: optionsAttributes,
437
+ fieldCodes: fieldCodes,
438
+ fieldCode: fieldCode
439
+ });
440
+ return;
441
+ }
442
+ case yup.QUESTION_KIND.RADIO.value:
443
+ case yup.QUESTION_KIND.DROPDOWN.value:
444
+ {
445
+ var _optionsAttributes$fi;
446
+ var optionFromValues = optionsAttributes === null || optionsAttributes === void 0 || (_optionsAttributes$fi = optionsAttributes.find(function (option) {
447
+ var _valuesMap$id3;
448
+ 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);
449
+ })) === null || _optionsAttributes$fi === void 0 ? void 0 : _optionsAttributes$fi.id;
450
+ var optionFromUrl = getOptionFromURL({
451
+ optionsAttributes: optionsAttributes,
452
+ fieldCodes: fieldCodes,
453
+ fieldCode: fieldCode
454
+ });
455
+ initValues[id] = optionFromValues || optionFromUrl;
456
+ return;
457
+ }
458
+ case yup.QUESTION_KIND.SPOT.value:
459
+ {
460
+ var _valuesMap$id$value2, _valuesMap3;
461
+ var urlValue = getNumberFromUrl({
462
+ fieldCodes: fieldCodes,
463
+ fieldCode: fieldCode,
464
+ kind: yup.QUESTION_KIND.INTEGER.value
465
+ });
466
+ 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;
467
+ initValues[id] = isValidSpotValue(candidateValue, remainingSlotsCount) ? candidateValue : yup.SPOT_QUESTION_DEFAULT_VALUE;
468
+ return;
469
+ }
470
+ case yup.QUESTION_KIND.INTEGER.value:
471
+ case yup.QUESTION_KIND.DECIMAL.value:
472
+ {
473
+ var _valuesMap4;
474
+ initValues[id] = ((_valuesMap4 = valuesMap) === null || _valuesMap4 === void 0 || (_valuesMap4 = _valuesMap4[id]) === null || _valuesMap4 === void 0 ? void 0 : _valuesMap4.value) || getNumberFromUrl({
475
+ fieldCodes: fieldCodes,
476
+ fieldCode: fieldCode,
477
+ kind: kind
478
+ });
479
+ return;
480
+ }
481
+ case yup.QUESTION_KIND.RATING.value:
482
+ {
483
+ var _valuesMap5;
484
+ initValues[id] = ((_valuesMap5 = valuesMap) === null || _valuesMap5 === void 0 || (_valuesMap5 = _valuesMap5[id]) === null || _valuesMap5 === void 0 ? void 0 : _valuesMap5.value) || getRatingFromUrl({
485
+ fieldCodes: fieldCodes,
486
+ fieldCode: fieldCode
487
+ });
488
+ return;
489
+ }
490
+ case yup.QUESTION_KIND.TERMS.value:
491
+ {
492
+ initValues[id] = false;
493
+ return;
494
+ }
495
+ case yup.QUESTION_KIND.FILE_UPLOAD.value:
496
+ {
497
+ var _valuesMap$id$value3, _valuesMap6;
498
+ initValues[id] = {
499
+ 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 : []
500
+ };
501
+ return;
502
+ }
503
+ case yup.QUESTION_KIND.PHONE.value:
504
+ case yup.QUESTION_KIND.SMS_REMINDER.value:
505
+ {
506
+ var _valuesMap$id$value4, _valuesMap7;
507
+ 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);
508
+ return;
509
+ }
510
+ case yup.QUESTION_KIND.STAR_RATING.value:
511
+ case yup.QUESTION_KIND.OPINION_SCALE.value:
512
+ {
513
+ var _valuesMap$id$value5, _valuesMap8;
514
+ 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({
515
+ minValue: minValue,
516
+ maxValue: maxValue,
517
+ fieldCodes: fieldCodes,
518
+ fieldCode: fieldCode
519
+ });
520
+ return;
521
+ }
522
+ case yup.QUESTION_KIND.NAME.value:
523
+ {
524
+ var _valuesMap$id$value6, _valuesMap9;
525
+ 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);
526
+ return;
527
+ }
528
+ case yup.QUESTION_KIND.ADDRESS.value:
529
+ {
530
+ var _valuesMap$id$value7, _valuesMap10;
531
+ initValues[id] = (_valuesMap$id$value7 = (_valuesMap10 = valuesMap) === null || _valuesMap10 === void 0 || (_valuesMap10 = _valuesMap10[id]) === null || _valuesMap10 === void 0 ? void 0 : _valuesMap10.value) !== null && _valuesMap$id$value7 !== void 0 ? _valuesMap$id$value7 : fields.reduce(function (values, field) {
532
+ values[field.id] = "";
533
+ return values;
534
+ }, {});
535
+ return;
536
+ }
537
+ default:
538
+ {
539
+ var _valuesMap$id$value8, _valuesMap11;
540
+ initValues[id] = (_valuesMap$id$value8 = (_valuesMap11 = valuesMap) === null || _valuesMap11 === void 0 || (_valuesMap11 = _valuesMap11[id]) === null || _valuesMap11 === void 0 ? void 0 : _valuesMap11.value) !== null && _valuesMap$id$value8 !== void 0 ? _valuesMap$id$value8 : resolveQueryParamValue(fieldCodes[fieldCode] || "");
541
+ return;
542
+ }
543
+ }
544
+ });
545
+ var formInitialValues = !index.isEmptyValues(localValues) ? localValues : initValues;
546
+ return ramda.mergeLeft(formInitialValues, buildEmailVerificationEntries(questions));
547
+ };
548
+ var generateFormResponse = function generateFormResponse(response, questions) {
549
+ var formResponse = [];
550
+ questions.forEach(function (question) {
551
+ var id = question.id,
552
+ kind = question.kind,
553
+ optionsAttributes = question.optionsAttributes;
554
+ if (!yup.SCHEMA_LESS_QUESTION_KINDS.includes(kind)) {
555
+ var responseValue = response[id];
556
+ if (kind === yup.QUESTION_KIND.RADIO.value || kind === yup.QUESTION_KIND.DROPDOWN.value) {
557
+ var option = neetoCist.findById(responseValue, optionsAttributes);
558
+ if (option) {
559
+ formResponse.push({
560
+ questionId: id,
561
+ questionOptionId: option.id,
562
+ value: option.label,
563
+ kind: kind
564
+ });
565
+ }
566
+ } else if (kind === yup.QUESTION_KIND.SPOT.value) {
567
+ formResponse.push({
568
+ questionId: id,
569
+ value: responseValue,
570
+ kind: kind
571
+ });
572
+ } else if (kind === yup.QUESTION_KIND.CHECKBOX.value) {
573
+ responseValue.forEach(function (isChecked, index) {
574
+ if (!isChecked) return;
575
+ var option = optionsAttributes[index];
576
+ formResponse.push({
577
+ questionId: id,
578
+ questionOptionId: option.id,
579
+ value: option.label,
580
+ kind: kind
581
+ });
582
+ });
583
+ } else if (isPhoneNumberField(kind)) {
584
+ formResponse.push({
585
+ questionId: id,
586
+ value: responseValue ? libphonenumberJs.parsePhoneNumber(responseValue).formatInternational() : "",
587
+ kind: kind
588
+ });
589
+ } else if (kind === yup.QUESTION_KIND.ADDITIONAL_GUESTS.value) {
590
+ formResponse.push({
591
+ questionId: id,
592
+ value: responseValue ? ramda.pluck("value", responseValue) : null,
593
+ kind: kind
594
+ });
595
+ } else if (kind === yup.QUESTION_KIND.RICH_TEXT.value) {
596
+ formResponse.push({
597
+ questionId: id,
598
+ value: utils$1.isEditorEmpty(responseValue) ? null : responseValue,
599
+ kind: kind
600
+ });
601
+ } else if (kind === yup.QUESTION_KIND.FILE_UPLOAD.value) {
602
+ formResponse.push({
603
+ questionId: id,
604
+ files: neetoCist.isPresent(responseValue) ? responseValue.files : null,
605
+ kind: kind
606
+ });
607
+ } else if (kind === yup.QUESTION_KIND.DATE.value) {
608
+ formResponse.push({
609
+ questionId: id,
610
+ value: utils.dayjs(responseValue).isValid() ?
611
+ // YYYY-MM-DD format is not supported by dateFormat.
612
+ // eslint-disable-next-line @bigbinary/neeto/use-standard-date-time-formats
613
+ utils.dayjs(responseValue).format("YYYY-MM-DD") : "",
614
+ kind: kind
615
+ });
616
+ } else formResponse.push({
617
+ questionId: id,
618
+ value: responseValue,
619
+ kind: kind
620
+ });
621
+ }
622
+ });
623
+ return formResponse;
624
+ };
625
+ var mergeRefs = function mergeRefs() {
626
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
627
+ refs[_key] = arguments[_key];
628
+ }
629
+ return function (node) {
630
+ return refs.forEach(function (ref) {
631
+ return typeof ref === "function" ? ref(node) : ref.current = node;
632
+ });
633
+ };
634
+ };
635
+ var getError = function getError(meta) {
636
+ if (meta.error && meta.touched) {
637
+ return typeof meta.error === "string" ? meta.error : "";
638
+ }
639
+ return "";
640
+ };
641
+ var buildAutoCompleteAttribute = function buildAutoCompleteAttribute(kind, autoCompleteKinds, formDomProps) {
642
+ return (formDomProps === null || formDomProps === void 0 ? void 0 : formDomProps.autoComplete) === "off" && ramda.includes(kind, autoCompleteKinds) ? "on" : undefined;
643
+ };
644
+ var renderButtonsInOrder = function renderButtonsInOrder(buttonsArray, shouldReverse) {
645
+ var orderedButtons = shouldReverse ? buttonsArray.reverse() : buttonsArray;
646
+ return ramda.map(ramda.identity, orderedButtons);
647
+ };
648
+ var getSelectedRating = function getSelectedRating(value) {
649
+ var parsedValue = parseInt(value);
650
+ return isNaN(parsedValue) ? -1 : parsedValue;
651
+ };
652
+ var isPhoneNumberField = ramda.includes(ramda.__, [yup.QUESTION_KIND.PHONE.value, yup.QUESTION_KIND.SMS_REMINDER.value]);
653
+
654
+ var _excluded$4 = ["kind", "customValidator"];
655
+ var _fieldKindValidatorMa;
656
+ 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; }
657
+ 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; }
658
+ var t = clientI18nInstance.t;
659
+ var isValidDate = function isValidDate(date) {
660
+ return date && utils.dayjs(date).isValid();
661
+ };
662
+ var extractEmailDomain = function extractEmailDomain(email) {
663
+ return email === null || email === void 0 ? void 0 : email.split("@")[1];
664
+ };
665
+ var isEmailFromWhitelistedDomain = function isEmailFromWhitelistedDomain(email, whitelistedDomains) {
666
+ if (ramda.isEmpty(whitelistedDomains)) return true;
667
+ var domain = extractEmailDomain(email);
668
+ return ramda.includes(domain, whitelistedDomains);
669
+ };
670
+ var isEmailFromBlacklistedDomain = function isEmailFromBlacklistedDomain(email, blacklistedDomains) {
671
+ var domain = extractEmailDomain(email);
672
+ return ramda.includes(domain, blacklistedDomains);
673
+ };
674
+ var countWords = function countWords(value) {
675
+ return value ? value.trim().split(/\s+/).filter(Boolean).length : 0;
676
+ };
677
+ var validateTextField = function validateTextField(_ref) {
678
+ var kind = _ref.kind,
679
+ label = _ref.label,
680
+ isRequired = _ref.isRequired,
681
+ minWords = _ref.minWords,
682
+ remainingSlotsCount = _ref.remainingSlotsCount;
683
+ var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
684
+ if (isPhoneNumberField(kind)) {
685
+ schema = PhoneNumber.validation(getInvalidFieldError(t("neetoForm.common.phoneNumberValidation")));
686
+ }
687
+ var requiredError = kind === yup.QUESTION_KIND.SPOT.value ? t("neetoForm.questions.spot.numberOfSpotsRequired") : getRequiredFieldError(label);
688
+ if (isRequired) schema = schema.trim().required(requiredError);
689
+ if (kind === yup.QUESTION_KIND.SPOT.value) {
690
+ schema = schema.test("integer-spots", t("neetoForm.questions.spot.mustBeInteger"), function (value) {
691
+ return neetoCist.isNotPresent(value) || value === "" || Number.isInteger(Number(value));
692
+ }).test("min-spots", t("neetoForm.error.mustBeOrGreaterThanOrEqualTo", {
693
+ value: 1
694
+ }), function (value) {
695
+ return neetoCist.isNotPresent(value) || value === "" || Number(value) > 0;
696
+ });
697
+ if (typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0) {
698
+ schema = schema.test("max-spots", t("neetoForm.questions.spot.exceedsRemainingSpots", {
699
+ count: remainingSlotsCount
700
+ }), function (value) {
701
+ return neetoCist.isNotPresent(value) || value === "" || Number(value) > 0 && Number(value) <= remainingSlotsCount;
702
+ });
703
+ }
704
+ }
705
+ if (minWords) {
706
+ schema = schema.test("min-words", t("neetoForm.questions.textarea.minimumWordsError", {
707
+ count: minWords
708
+ }), function (value) {
709
+ return !value || countWords(value) >= minWords;
710
+ });
711
+ }
712
+ return schema.trim();
713
+ };
714
+ var validateEmailField = function validateEmailField(_ref2) {
715
+ var label = _ref2.label,
716
+ isRequired = _ref2.isRequired,
717
+ whitelistedDomains = _ref2.whitelistedDomains,
718
+ blacklistedDomains = _ref2.blacklistedDomains;
719
+ var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string")).email(getInvalidFieldError("Email")).test("verify domain", function (_ref3) {
720
+ var value = _ref3.value;
721
+ return t("neetoForm.error.emailFromRestrictedDomain", {
722
+ domain: extractEmailDomain(value)
723
+ });
724
+ }, function (value) {
725
+ return neetoCist.isNotPresent(value) || isEmailFromWhitelistedDomain(value, whitelistedDomains) && !isEmailFromBlacklistedDomain(value, blacklistedDomains);
726
+ });
727
+ if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
728
+ return schema.trim();
729
+ };
730
+ var validateNameField = function validateNameField(_ref4) {
731
+ var label = _ref4.label,
732
+ isRequired = _ref4.isRequired;
733
+ var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
734
+ if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
735
+ return schema.trim();
736
+ };
737
+ var validateSingleChoiceField = function validateSingleChoiceField(_ref5) {
738
+ var label = _ref5.label,
739
+ isRequired = _ref5.isRequired;
740
+ var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
741
+ if (isRequired) schema = schema.required(getSelectMinError());
742
+ return schema.trim();
743
+ };
744
+ var validateMultiChoiceField = function validateMultiChoiceField(_ref6) {
745
+ var isRequired = _ref6.isRequired;
746
+ var schema = yup__namespace.array().of(yup__namespace["boolean"]());
747
+ if (isRequired) schema = schema.compact().min(1, getSelectMinError());
748
+ return schema;
749
+ };
750
+ var validateRatingField = function validateRatingField(_ref7) {
751
+ var label = _ref7.label,
752
+ isRequired = _ref7.isRequired;
753
+ var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
754
+ if (isRequired) schema = schema.required(getSelectMinError());
755
+ return schema.trim();
756
+ };
757
+ var validateStarRatingField = function validateStarRatingField(_ref8) {
758
+ var label = _ref8.label,
759
+ isRequired = _ref8.isRequired;
760
+ var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
761
+ if (isRequired) {
762
+ schema = schema.required(getSelectMinError(t("neetoForm.common.rating")));
763
+ }
764
+ return schema.trim();
765
+ };
766
+ var validateOpinionScaleField = function validateOpinionScaleField(_ref9) {
767
+ var label = _ref9.label,
768
+ isRequired = _ref9.isRequired;
769
+ var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
770
+ if (isRequired) {
771
+ schema = schema.required(getSelectMinError(t("neetoForm.common.selection")));
772
+ }
773
+ return schema.trim();
774
+ };
775
+ var validateTermsField = function validateTermsField(_ref10) {
776
+ var _ref10$isRequired = _ref10.isRequired,
777
+ isRequired = _ref10$isRequired === void 0 ? true : _ref10$isRequired;
778
+ return isRequired ? yup__namespace["boolean"]().oneOf([true], t("neetoForm.common.mustAcceptTermsAndConditions")) : yup__namespace["boolean"]().notRequired();
779
+ };
780
+ var validateConditionField = function validateConditionField(_ref11) {
781
+ var _ref11$isRequired = _ref11.isRequired,
782
+ isRequired = _ref11$isRequired === void 0 ? true : _ref11$isRequired;
783
+ return isRequired ? yup__namespace["boolean"]().oneOf([true], t("neetoForm.common.mustAcceptCondition")) : yup__namespace["boolean"]().notRequired();
784
+ };
785
+ var validateDateField = function validateDateField(_ref12) {
786
+ var label = _ref12.label,
787
+ isRequired = _ref12.isRequired;
788
+ var schema = yup__namespace.string().test("is valid date", getInvalidTypeError(label, "date"), function (value) {
789
+ return neetoCist.isNotPresent(value) || isValidDate(value);
790
+ });
791
+ if (isRequired) {
792
+ schema = schema.required(getRequiredFieldError(label));
793
+ }
794
+ return schema;
795
+ };
796
+ var validateMultiEmailField = function validateMultiEmailField(_ref13) {
797
+ var isRequired = _ref13.isRequired;
798
+ var schema = yup__namespace.array().of(yup__namespace.object().shape({
799
+ value: yup__namespace.string().email(getInvalidFieldError("Email")).trim()
800
+ })).nullable();
801
+ if (isRequired) {
802
+ schema = schema.compact().min(1, getSelectMinError(t("neetoForm.common.email")));
803
+ }
804
+ return schema;
805
+ };
806
+ var validateAddressField = function validateAddressField(_ref14) {
807
+ var label = _ref14.label,
808
+ isRequired = _ref14.isRequired;
809
+ var schema = yup__namespace.string().typeError(getInvalidTypeError(label, "string"));
810
+ if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
811
+ return schema.trim();
812
+ };
813
+ var editorHasValue = function editorHasValue(content) {
814
+ return !utils$1.isEditorEmpty(content);
815
+ };
816
+ var validateRichTextField = function validateRichTextField(_ref15) {
817
+ var isRequired = _ref15.isRequired;
818
+ var schema = yup__namespace.string();
819
+ if (isRequired) {
820
+ schema = schema.test("required", getRequiredFieldError("content"), editorHasValue);
821
+ }
822
+ return schema.trim();
823
+ };
824
+ var validateFileUploadField = function validateFileUploadField(_ref16) {
825
+ var isRequired = _ref16.isRequired,
826
+ multipleFilesAllowed = _ref16.multipleFilesAllowed;
827
+ var files_schema = yup__namespace.array();
828
+ if (isRequired) {
829
+ files_schema = files_schema.of(yup__namespace.object().shape({
830
+ name: yup__namespace.string(),
831
+ signedId: yup__namespace.string().required(t("neetoForm.fileUpload.validations.waitForUpload")),
832
+ url: yup__namespace.string().required(t("neetoForm.fileUpload.validations.waitForUpload"))
833
+ })).unique("name", t("neetoForm.fileUpload.validations.removeDuplicates")).min(1, multipleFilesAllowed ? t("neetoForm.fileUpload.validations.atLeastOneFileRequired") : t("neetoForm.fileUpload.validations.fileIsRequired"));
834
+ }
835
+ return yup__namespace.object().shape({
836
+ files: files_schema
837
+ });
838
+ };
839
+ var validateCaptchaField = function validateCaptchaField(_ref17) {
840
+ var variant = _ref17.variant;
841
+ return variant === constants.CAPTCHA_TYPES.MATH_CAPTCHA ? yup__namespace.mixed().test("verification failed", t("neetoForm.error.captchaVerificationFailed"), function (value) {
842
+ return neetoCist.isNotPresent(value) || value;
843
+ }).transform(function (value) {
844
+ return value === "" ? null : value;
845
+ }).required(t("neetoForm.error.incompleteCaptcha")) : yup__namespace.string().trim().required(t("neetoForm.error.incompleteCaptcha"));
846
+ };
847
+ 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));
848
+ var validateFieldValue = function validateFieldValue(_ref18) {
849
+ var kind = _ref18.kind,
850
+ customValidator = _ref18.customValidator,
851
+ otherProps = _objectWithoutProperties(_ref18, _excluded$4);
852
+ return function (value) {
853
+ if (!(kind in fieldKindValidatorMap)) return;
854
+ var validator = fieldKindValidatorMap[kind];
855
+ var schema = customValidator || validator(_objectSpread$h({
856
+ kind: kind
857
+ }, otherProps));
858
+
859
+ // eslint-disable-next-line consistent-return, no-async-promise-executor
860
+ return new Promise(/*#__PURE__*/function () {
861
+ var _ref19 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve) {
862
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
863
+ while (1) switch (_context.prev = _context.next) {
864
+ case 0:
865
+ _context.prev = 0;
866
+ _context.next = 3;
867
+ return schema.validate(value);
868
+ case 3:
869
+ resolve(undefined);
870
+ _context.next = 9;
871
+ break;
872
+ case 6:
873
+ _context.prev = 6;
874
+ _context.t0 = _context["catch"](0);
875
+ resolve(_context.t0.message);
876
+ case 9:
877
+ case "end":
878
+ return _context.stop();
879
+ }
880
+ }, _callee, null, [[0, 6]]);
881
+ }));
882
+ return function (_x) {
883
+ return _ref19.apply(this, arguments);
884
+ };
885
+ }());
886
+ };
887
+ };
888
+ var validateVerificationCode = function validateVerificationCode(context) {
889
+ return function (value) {
890
+ var entity = t("neetoForm.emailVerification.verificationCode");
891
+ var schema = yup__namespace.string().trim().when("$isVerificationEnabled", {
892
+ is: true,
893
+ then: function then(schema) {
894
+ return schema.when("$isRequired", {
895
+ is: true,
896
+ then: function then(s) {
897
+ return s.required(getRequiredFieldError(entity));
898
+ }
899
+ }).when("$email", function (email, s) {
900
+ if (email !== null && email !== void 0 && email.trim()) {
901
+ return s.required(getRequiredFieldError(entity));
902
+ }
903
+ return s;
904
+ }).test("is-6-digit-number", t("neetoForm.error.mustBeASixDigitNumber", {
905
+ entity: entity
906
+ }), function (value) {
907
+ return neetoCist.isNotPresent(value) || yup.SIX_DIGIT_NUMBER_REGEX.test(value);
908
+ }).test("verify code", t("neetoForm.error.emailNotVerified"), function () {
909
+ var _this$options;
910
+ 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;
911
+ });
912
+ }
913
+ });
914
+
915
+ // eslint-disable-next-line no-async-promise-executor
916
+ return new Promise(/*#__PURE__*/function () {
917
+ var _ref20 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve) {
918
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
919
+ while (1) switch (_context2.prev = _context2.next) {
920
+ case 0:
921
+ _context2.prev = 0;
922
+ _context2.next = 3;
923
+ return schema.validate(value, {
924
+ context: context
925
+ });
926
+ case 3:
927
+ resolve(undefined);
928
+ _context2.next = 9;
929
+ break;
930
+ case 6:
931
+ _context2.prev = 6;
932
+ _context2.t0 = _context2["catch"](0);
933
+ resolve(_context2.t0.message);
934
+ case 9:
935
+ case "end":
936
+ return _context2.stop();
937
+ }
938
+ }, _callee2, null, [[0, 6]]);
939
+ }));
940
+ return function (_x2) {
941
+ return _ref20.apply(this, arguments);
942
+ };
943
+ }());
944
+ };
945
+ };
946
+
947
+ var MultipleEmailInput = function MultipleEmailInput(_ref) {
948
+ var question = _ref.question,
949
+ customValidator = _ref.customValidator;
950
+ var name = question.id,
951
+ kind = question.kind,
952
+ isRequired = question.isRequired,
953
+ nodeId = question.nodeId,
954
+ isReadOnly = question.isReadOnly;
955
+ var label = index.fieldWithFallback(question, "label");
956
+ var _useFormikContext = formik.useFormikContext(),
957
+ submitCount = _useFormikContext.submitCount;
958
+ var _useTranslation = reactI18next.useTranslation(),
959
+ t = _useTranslation.t;
960
+ var _useField = formik.useField({
961
+ name: name || nodeId,
962
+ validate: validateFieldValue({
963
+ kind: kind,
964
+ label: label,
965
+ isRequired: isRequired,
966
+ customValidator: customValidator
967
+ })
968
+ }),
969
+ _useField2 = _slicedToArray(_useField, 3),
970
+ field = _useField2[0],
971
+ meta = _useField2[1],
972
+ _useField2$ = _useField2[2],
973
+ setValue = _useField2$.setValue,
974
+ setTouched = _useField2$.setTouched;
975
+ var _useState = React.useState(neetoCist.isPresent(field.value)),
976
+ _useState2 = _slicedToArray(_useState, 2),
977
+ isInputVisible = _useState2[0],
978
+ setIsInputVisible = _useState2[1];
979
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
980
+ className: "neeto-form-engine-input__wrapper",
981
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
982
+ className: "neeto-ui-w-full",
983
+ children: isInputVisible ? /*#__PURE__*/jsxRuntime.jsx(NeetoUIMultiEmailInput, {
984
+ isRequired: isRequired,
985
+ label: label,
986
+ disabled: isReadOnly,
987
+ error: meta.touched ? meta.error : "",
988
+ helpText: t("neetoForm.common.addGuestsHelper"),
989
+ name: field.name,
990
+ placeholder: index.fieldWithFallback(question, "placeholder"),
991
+ value: field.value,
992
+ onBlur: function onBlur() {
993
+ return setTouched(true);
994
+ },
995
+ onChange: setValue
996
+ }) : /*#__PURE__*/jsxRuntime.jsxs("div", {
997
+ className: "flex flex-col gap-2 items-end",
998
+ children: [/*#__PURE__*/jsxRuntime.jsx(Button, _defineProperty(_defineProperty(_defineProperty({
999
+ label: label,
1000
+ "data-testid": "add-guest-button",
1001
+ disabled: isReadOnly,
1002
+ icon: Plus,
1003
+ iconPosition: "left"
1004
+ }, "label", t("neetoForm.common.addGuests")), "style", "link"), "onClick", function onClick() {
1005
+ return setIsInputVisible(true);
1006
+ })), (meta === null || meta === void 0 ? void 0 : meta.error) && submitCount > 0 && /*#__PURE__*/jsxRuntime.jsx("span", {
1007
+ className: "neeto-ui-text-error-500",
1008
+ children: meta.error
1009
+ })]
1010
+ })
1011
+ })
1012
+ });
1013
+ };
1014
+
1015
+ 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; }
1016
+ 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; }
1017
+ var AddressField = function AddressField(_ref) {
1018
+ var question = _ref.question,
1019
+ customValidator = _ref.customValidator;
1020
+ var name = question.id,
1021
+ kind = question.kind,
1022
+ isAddressRequired = question.isRequired,
1023
+ isReadOnly = question.isReadOnly,
1024
+ _question$fields = question.fields,
1025
+ fields = _question$fields === void 0 ? [] : _question$fields;
1026
+ var label = index.fieldWithFallback(question, "label");
1027
+ var transformedFields = fields.map(function (field) {
1028
+ return _objectSpread$g(_objectSpread$g({}, field), {}, {
1029
+ label: index.fieldWithFallback(field, "label")
1030
+ });
1031
+ });
1032
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
1033
+ className: "neeto-form-engine-address-wrapper",
1034
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
1035
+ className: "neeto-form-engine-input__label-wrapper",
1036
+ children: label && /*#__PURE__*/jsxRuntime.jsx("label", {
1037
+ className: "neeto-form-engine-label",
1038
+ "data-testid": "".concat(neetoCist.hyphenate(label), "-input-label"),
1039
+ children: label
1040
+ })
1041
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
1042
+ className: "neeto-form-engine-address pb-1",
1043
+ children: getVisibleOptions(transformedFields).map(function (_ref2) {
1044
+ var id = _ref2.id,
1045
+ label = _ref2.label,
1046
+ width = _ref2.width,
1047
+ fieldType = _ref2.fieldType,
1048
+ properties = _ref2.properties,
1049
+ isRequired = _ref2.isRequired;
1050
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
1051
+ "data-testid": "neeto-form-engine-address-fields",
1052
+ className: classnames("neeto-form-engine-address__field", {
1053
+ "neeto-form-engine-address__field--width-full": width === yup.ADDRESS_FIELD_WIDTHS.FULL,
1054
+ "neeto-form-engine-address__field--width-half": width === yup.ADDRESS_FIELD_WIDTHS.HALF,
1055
+ "neeto-form-engine-address__field--width-one-forth": width === yup.ADDRESS_FIELD_WIDTHS.ONE_FOURTH,
1056
+ "neeto-form-engine-address__field--width-three-forth": width === yup.ADDRESS_FIELD_WIDTHS.THREE_FOURTH
1057
+ }),
1058
+ children: /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
1059
+ name: "".concat(name, ".").concat(id),
1060
+ validate: isAddressRequired ? validateFieldValue({
1061
+ kind: kind,
1062
+ label: label,
1063
+ isRequired: isRequired,
1064
+ customValidator: customValidator
1065
+ }) : neetoCist.noop,
1066
+ children: function children(_ref3) {
1067
+ var _properties$options;
1068
+ var field = _ref3.field,
1069
+ meta = _ref3.meta,
1070
+ form = _ref3.form;
1071
+ return fieldType === yup.ADDRESS_FIELD_TYPES.SELECT ? /*#__PURE__*/jsxRuntime.jsx(Select, _objectSpread$g(_objectSpread$g({
1072
+ label: label,
1073
+ size: "large"
1074
+ }, field), {}, {
1075
+ error: meta.touched && meta.error,
1076
+ isDisabled: isReadOnly,
1077
+ menuPosition: "absolute",
1078
+ required: isRequired,
1079
+ value: neetoCist.toLabelAndValue(field.value),
1080
+ options: properties === null || properties === void 0 || (_properties$options = properties.options) === null || _properties$options === void 0 ? void 0 : _properties$options.map(function (_ref4) {
1081
+ var label = _ref4.label;
1082
+ return neetoCist.toLabelAndValue(label);
1083
+ }),
1084
+ onChange: function onChange(_ref5) {
1085
+ var value = _ref5.value;
1086
+ return !isReadOnly && form.setFieldValue("".concat(name, ".").concat(id), value);
1087
+ }
1088
+ })) : /*#__PURE__*/jsxRuntime.jsx(Input, _objectSpread$g(_objectSpread$g({}, _objectSpread$g(_objectSpread$g({}, field), {}, {
1089
+ label: label
1090
+ })), {}, {
1091
+ disabled: isReadOnly,
1092
+ error: meta.touched && meta.error,
1093
+ required: isRequired
1094
+ }));
1095
+ }
1096
+ })
1097
+ }, id);
1098
+ })
1099
+ })]
1100
+ });
1101
+ };
1102
+
1103
+ var CaptchaField = function CaptchaField(_ref) {
1104
+ var question = _ref.question,
1105
+ preview = _ref.preview,
1106
+ customValidator = _ref.customValidator,
1107
+ captchaRef = _ref.captchaRef;
1108
+ var name = question.id,
1109
+ kind = question.kind,
1110
+ isRequired = question.isRequired,
1111
+ variant = question.variant,
1112
+ nodeId = question.nodeId;
1113
+ var label = index.fieldWithFallback(question, "label");
1114
+ var _useField = formik.useField({
1115
+ name: name || nodeId,
1116
+ validate: validateFieldValue({
1117
+ kind: kind,
1118
+ label: label,
1119
+ isRequired: isRequired,
1120
+ customValidator: customValidator,
1121
+ variant: variant
1122
+ })
1123
+ }),
1124
+ _useField2 = _slicedToArray(_useField, 3);
1125
+ _useField2[0];
1126
+ var _useField2$ = _useField2[1],
1127
+ touched = _useField2$.touched,
1128
+ error = _useField2$.error,
1129
+ _useField2$2 = _useField2[2],
1130
+ setValue = _useField2$2.setValue,
1131
+ setTouched = _useField2$2.setTouched;
1132
+ var handleVerifyCaptcha = function handleVerifyCaptcha(response) {
1133
+ setTouched(true);
1134
+ setValue(response);
1135
+ };
1136
+ var Component = CAPTCHA_COMPONENT_MAP[variant];
1137
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
1138
+ className: "neeto-form-engine-input__wrapper",
1139
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
1140
+ className: "neeto-form-engine-input__label-wrapper",
1141
+ children: label && /*#__PURE__*/jsxRuntime.jsx("label", {
1142
+ className: "neeto-form-engine-label",
1143
+ children: getLabel(label, isRequired)
1144
+ })
1145
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
1146
+ className: classnames({
1147
+ "pointer-events-none": preview
1148
+ }),
1149
+ children: /*#__PURE__*/jsxRuntime.jsx(Component, {
1150
+ captchaRef: captchaRef,
1151
+ handleVerifyCaptcha: handleVerifyCaptcha,
1152
+ handleBlur: function handleBlur() {
1153
+ return setTouched(true);
1154
+ }
1155
+ })
1156
+ }), touched && error && /*#__PURE__*/jsxRuntime.jsx("p", {
1157
+ className: "neeto-form-engine-input__error",
1158
+ "data-testid": "neeto-form-engine-captcha-error",
1159
+ children: error
1160
+ })]
1161
+ });
1162
+ };
1163
+
1164
+ var MATH_OPERATORS = {
1165
+ PLUS: "+",
1166
+ MINUS: "-"
1167
+ };
1168
+
1169
+ var generateRandomOperation = function generateRandomOperation() {
1170
+ var firstNumber = neetoCist.getRandomInt(1, 50);
1171
+ var secondNumber = neetoCist.getRandomInt(1, 50);
1172
+ var operator = neetoCist.randomPick.apply(void 0, _toConsumableArray(ramda.values(MATH_OPERATORS)));
1173
+ return {
1174
+ firstNumber: firstNumber,
1175
+ secondNumber: secondNumber,
1176
+ operator: operator
1177
+ };
1178
+ };
1179
+
1180
+ var MathCaptcha = function MathCaptcha(_ref) {
1181
+ var captchaRef = _ref.captchaRef,
1182
+ handleVerifyCaptcha = _ref.handleVerifyCaptcha,
1183
+ handleBlur = _ref.handleBlur;
1184
+ var _useState = React.useState(generateRandomOperation()),
1185
+ _useState2 = _slicedToArray(_useState, 2),
1186
+ operation = _useState2[0],
1187
+ setOperation = _useState2[1];
1188
+ var _useState3 = React.useState(""),
1189
+ _useState4 = _slicedToArray(_useState3, 2),
1190
+ userInput = _useState4[0],
1191
+ setUserInput = _useState4[1];
1192
+ var firstNumber = operation.firstNumber,
1193
+ secondNumber = operation.secondNumber,
1194
+ operator = operation.operator;
1195
+ var resetCaptcha = function resetCaptcha() {
1196
+ setOperation(generateRandomOperation());
1197
+ setUserInput("");
1198
+ };
1199
+ React.useImperativeHandle(captchaRef, function () {
1200
+ return {
1201
+ reset: resetCaptcha
1202
+ };
1203
+ });
1204
+ var calculateResult = function calculateResult() {
1205
+ switch (operator) {
1206
+ case MATH_OPERATORS.PLUS:
1207
+ return firstNumber + secondNumber;
1208
+ case MATH_OPERATORS.MINUS:
1209
+ return firstNumber - secondNumber;
1210
+ default:
1211
+ return null;
1212
+ }
1213
+ };
1214
+ var verifyCaptcha = function verifyCaptcha() {
1215
+ var result = calculateResult();
1216
+ if (result === null) return;
1217
+ handleVerifyCaptcha(result === Number(userInput));
1218
+ };
1219
+ reactUtils.useUpdateEffect(function () {
1220
+ verifyCaptcha();
1221
+ }, [userInput]);
1222
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
1223
+ className: "neeto-form-nano-math-captcha",
1224
+ "data-testid": "math-captcha",
1225
+ ref: captchaRef,
1226
+ children: [/*#__PURE__*/jsxRuntime.jsx("button", {
1227
+ className: "neeto-form-nano-math-captcha__button",
1228
+ type: "button",
1229
+ onClick: resetCaptcha,
1230
+ children: /*#__PURE__*/jsxRuntime.jsx(Refresh, {})
1231
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
1232
+ className: "neeto-form-nano-math-captcha__equation",
1233
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
1234
+ "data-testid": "first-number",
1235
+ children: firstNumber
1236
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
1237
+ "data-testid": "operator",
1238
+ children: operator
1239
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
1240
+ "data-testid": "second-number",
1241
+ children: secondNumber
1242
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
1243
+ children: "="
1244
+ })]
1245
+ }), /*#__PURE__*/jsxRuntime.jsx(Input, {
1246
+ required: true,
1247
+ className: "neeto-form-nano-math-captcha__input",
1248
+ "data-testid": "math-captcha-input",
1249
+ value: userInput,
1250
+ onBlur: handleBlur,
1251
+ onChange: utils.withEventTargetValue(setUserInput)
1252
+ })]
1253
+ });
1254
+ };
1255
+
1256
+ var Recaptcha = function Recaptcha(_ref) {
1257
+ var captchaRef = _ref.captchaRef,
1258
+ handleVerifyCaptcha = _ref.handleVerifyCaptcha;
1259
+ var verifyRecaptcha = function verifyRecaptcha(response) {
1260
+ if (response === null) {
1261
+ return;
1262
+ }
1263
+ handleVerifyCaptcha(response);
1264
+ };
1265
+ var expiredRecaptcha = function expiredRecaptcha() {
1266
+ var _captchaRef$current;
1267
+ captchaRef === null || captchaRef === void 0 || (_captchaRef$current = captchaRef.current) === null || _captchaRef$current === void 0 || _captchaRef$current.reset();
1268
+ handleVerifyCaptcha("");
1269
+ };
1270
+ return /*#__PURE__*/jsxRuntime.jsx(ReCAPTCHA, {
1271
+ hl: clientI18nInstance.language,
1272
+ ref: captchaRef,
1273
+ sitekey: initializers.globalProps.formNanoRecaptchaV2SiteKey,
1274
+ onChange: verifyRecaptcha,
1275
+ onErrored: neetoCist.noop,
1276
+ onExpired: expiredRecaptcha
1277
+ }, clientI18nInstance.language);
1278
+ };
1279
+
1280
+ 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; }
1281
+ 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; }
1282
+ var ConditionField = function ConditionField(_ref) {
1283
+ var question = _ref.question,
1284
+ customValidator = _ref.customValidator;
1285
+ var name = question.id,
1286
+ kind = question.kind,
1287
+ isRequired = question.isRequired,
1288
+ nodeId = question.nodeId;
1289
+ var label = index.fieldWithFallback(question, "label");
1290
+ return /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
1291
+ name: name || nodeId,
1292
+ validate: validateFieldValue({
1293
+ kind: kind,
1294
+ label: label,
1295
+ isRequired: isRequired,
1296
+ customValidator: customValidator
1297
+ }),
1298
+ children: function children(_ref2) {
1299
+ var meta = _ref2.meta,
1300
+ field = _ref2.field;
1301
+ return /*#__PURE__*/jsxRuntime.jsx(Checkbox, _objectSpread$f(_objectSpread$f({}, _objectSpread$f(_objectSpread$f({}, field), {}, {
1302
+ label: label,
1303
+ name: name
1304
+ })), {}, {
1305
+ checked: field.value,
1306
+ error: meta.touched ? meta.error : "",
1307
+ required: isRequired
1308
+ }));
1309
+ }
1310
+ });
1311
+ };
1312
+
1313
+ var _excluded$3 = ["value"];
1314
+ 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; }
1315
+ 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; }
1316
+ var DateField = function DateField(_ref) {
1317
+ var question = _ref.question,
1318
+ customValidator = _ref.customValidator;
1319
+ var name = question.id,
1320
+ kind = question.kind,
1321
+ isRequired = question.isRequired,
1322
+ nodeId = question.nodeId,
1323
+ isReadOnly = question.isReadOnly;
1324
+ var label = index.fieldWithFallback(question, "label");
1325
+ var _QUESTION_KIND$kind$t = yup.QUESTION_KIND[kind.toUpperCase()].type,
1326
+ type = _QUESTION_KIND$kind$t === void 0 ? "date" : _QUESTION_KIND$kind$t;
1327
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
1328
+ className: "neeto-form-engine-input__wrapper",
1329
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
1330
+ className: "neeto-form-engine-input__label-wrapper",
1331
+ children: label && /*#__PURE__*/jsxRuntime.jsx("label", {
1332
+ className: "neeto-form-engine-label",
1333
+ "data-testid": "".concat(neetoCist.hyphenate(label), "-input-label"),
1334
+ children: getLabel(label, isRequired)
1335
+ })
1336
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
1337
+ className: "neeto-form-engine-date-picker",
1338
+ children: /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
1339
+ name: name || nodeId,
1340
+ validate: validateFieldValue({
1341
+ kind: kind,
1342
+ label: label,
1343
+ isRequired: isRequired,
1344
+ customValidator: customValidator
1345
+ }),
1346
+ children: function children(_ref2) {
1347
+ var meta = _ref2.meta,
1348
+ _ref2$field = _ref2.field,
1349
+ value = _ref2$field.value,
1350
+ field = _objectWithoutProperties(_ref2$field, _excluded$3),
1351
+ form = _ref2.form;
1352
+ return /*#__PURE__*/jsxRuntime.jsx(DatePicker, _objectSpread$e(_objectSpread$e({}, _objectSpread$e(_objectSpread$e({}, field), {}, {
1353
+ type: type
1354
+ })), {}, {
1355
+ "data-testid": "".concat(neetoCist.hyphenate(label), "-input-field"),
1356
+ dateFormat: "MMM D, YYYY",
1357
+ disabled: isReadOnly,
1358
+ error: meta.touched ? meta.error : "",
1359
+ placeholder: index.fieldWithFallback(question, "placeholder"),
1360
+ popupClassName: "neeto-form-engine-date-picker-popup",
1361
+ required: isRequired,
1362
+ size: "small",
1363
+ value: getValidDate(value),
1364
+ onCalendarChange: function onCalendarChange(date) {
1365
+ if (date) {
1366
+ form.setFieldValue(name, date.toISOString());
1367
+ }
1368
+ },
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(constants.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(constants.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$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; }
1407
+ 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; }
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$d(_objectSpread$d({
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$d(_objectSpread$d({
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(Button, {
1462
+ "data-testid": "send-code-button",
1463
+ disabled: isDisabled,
1464
+ size: "small",
1465
+ style: "secondary",
1466
+ onClick: handleClick,
1467
+ children: isSendingVerificationCode ? /*#__PURE__*/jsxRuntime.jsx(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(Button, {
1506
+ "data-testid": "otp-resend-button",
1507
+ disabled: isResendDisabled,
1508
+ size: "small",
1509
+ style: "link",
1510
+ onClick: handleResendClick
1511
+ })
1512
+ }
1513
+ })
1514
+ });
1515
+ };
1516
+
1517
+ 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; }
1518
+ 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; }
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(Input, _objectSpread$c(_objectSpread$c({}, _objectSpread$c({}, 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.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(NeetoUICallout, {
1603
+ style: calloutDetails.style,
1604
+ children: calloutDetails.message
1605
+ })]
1606
+ });
1607
+ };
1608
+
1609
+ 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; }
1610
+ 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; }
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 = index.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
+ 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.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(Input, _objectSpread$b(_objectSpread$b({}, _objectSpread$b(_objectSpread$b({
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: index.fieldWithFallback(question, "placeholder"),
1741
+ required: isRequired,
1742
+ onBlur: function onBlur() {
1743
+ return setTouched(true);
1744
+ },
1745
+ onBlurCapture: utils.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 = index.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(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$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; }
1826
+ 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; }
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 = index.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(Input, _objectSpread$a(_objectSpread$a({}, _objectSpread$a(_objectSpread$a({
1858
+ type: type
1859
+ }, field), {}, {
1860
+ autoComplete: autoComplete,
1861
+ label: label,
1862
+ name: name
1863
+ })), {}, {
1864
+ disabled: isReadOnly,
1865
+ error: touched ? error : "",
1866
+ placeholder: index.fieldWithFallback(question, placeholderField),
1867
+ required: isRequired,
1868
+ onBlur: function onBlur() {
1869
+ return setTouched(true);
1870
+ },
1871
+ onChange: utils.withEventTargetValue(setValue)
1872
+ }));
1873
+ };
1874
+
1875
+ 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; }
1876
+ 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; }
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$9(_objectSpread$9({}, props), {}, {
1885
+ labelField: yup.LABEL_FIELDS.FIRST_NAME,
1886
+ name: "".concat(id, ".firstName"),
1887
+ placeholderField: "firstNamePlaceholder"
1888
+ })), /*#__PURE__*/jsxRuntime.jsx(Field, _objectSpread$9(_objectSpread$9({}, 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$9(_objectSpread$9({}, 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 = index.fieldWithFallback(question, "label");
1913
+ var leftOpinionLabel = index.fieldWithFallback(question, "leftOpinionLabel");
1914
+ var rightOpinionLabel = index.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 neeto-ui-bg-gray-100",
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
+ var Choices = function Choices(_ref) {
2059
+ var label = _ref.label,
2060
+ options = _ref.options,
2061
+ type = _ref.type,
2062
+ name = _ref.name,
2063
+ value = _ref.value,
2064
+ onChange = _ref.onChange,
2065
+ onValueChange = _ref.onValueChange,
2066
+ error = _ref.error,
2067
+ disabled = _ref.isDisabled,
2068
+ _ref$isPictureChoice = _ref.isPictureChoice,
2069
+ isPictureChoice = _ref$isPictureChoice === void 0 ? yup.DEFAULT_CHOICE_QUESTION_ATTRIBUTES.isPictureChoice : _ref$isPictureChoice,
2070
+ _ref$imageHeight = _ref.imageHeight,
2071
+ imageHeight = _ref$imageHeight === void 0 ? yup.DEFAULT_CHOICE_QUESTION_ATTRIBUTES.imageHeight : _ref$imageHeight,
2072
+ _ref$shouldFitImages = _ref.shouldFitImages,
2073
+ shouldFitImages = _ref$shouldFitImages === void 0 ? yup.DEFAULT_CHOICE_QUESTION_ATTRIBUTES.shouldFitImages : _ref$shouldFitImages;
2074
+ var isCheckBox = type === "checkbox";
2075
+ var ChoiceWrapper = isCheckBox ? "div" : Radio;
2076
+ var Component = isCheckBox ? Checkbox : Radio.Item;
2077
+ var handleChoiceValueChange = function handleChoiceValueChange(updatedValue) {
2078
+ if (typeof onValueChange === "function") {
2079
+ onValueChange(updatedValue);
2080
+ return;
2081
+ }
2082
+ onChange({
2083
+ target: {
2084
+ name: name,
2085
+ value: updatedValue
2086
+ }
2087
+ });
2088
+ };
2089
+ var shouldDeselectOption = function shouldDeselectOption(optionId) {
2090
+ return !isCheckBox && !disabled && value === optionId;
2091
+ };
2092
+ var handleChoiceClick = function handleChoiceClick(event, optionId) {
2093
+ if (!shouldDeselectOption(optionId)) return;
2094
+ event.preventDefault();
2095
+ handleChoiceValueChange("");
2096
+ };
2097
+ var handleChoiceKeyDown = function handleChoiceKeyDown(event, optionId) {
2098
+ if (!shouldDeselectOption(optionId)) return;
2099
+ if (!yup.RADIO_DESELECT_KEYS.includes(event.key)) return;
2100
+ event.preventDefault();
2101
+ handleChoiceValueChange("");
2102
+ };
2103
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
2104
+ className: "neeto-form-engine-choices__wrapper",
2105
+ "data-testid": "".concat(neetoCist.hyphenate(label), "-select-container-wrapper"),
2106
+ children: [/*#__PURE__*/jsxRuntime.jsx("label", {
2107
+ className: "neeto-form-engine-label",
2108
+ "data-testid": "".concat(neetoCist.hyphenate(label), "-input-label"),
2109
+ children: label
2110
+ }), /*#__PURE__*/jsxRuntime.jsx(ChoiceWrapper, {
2111
+ stacked: !isCheckBox,
2112
+ className: classnames("neeto-form-engine-choices", {
2113
+ "neeto-form-engine-choices--picture": isPictureChoice
2114
+ }),
2115
+ children: options.map(function (option, index) {
2116
+ var _value$index, _option$image;
2117
+ 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;
2118
+ return /*#__PURE__*/jsxRuntime.jsxs("label", {
2119
+ htmlFor: option.id,
2120
+ className: classnames("neeto-form-engine-choice", {
2121
+ "neeto-form-engine-choice--picture": isPictureChoice,
2122
+ "neeto-form-engine-choice--selected": isChecked,
2123
+ "cursor-not-allowed": disabled
2124
+ }),
2125
+ onClick: function onClick(event) {
2126
+ return handleChoiceClick(event, option.id);
2127
+ },
2128
+ children: [isPictureChoice && /*#__PURE__*/jsxRuntime.jsx(ChoiceImage, {
2129
+ shouldFitImages: shouldFitImages,
2130
+ alt: option.label,
2131
+ height: imageHeight,
2132
+ src: (_option$image = option.image) === null || _option$image === void 0 ? void 0 : _option$image.url
2133
+ }), /*#__PURE__*/jsxRuntime.jsx(Component, {
2134
+ disabled: disabled,
2135
+ onChange: onChange,
2136
+ type: type,
2137
+ checked: isChecked,
2138
+ className: classnames({
2139
+ "cursor-not-allowed": disabled
2140
+ }),
2141
+ id: option.id,
2142
+ label: option.label,
2143
+ name: isCheckBox ? "".concat(name, ".").concat(index) : name,
2144
+ value: option.id,
2145
+ labelProps: {
2146
+ className: classnames({
2147
+ "cursor-not-allowed": disabled
2148
+ })
2149
+ },
2150
+ onKeyDown: function onKeyDown(event) {
2151
+ return handleChoiceKeyDown(event, option.id);
2152
+ }
2153
+ })]
2154
+ }, option.id);
2155
+ })
2156
+ }), !!error && typeof error === "string" && /*#__PURE__*/jsxRuntime.jsx("p", {
2157
+ className: "neeto-form-engine-input__error",
2158
+ "data-testid": "neeto-form-engine-".concat(type, "-error"),
2159
+ children: error
2160
+ })]
2161
+ });
2162
+ };
2163
+ var Choices$1 = /*#__PURE__*/React.memo(Choices);
2164
+
2165
+ 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; }
2166
+ 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; }
2167
+ var OptionsField = function OptionsField(_ref) {
2168
+ var question = _ref.question,
2169
+ customValidator = _ref.customValidator,
2170
+ isLastFewElements = _ref.isLastFewElements;
2171
+ var _useFormikContext = formik.useFormikContext(),
2172
+ setFieldTouched = _useFormikContext.setFieldTouched,
2173
+ setFieldValue = _useFormikContext.setFieldValue,
2174
+ validateField = _useFormikContext.validateField;
2175
+ var name = question.id,
2176
+ kind = question.kind,
2177
+ isRequired = question.isRequired,
2178
+ isReadOnly = question.isReadOnly,
2179
+ isPictureChoiceFromQuestion = question.isPictureChoice,
2180
+ imageHeight = question.imageHeight,
2181
+ shouldFitImages = question.shouldFitImages,
2182
+ _question$optionsAttr = question.optionsAttributes,
2183
+ options = _question$optionsAttr === void 0 ? [] : _question$optionsAttr;
2184
+ var isPictureChoice = isPictureChoiceFromQuestion;
2185
+ var isDropdown = kind === yup.QUESTION_KIND.DROPDOWN.value;
2186
+ var label = index.fieldWithFallback(question, "label");
2187
+ var Component = isDropdown ? Select : Choices$1;
2188
+ var transformedOptions = isDropdown ? options.map(function (option) {
2189
+ return {
2190
+ label: index.fieldWithFallback(option, "label"),
2191
+ position: option.position,
2192
+ value: option.id
2193
+ };
2194
+ }) : options.map(function (option) {
2195
+ return _objectSpread$8(_objectSpread$8({}, option), {}, {
2196
+ label: index.fieldWithFallback(option, "label")
2197
+ });
2198
+ });
2199
+ var handleSelect = function handleSelect(option) {
2200
+ setFieldValue(name, option === null || option === void 0 ? void 0 : option.value, false);
2201
+ setFieldTouched(name, true, false);
2202
+ setTimeout(function () {
2203
+ return validateField(name);
2204
+ });
2205
+ };
2206
+ var handleValueChange = function handleValueChange(updatedValue) {
2207
+ setFieldValue(name, updatedValue, false);
2208
+ setFieldTouched(name, true, false);
2209
+ setTimeout(function () {
2210
+ return validateField(name);
2211
+ });
2212
+ };
2213
+ var customFilter = function customFilter(option, inputValue) {
2214
+ if (!option) return false;
2215
+ return containsIgnoreCase(option.label, inputValue);
2216
+ };
2217
+ return /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
2218
+ name: name,
2219
+ validate: validateFieldValue({
2220
+ kind: kind,
2221
+ label: label,
2222
+ isRequired: isRequired,
2223
+ customValidator: customValidator
2224
+ }),
2225
+ children: function children(_ref2) {
2226
+ var meta = _ref2.meta,
2227
+ field = _ref2.field;
2228
+ var onChange = field.onChange,
2229
+ value = field.value;
2230
+ return /*#__PURE__*/jsxRuntime.jsx(Component, _objectSpread$8(_objectSpread$8({
2231
+ error: getError(meta),
2232
+ isDisabled: isReadOnly,
2233
+ label: getLabel(label, isRequired),
2234
+ options: transformedOptions,
2235
+ strategy: "fixed",
2236
+ type: kind
2237
+ }, _objectSpread$8(_objectSpread$8({
2238
+ isRequired: isRequired,
2239
+ name: name
2240
+ }, isDropdown && {
2241
+ filterOption: customFilter
2242
+ }), !isDropdown && {
2243
+ imageHeight: imageHeight,
2244
+ isPictureChoice: isPictureChoice,
2245
+ shouldFitImages: shouldFitImages
2246
+ })), {}, {
2247
+ value: isDropdown ? neetoCist.findBy({
2248
+ value: value
2249
+ }, transformedOptions) || null : value,
2250
+ onChange: isDropdown ? handleSelect : onChange,
2251
+ onValueChange: !isDropdown ? handleValueChange : undefined
2252
+ }, isDropdown && {
2253
+ isClearable: true,
2254
+ menuPlacement: isLastFewElements ? "top" : "auto",
2255
+ menuPortalTarget: document.body,
2256
+ menuPosition: "fixed"
2257
+ }));
2258
+ }
2259
+ });
2260
+ };
2261
+
2262
+ var PhoneNumberField = function PhoneNumberField(_ref) {
2263
+ var _getPhoneData;
2264
+ var question = _ref.question,
2265
+ autoComplete = _ref.autoComplete,
2266
+ isLastFewElements = _ref.isLastFewElements;
2267
+ var name = question.id,
2268
+ kind = question.kind,
2269
+ isRequired = question.isRequired,
2270
+ nodeId = question.nodeId,
2271
+ isReadOnly = question.isReadOnly;
2272
+ var label = index.fieldWithFallback(question, "label");
2273
+ var _useField = formik.useField({
2274
+ name: name || nodeId,
2275
+ validate: validateFieldValue({
2276
+ kind: kind,
2277
+ label: label,
2278
+ isRequired: isRequired
2279
+ })
2280
+ }),
2281
+ _useField2 = _slicedToArray(_useField, 3),
2282
+ value = _useField2[0].value,
2283
+ _useField2$ = _useField2[1],
2284
+ touched = _useField2$.touched,
2285
+ error = _useField2$.error,
2286
+ _useField2$2 = _useField2[2],
2287
+ setValue = _useField2$2.setValue,
2288
+ setTouched = _useField2$2.setTouched;
2289
+ return /*#__PURE__*/jsxRuntime.jsx(PhoneNumber.PhoneNumberInput, {
2290
+ autoComplete: autoComplete,
2291
+ label: label,
2292
+ value: value,
2293
+ className: "neeto-form-engine-input__wrapper items-stretch",
2294
+ disabled: isReadOnly,
2295
+ error: touched ? error : "",
2296
+ initialCountryCode: (_getPhoneData = getPhoneData(value)) === null || _getPhoneData === void 0 ? void 0 : _getPhoneData.country,
2297
+ placeholder: index.fieldWithFallback(question, "placeholder"),
2298
+ required: isRequired,
2299
+ selectProps: {
2300
+ isDisabled: isReadOnly,
2301
+ menuPlacement: isLastFewElements ? "top" : "auto",
2302
+ menuPortalTarget: document.body,
2303
+ menuPosition: "fixed"
2304
+ },
2305
+ onBlur: function onBlur() {
2306
+ return setTouched(true);
2307
+ },
2308
+ onChange: setValue
2309
+ });
2310
+ };
2311
+
2312
+ var _excluded$2 = ["name", "label", "error", "lowestRatingLabel", "averageRatingLabel", "highestRatingLabel", "value", "disabled"];
2313
+ 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; }
2314
+ 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; }
2315
+ var Rating = function Rating(_ref) {
2316
+ var name = _ref.name,
2317
+ label = _ref.label,
2318
+ error = _ref.error,
2319
+ lowestRatingLabel = _ref.lowestRatingLabel,
2320
+ averageRatingLabel = _ref.averageRatingLabel,
2321
+ highestRatingLabel = _ref.highestRatingLabel,
2322
+ value = _ref.value,
2323
+ disabled = _ref.disabled,
2324
+ other = _objectWithoutProperties(_ref, _excluded$2);
2325
+ var handleClick = function handleClick(e) {
2326
+ return e.currentTarget.nextElementSibling.click();
2327
+ };
2328
+ var render = function render() {
2329
+ var labels = [highestRatingLabel, averageRatingLabel, lowestRatingLabel];
2330
+ return yup.RATING_OPTIONS.map(function (_ref2, index) {
2331
+ var Icon = _ref2.icon,
2332
+ modifier = _ref2.modifier,
2333
+ rating = _ref2.value;
2334
+ return /*#__PURE__*/jsxRuntime.jsxs(React.Fragment, {
2335
+ children: [/*#__PURE__*/jsxRuntime.jsxs("button", {
2336
+ disabled: disabled,
2337
+ type: "button",
2338
+ className: classnames("neeto-form-engine-rating__item neeto-form-engine-rating__item--".concat(modifier), {
2339
+ active: rating === value
2340
+ }),
2341
+ onClick: handleClick,
2342
+ children: [/*#__PURE__*/jsxRuntime.jsx(Icon, {}), /*#__PURE__*/jsxRuntime.jsx("label", {
2343
+ className: "neeto-form-engine-label",
2344
+ children: labels[index]
2345
+ })]
2346
+ }), /*#__PURE__*/jsxRuntime.jsx("input", _objectSpread$7({
2347
+ name: name,
2348
+ hidden: true,
2349
+ checked: rating === value,
2350
+ type: "radio",
2351
+ value: rating
2352
+ }, other))]
2353
+ }, rating);
2354
+ });
2355
+ };
2356
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
2357
+ className: "neeto-form-engine-rating",
2358
+ children: [/*#__PURE__*/jsxRuntime.jsx("label", {
2359
+ className: "neeto-form-engine-label",
2360
+ "data-testid": "rating-input-label",
2361
+ children: label
2362
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
2363
+ className: "neeto-form-engine-rating__row",
2364
+ "data-testid": "rating-input-field",
2365
+ children: render()
2366
+ }), !!error && typeof error === "string" && /*#__PURE__*/jsxRuntime.jsx("p", {
2367
+ className: "neeto-form-engine-input__error",
2368
+ "data-testid": "neeto-form-engine-rating-error",
2369
+ children: error
2370
+ })]
2371
+ });
2372
+ };
2373
+ var Rating$1 = /*#__PURE__*/React.memo(Rating);
2374
+
2375
+ 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; }
2376
+ 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; }
2377
+ var RatingField = function RatingField(_ref) {
2378
+ var question = _ref.question,
2379
+ customValidator = _ref.customValidator;
2380
+ var name = question.id,
2381
+ kind = question.kind,
2382
+ isRequired = question.isRequired,
2383
+ isReadOnly = question.isReadOnly;
2384
+ var label = index.fieldWithFallback(question, "label");
2385
+ return /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
2386
+ name: name,
2387
+ validate: validateFieldValue({
2388
+ kind: kind,
2389
+ label: label,
2390
+ isRequired: isRequired,
2391
+ customValidator: customValidator
2392
+ }),
2393
+ children: function children(_ref2) {
2394
+ var meta = _ref2.meta,
2395
+ field = _ref2.field;
2396
+ return /*#__PURE__*/jsxRuntime.jsx(Rating$1, _objectSpread$6(_objectSpread$6({}, field), {}, {
2397
+ disabled: isReadOnly,
2398
+ error: meta.touched ? meta.error : "",
2399
+ label: getLabel(label, isRequired),
2400
+ averageRatingLabel: index.fieldWithFallback(question, "averageRatingLabel") || yup.RATING_VALUES.AVERAGE.label,
2401
+ highestRatingLabel: index.fieldWithFallback(question, "highestRatingLabel") || yup.RATING_VALUES.GOOD.label,
2402
+ lowestRatingLabel: index.fieldWithFallback(question, "lowestRatingLabel") || yup.RATING_VALUES.BAD.label
2403
+ }));
2404
+ }
2405
+ });
2406
+ };
2407
+
2408
+ 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; }
2409
+ 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; }
2410
+ var RichTextEditor = function RichTextEditor(_ref) {
2411
+ var editorRef = _ref.editorRef,
2412
+ question = _ref.question,
2413
+ _ref$editorProps = _ref.editorProps,
2414
+ editorProps = _ref$editorProps === void 0 ? {} : _ref$editorProps;
2415
+ var _useFormikContext = formik.useFormikContext(),
2416
+ errors = _useFormikContext.errors,
2417
+ touched = _useFormikContext.touched;
2418
+ var name = question.id,
2419
+ kind = question.kind,
2420
+ isRequired = question.isRequired,
2421
+ nodeId = question.nodeId,
2422
+ isReadOnly = question.isReadOnly;
2423
+ var label = index.fieldWithFallback(question, "label");
2424
+ var debouncedPlaceholder = reactUtils.useDebounce(index.fieldWithFallback(question, "placeholder"), 300);
2425
+ React.useEffect(function () {
2426
+ var _editorRef$current, _editorRef$current$se;
2427
+ 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);
2428
+ }, [editorRef === null || editorRef === void 0 ? void 0 : editorRef.current, isReadOnly]);
2429
+ var propsToCompare = ["debouncedPlaceholder", "error", "touched", "isReadOnly"];
2430
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
2431
+ className: "neeto-form-engine-input__wrapper",
2432
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
2433
+ className: "neeto-form-engine-input__label-wrapper",
2434
+ children: label && /*#__PURE__*/jsxRuntime.jsx("label", {
2435
+ className: "neeto-form-engine-label",
2436
+ "data-testid": "".concat(neetoCist.hyphenate(label), "-input-label"),
2437
+ children: getLabel(label, isRequired)
2438
+ })
2439
+ }), /*#__PURE__*/jsxRuntime.jsx(formik.FastField, {
2440
+ debouncedPlaceholder: debouncedPlaceholder,
2441
+ isReadOnly: isReadOnly,
2442
+ error: errors[name],
2443
+ name: name || nodeId,
2444
+ shouldUpdate: isPropsUnequal(propsToCompare),
2445
+ touched: touched[name],
2446
+ validate: validateFieldValue({
2447
+ kind: kind,
2448
+ label: label,
2449
+ isRequired: isRequired
2450
+ }),
2451
+ children: function children(_ref2) {
2452
+ var field = _ref2.field,
2453
+ form = _ref2.form,
2454
+ meta = _ref2.meta;
2455
+ return /*#__PURE__*/jsxRuntime.jsx(NeetoEditor, _objectSpread$5({
2456
+ editable: isReadOnly,
2457
+ error: meta.touched ? meta.error : "",
2458
+ initialValue: field.value,
2459
+ menuType: isReadOnly ? "bubble" : "fixed",
2460
+ placeholder: debouncedPlaceholder,
2461
+ ref: editorRef,
2462
+ addons: isReadOnly ? [] : ["attachments", "block-quote", "code-block", "image-upload"],
2463
+ className: classnames("neeto-form-engine-rich-text-input", {
2464
+ "cursor-not-allowed border": isReadOnly
2465
+ }),
2466
+ onBlur: function onBlur() {
2467
+ return form.setFieldTouched(name, true);
2468
+ },
2469
+ onChange: function onChange(value) {
2470
+ return form.setFieldValue(name, value);
2471
+ }
2472
+ }, editorProps), debouncedPlaceholder);
2473
+ }
2474
+ })]
2475
+ });
2476
+ };
2477
+
2478
+ var _excluded$1 = ["value", "iconType", "label", "rating"];
2479
+ 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; }
2480
+ 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; }
2481
+ var RatingButton = function RatingButton(_ref) {
2482
+ var _ref$value = _ref.value,
2483
+ value = _ref$value === void 0 ? 0 : _ref$value,
2484
+ iconType = _ref.iconType,
2485
+ label = _ref.label,
2486
+ rating = _ref.rating,
2487
+ otherProps = _objectWithoutProperties(_ref, _excluded$1);
2488
+ var handleClick = function handleClick(e) {
2489
+ return e.currentTarget.nextElementSibling.click();
2490
+ };
2491
+ var Icon = yup.ICONS_MAP[iconType];
2492
+ var selectedRating = getSelectedRating(value);
2493
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2494
+ children: [/*#__PURE__*/jsxRuntime.jsxs("button", {
2495
+ className: classnames({
2496
+ active: rating === value
2497
+ }),
2498
+ disabled: otherProps === null || otherProps === void 0 ? void 0 : otherProps.disabled,
2499
+ type: "button",
2500
+ onClick: handleClick,
2501
+ children: [/*#__PURE__*/jsxRuntime.jsx(Icon, {
2502
+ size: 24,
2503
+ className: classnames("neeto-form-engine-star-rating__icon", {
2504
+ "neeto-form-engine-star-rating__icon--active": rating <= selectedRating
2505
+ })
2506
+ }), /*#__PURE__*/jsxRuntime.jsx("label", {
2507
+ className: "neeto-form-engine-label",
2508
+ children: label
2509
+ })]
2510
+ }), /*#__PURE__*/jsxRuntime.jsx("input", _objectSpread$4({
2511
+ hidden: true,
2512
+ checked: ramda.equals(rating, value),
2513
+ type: "radio",
2514
+ value: rating
2515
+ }, otherProps))]
2516
+ });
2517
+ };
2518
+ var RatingButton$1 = /*#__PURE__*/React.memo(RatingButton);
2519
+
2520
+ var _excluded = ["label", "minValue", "maxValue", "error"];
2521
+ 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; }
2522
+ 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; }
2523
+ var StarRating = function StarRating(_ref) {
2524
+ var label = _ref.label,
2525
+ minValue = _ref.minValue,
2526
+ maxValue = _ref.maxValue,
2527
+ error = _ref.error,
2528
+ props = _objectWithoutProperties(_ref, _excluded);
2529
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
2530
+ className: "neeto-form-engine-input__wrapper neeto-form-engine-star-rating",
2531
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
2532
+ className: "neeto-form-engine-input__label-wrapper",
2533
+ children: /*#__PURE__*/jsxRuntime.jsx("label", {
2534
+ className: "neeto-form-engine-label",
2535
+ "data-testid": "star-rating-input-label",
2536
+ children: label
2537
+ })
2538
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
2539
+ className: "neeto-form-engine-star-rating__row",
2540
+ "data-testid": "star-rating-input-field",
2541
+ children: yup.generateArray(minValue, maxValue).map(function (index) {
2542
+ return /*#__PURE__*/jsxRuntime.jsx(RatingButton$1, _objectSpread$3({
2543
+ label: index,
2544
+ rating: index
2545
+ }, props), index);
2546
+ })
2547
+ }), !!error && typeof error === "string" && /*#__PURE__*/jsxRuntime.jsx("p", {
2548
+ className: "neeto-form-engine-input__error",
2549
+ "data-testid": "neeto-form-engine-star-rating-error",
2550
+ children: error
2551
+ })]
2552
+ });
2553
+ };
2554
+ var StarRating$1 = /*#__PURE__*/React.memo(StarRating);
2555
+
2556
+ 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; }
2557
+ 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; }
2558
+ var StarRatingField = function StarRatingField(_ref) {
2559
+ var question = _ref.question,
2560
+ customValidator = _ref.customValidator;
2561
+ var name = question.id,
2562
+ kind = question.kind,
2563
+ isRequired = question.isRequired,
2564
+ minValue = question.minValue,
2565
+ maxValue = question.maxValue,
2566
+ iconType = question.iconType,
2567
+ isReadOnly = question.isReadOnly;
2568
+ var label = index.fieldWithFallback(question, "label");
2569
+ return /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
2570
+ name: name,
2571
+ validate: validateFieldValue({
2572
+ kind: kind,
2573
+ label: label,
2574
+ isRequired: isRequired,
2575
+ customValidator: customValidator
2576
+ }),
2577
+ children: function children(_ref2) {
2578
+ var meta = _ref2.meta,
2579
+ field = _ref2.field;
2580
+ return /*#__PURE__*/jsxRuntime.jsx(StarRating$1, _objectSpread$2({
2581
+ iconType: iconType,
2582
+ maxValue: maxValue,
2583
+ minValue: minValue,
2584
+ name: name,
2585
+ disabled: isReadOnly,
2586
+ error: meta.touched ? meta.error : "",
2587
+ label: getLabel(label, isRequired)
2588
+ }, field));
2589
+ }
2590
+ });
2591
+ };
2592
+
2593
+ 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; }
2594
+ 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; }
2595
+ var TermsField = function TermsField(_ref) {
2596
+ var question = _ref.question,
2597
+ customValidator = _ref.customValidator;
2598
+ var name = question.id,
2599
+ kind = question.kind,
2600
+ isRequired = question.isRequired,
2601
+ nodeId = question.nodeId;
2602
+ var label = index.fieldWithFallback(question, "label", true);
2603
+ return /*#__PURE__*/jsxRuntime.jsx(formik.Field, {
2604
+ name: name || nodeId,
2605
+ validate: validateFieldValue({
2606
+ kind: kind,
2607
+ label: label,
2608
+ isRequired: isRequired,
2609
+ customValidator: customValidator
2610
+ }),
2611
+ children: function children(_ref2) {
2612
+ var meta = _ref2.meta,
2613
+ field = _ref2.field;
2614
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
2615
+ className: "neeto-form-engine-terms",
2616
+ children: /*#__PURE__*/jsxRuntime.jsx(Checkbox, _objectSpread$1(_objectSpread$1({}, _objectSpread$1(_objectSpread$1({}, field), {}, {
2617
+ name: name
2618
+ })), {}, {
2619
+ checked: field.value,
2620
+ error: meta.touched ? meta.error : "",
2621
+ children: /*#__PURE__*/jsxRuntime.jsx(EditorContent, {
2622
+ content: label
2623
+ })
2624
+ }))
2625
+ });
2626
+ }
2627
+ });
2628
+ };
2629
+
2630
+ 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; }
2631
+ 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; }
2632
+ var TextField = function TextField(_ref) {
2633
+ var _otherProps$onChange;
2634
+ var question = _ref.question,
2635
+ customValidator = _ref.customValidator,
2636
+ autoComplete = _ref.autoComplete,
2637
+ remainingSlotsCount = _ref.remainingSlotsCount;
2638
+ var _useTranslation = reactI18next.useTranslation(),
2639
+ t = _useTranslation.t;
2640
+ var name = question.id,
2641
+ kind = question.kind,
2642
+ isRequired = question.isRequired,
2643
+ isReadOnly = question.isReadOnly,
2644
+ nodeId = question.nodeId,
2645
+ minWords = question.minWords;
2646
+ var label = index.fieldWithFallback(question, "label");
2647
+ var _QUESTION_KIND$kind$t = yup.QUESTION_KIND[kind.toUpperCase()],
2648
+ _QUESTION_KIND$kind$t2 = _QUESTION_KIND$kind$t.type,
2649
+ type = _QUESTION_KIND$kind$t2 === void 0 ? "text" : _QUESTION_KIND$kind$t2,
2650
+ onKeyDown = _QUESTION_KIND$kind$t.onKeyDown,
2651
+ otherProps = _QUESTION_KIND$kind$t.otherProps;
2652
+ var Component = kind === yup.QUESTION_KIND.TEXTAREA.value ? Textarea : Input;
2653
+ var _useField = formik.useField({
2654
+ name: name || nodeId,
2655
+ validate: validateFieldValue({
2656
+ kind: kind,
2657
+ label: label,
2658
+ isRequired: isRequired,
2659
+ minWords: minWords,
2660
+ customValidator: customValidator,
2661
+ remainingSlotsCount: remainingSlotsCount
2662
+ })
2663
+ }),
2664
+ _useField2 = _slicedToArray(_useField, 3),
2665
+ field = _useField2[0],
2666
+ _useField2$ = _useField2[1],
2667
+ touched = _useField2$.touched,
2668
+ error = _useField2$.error,
2669
+ _useField2$2 = _useField2[2],
2670
+ setValue = _useField2$2.setValue,
2671
+ setTouched = _useField2$2.setTouched;
2672
+ var handleFieldChange = utils.withEventTargetValue(setValue);
2673
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
2674
+ className: "w-full flex flex-col gap-2",
2675
+ children: [/*#__PURE__*/jsxRuntime.jsx(Component, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({
2676
+ type: type
2677
+ }, field), {}, {
2678
+ autoComplete: autoComplete,
2679
+ label: label,
2680
+ onKeyDown: onKeyDown
2681
+ }, kind === yup.QUESTION_KIND.SPOT.value && _objectSpread({
2682
+ min: 1
2683
+ }, typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0 && {
2684
+ max: remainingSlotsCount
2685
+ }))), {}, {
2686
+ disabled: isReadOnly,
2687
+ error: touched ? error : "",
2688
+ name: neetoCist.slugify(label),
2689
+ placeholder: index.fieldWithFallback(question, "placeholder"),
2690
+ required: isRequired,
2691
+ onBlur: function onBlur() {
2692
+ return setTouched(true);
2693
+ },
2694
+ onChange: (_otherProps$onChange = otherProps === null || otherProps === void 0 ? void 0 : otherProps.onChange(handleFieldChange)) !== null && _otherProps$onChange !== void 0 ? _otherProps$onChange : handleFieldChange
2695
+ })), kind === yup.QUESTION_KIND.SPOT.value && typeof remainingSlotsCount === "number" && remainingSlotsCount >= 0 && /*#__PURE__*/jsxRuntime.jsx("div", {
2696
+ className: "flex justify-end",
2697
+ children: /*#__PURE__*/jsxRuntime.jsx(Tag, {
2698
+ icon: Info,
2699
+ style: "info",
2700
+ label: t("neetoForm.questions.spot.remainingSlotsCount", {
2701
+ count: remainingSlotsCount
2702
+ })
2703
+ })
2704
+ })]
2705
+ });
2706
+ };
2707
+
2708
+ var _QUESTION_TO_COMPONEN;
2709
+ 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) {
2710
+ var question = _ref.question;
2711
+ return /*#__PURE__*/jsxRuntime.jsx(EditorContent, {
2712
+ content: index.fieldWithFallback(question, "label", true)
2713
+ });
2714
+ }), 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));
2715
+ var CAPTCHA_COMPONENT_MAP = _defineProperty(_defineProperty({}, constants.CAPTCHA_TYPES.RECAPTCHA_V2, Recaptcha), constants.CAPTCHA_TYPES.MATH_CAPTCHA, MathCaptcha);
2716
+
2717
+ var getFieldComponent = function getFieldComponent(_ref) {
2718
+ var kind = _ref.kind;
2719
+ if (kind in QUESTION_TO_COMPONENT_MAP) return QUESTION_TO_COMPONENT_MAP[kind];
2720
+ return function () {
2721
+ return null;
2722
+ };
2723
+ };
2724
+ var isPropsUnequal = function isPropsUnequal(props) {
2725
+ return function (nextProps, prevProps) {
2726
+ return neetoCist.notEqualsDeep(ramda.pick(props, nextProps), ramda.pick(props, prevProps));
2727
+ };
2728
+ };
2729
+ var getValidDate = function getValidDate(date) {
2730
+ if (!date) return "";
2731
+ return utils.dayjs(date).isValid() ? utils.dayjs(date) : "";
2732
+ };
2733
+ var getPhoneData = function getPhoneData(value, countryCode) {
2734
+ try {
2735
+ return libphonenumberJs.parsePhoneNumber(value, countryCode);
2736
+ } catch (_unused) {
2737
+ return undefined;
2738
+ }
2739
+ };
2740
+ var containsIgnoreCase = function containsIgnoreCase(string, substring) {
2741
+ return string.toLowerCase().includes(substring.toLowerCase());
2742
+ };
2743
+ var getVisibleOptions = function getVisibleOptions(options) {
2744
+ return Array.isArray(options) ? options.filter(function (option) {
2745
+ return !option.deleted;
2746
+ }).sort(function (a, b) {
2747
+ return a.position - b.position;
2748
+ }) : [];
2749
+ };
2750
+
2751
+ exports.FormikWrap = FormikWrap;
2752
+ exports.buildAutoCompleteAttribute = buildAutoCompleteAttribute;
2753
+ exports.clearEmailVerificationDetails = clearEmailVerificationDetails;
2754
+ exports.clearLocalStorageValues = clearLocalStorageValues;
2755
+ exports.clientI18nInstance = clientI18nInstance;
2756
+ exports.generateFormResponse = generateFormResponse;
2757
+ exports.generateInitValues = generateInitValues;
2758
+ exports.getFieldComponent = getFieldComponent;
2759
+ exports.getWithExpiry = getWithExpiry;
2760
+ exports.mergeRefs = mergeRefs;
2761
+ exports.renderButtonsInOrder = renderButtonsInOrder;
2762
+ //# sourceMappingURL=utils-QSMxxdQN.js.map