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