@bigbinary/neeto-form-frontend 3.3.2 → 3.4.1
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/app/javascript/src/translations/en.json +4 -4
- package/dist/BuildForm.js +2378 -0
- package/dist/BuildForm.js.map +1 -0
- package/dist/ExternalForm.js +658 -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 +2700 -0
- package/dist/Submission.js.map +1 -0
- package/dist/UrlBuilder.js +297 -0
- package/dist/UrlBuilder.js.map +1 -0
- package/dist/buildForm-4a5a5251.js +35 -0
- package/dist/buildForm-4a5a5251.js.map +1 -0
- package/dist/buildForm-77b32f08.js +42 -0
- package/dist/buildForm-77b32f08.js.map +1 -0
- package/dist/cjs/BuildForm.js +2437 -0
- package/dist/cjs/BuildForm.js.map +1 -0
- package/dist/cjs/ExternalForm.js +699 -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 +2711 -0
- package/dist/cjs/Submission.js.map +1 -0
- package/dist/cjs/UrlBuilder.js +309 -0
- package/dist/cjs/UrlBuilder.js.map +1 -0
- package/dist/cjs/hooks.js +34 -0
- package/dist/cjs/hooks.js.map +1 -0
- package/dist/cjs/index.js +116 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/constants-25c02c05.js +486 -0
- package/dist/constants-25c02c05.js.map +1 -0
- package/dist/constants-8afd221a.js +455 -0
- package/dist/constants-8afd221a.js.map +1 -0
- package/dist/constants-9310a7c2.js +342 -0
- package/dist/constants-9310a7c2.js.map +1 -0
- package/dist/constants-f0f38e6f.js +378 -0
- package/dist/constants-f0f38e6f.js.map +1 -0
- package/dist/hooks.js +20 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index-2664c3e7.js +39 -0
- package/dist/index-2664c3e7.js.map +1 -0
- package/dist/index-b6bb805c.js +46 -0
- package/dist/index-b6bb805c.js.map +1 -0
- package/dist/index.js +95 -9325
- package/dist/index.js.map +1 -1
- package/dist/main.css +12 -1
- package/dist/main.css.map +1 -1
- package/dist/useFormApi-ca36173e.js +492 -0
- package/dist/useFormApi-ca36173e.js.map +1 -0
- package/dist/useFormApi-d733cb8d.js +467 -0
- package/dist/useFormApi-d733cb8d.js.map +1 -0
- package/dist/useFormSubmission-866195bb.js +24 -0
- package/dist/useFormSubmission-866195bb.js.map +1 -0
- package/dist/useFormSubmission-f8866b84.js +22 -0
- package/dist/useFormSubmission-f8866b84.js.map +1 -0
- package/dist/utils-1ab9e83f.js +2158 -0
- package/dist/utils-1ab9e83f.js.map +1 -0
- package/dist/utils-38cc949e.js +2222 -0
- package/dist/utils-38cc949e.js.map +1 -0
- package/package.json +19 -7
- package/dist/index.cjs.js +0 -9424
- package/dist/index.cjs.js.map +0 -1
|
@@ -0,0 +1,2158 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useEffect, useState, useImperativeHandle, useRef, useCallback, createElement, memo, Fragment } from 'react';
|
|
3
|
+
import { useFormikContext, useField, Field, FastField } from 'formik';
|
|
4
|
+
import { isPresent, isNotPresent, isNotEmpty, findBy, findById, getRandomInt, randomPick, noop, hyphenate, slugify, notEqualsDeep } from '@bigbinary/neeto-cist';
|
|
5
|
+
import { i as isFunction, b as isEmptyValues, f as fieldWithFallback } from './index-2664c3e7.js';
|
|
6
|
+
import dayjs from 'dayjs';
|
|
7
|
+
import { parsePhoneNumber } from 'libphonenumber-js';
|
|
8
|
+
import { pipe, toLower, reject, prop, map, includes, isNil, clamp, identity, pluck, values, assoc, isEmpty, isNotNil, equals, pick } from 'ramda';
|
|
9
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
10
|
+
import EditorContent from '@bigbinary/neeto-editor/EditorContent';
|
|
11
|
+
import { C as CAPTCHA_TYPES, o as generateArray } from './constants-8afd221a.js';
|
|
12
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
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 * as yup from 'yup';
|
|
22
|
+
import i18next from 'i18next';
|
|
23
|
+
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
24
|
+
import { Q as QUESTION_KIND, E as ERROR_CODES, e as EMAIL_REGEX, R as RATING_VALUES, S as SCHEMA_LESS_QUESTION_KINDS, f as RATING_OPTIONS, I as ICONS_MAP } from './constants-9310a7c2.js';
|
|
25
|
+
import classnames from 'classnames';
|
|
26
|
+
import path from 'path';
|
|
27
|
+
import { useUpdateEffect, withT, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
28
|
+
import { withEventTargetValue } from '@bigbinary/neeto-commons-frontend/utils';
|
|
29
|
+
import Refresh from '@bigbinary/neeto-icons/Refresh';
|
|
30
|
+
import Input from '@bigbinary/neetoui/Input';
|
|
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 localeData from 'dayjs/plugin/localeData';
|
|
36
|
+
import utc from 'dayjs/plugin/utc';
|
|
37
|
+
import weekday from 'dayjs/plugin/weekday';
|
|
38
|
+
import weekOfYear from 'dayjs/plugin/weekOfYear';
|
|
39
|
+
import DatePicker from '@bigbinary/neetoui/DatePicker';
|
|
40
|
+
import Label from '@bigbinary/neetoui/Label';
|
|
41
|
+
import Typography from '@bigbinary/neetoui/Typography';
|
|
42
|
+
import { DirectUpload } from '@rails/activestorage';
|
|
43
|
+
import { useDropzone } from 'react-dropzone';
|
|
44
|
+
import { D as DIRECT_UPLOAD_URL } from './useFormApi-d733cb8d.js';
|
|
45
|
+
import FileGeneric from '@bigbinary/neeto-icons/FileGeneric';
|
|
46
|
+
import Check from '@bigbinary/neeto-icons/Check';
|
|
47
|
+
import Close from '@bigbinary/neeto-icons/Close';
|
|
48
|
+
import { motion } from 'framer-motion';
|
|
49
|
+
import Select from '@bigbinary/neetoui/Select';
|
|
50
|
+
import Radio from '@bigbinary/neetoui/Radio';
|
|
51
|
+
import NeetoEditor from '@bigbinary/neeto-editor/Editor';
|
|
52
|
+
import Textarea from '@bigbinary/neetoui/Textarea';
|
|
53
|
+
|
|
54
|
+
var clientI18nInstance = i18next.cloneInstance();
|
|
55
|
+
|
|
56
|
+
var clearLocalStorageValues = function clearLocalStorageValues(key) {
|
|
57
|
+
try {
|
|
58
|
+
localStorage.removeItem(key);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
// eslint-disable-next-line no-console
|
|
61
|
+
console.error(error);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var setWithExpiry = function setWithExpiry(key, value) {
|
|
65
|
+
var expireInDays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
66
|
+
var expiryDate = dayjs().add(expireInDays, "day").toDate();
|
|
67
|
+
var item = {
|
|
68
|
+
value: value,
|
|
69
|
+
localStorageExpiry: expiryDate.getTime()
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
localStorage.setItem(key, JSON.stringify(item));
|
|
73
|
+
} catch (error) {
|
|
74
|
+
// eslint-disable-next-line no-console
|
|
75
|
+
console.error(error);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var getWithExpiry = function getWithExpiry(key) {
|
|
79
|
+
try {
|
|
80
|
+
var itemStr = localStorage.getItem(key);
|
|
81
|
+
if (!itemStr) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
var item = JSON.parse(itemStr);
|
|
85
|
+
var now = new Date();
|
|
86
|
+
if (now.getTime() > item.localStorageExpiry) {
|
|
87
|
+
localStorage.removeItem(key);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return item.value;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
// eslint-disable-next-line no-console
|
|
93
|
+
console.error(error);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
var FormikWrap = function FormikWrap(_ref) {
|
|
99
|
+
var onError = _ref.onError,
|
|
100
|
+
children = _ref.children,
|
|
101
|
+
formId = _ref.formId,
|
|
102
|
+
preserveValues = _ref.preserveValues,
|
|
103
|
+
onValuesChange = _ref.onValuesChange,
|
|
104
|
+
dataUpdateCount = _ref.dataUpdateCount;
|
|
105
|
+
var _useFormikContext = useFormikContext(),
|
|
106
|
+
errors = _useFormikContext.errors,
|
|
107
|
+
touched = _useFormikContext.touched,
|
|
108
|
+
isValid = _useFormikContext.isValid,
|
|
109
|
+
isSubmitting = _useFormikContext.isSubmitting,
|
|
110
|
+
values = _useFormikContext.values,
|
|
111
|
+
validateForm = _useFormikContext.validateForm;
|
|
112
|
+
var revalidate = function revalidate() {
|
|
113
|
+
return isPresent(errors) && validateForm();
|
|
114
|
+
};
|
|
115
|
+
useEffect(function () {
|
|
116
|
+
revalidate();
|
|
117
|
+
}, [clientI18nInstance.language, dataUpdateCount]);
|
|
118
|
+
var syncValuesWithLocalStorage = function syncValuesWithLocalStorage() {
|
|
119
|
+
return preserveValues && !isEmptyValues(values) && setWithExpiry("".concat(formId, "/values"), values);
|
|
120
|
+
};
|
|
121
|
+
useEffect(function () {
|
|
122
|
+
syncValuesWithLocalStorage();
|
|
123
|
+
onValuesChange && onValuesChange(values);
|
|
124
|
+
}, [values, formId, preserveValues]);
|
|
125
|
+
useEffect(function () {
|
|
126
|
+
if (isSubmitting || isValid) return;
|
|
127
|
+
|
|
128
|
+
// include only touched fields
|
|
129
|
+
var touchedErrors = Object.keys(errors).filter(function (key) {
|
|
130
|
+
return touched[key];
|
|
131
|
+
}).reduce(function (obj, key) {
|
|
132
|
+
obj[key] = errors[key];
|
|
133
|
+
return obj;
|
|
134
|
+
}, {});
|
|
135
|
+
if (isFunction(onError)) onError(touchedErrors);
|
|
136
|
+
}, [isValid, isSubmitting]);
|
|
137
|
+
return children;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
var t$2 = clientI18nInstance.t;
|
|
141
|
+
var getInvalidFieldError = function getInvalidFieldError(label) {
|
|
142
|
+
return t$2("neetoForm.error.invalidField", {
|
|
143
|
+
label: label
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
var getRequiredFieldError = function getRequiredFieldError(label) {
|
|
147
|
+
return t$2("neetoForm.error.requiredField", {
|
|
148
|
+
label: label
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
var getSelectMinError = function getSelectMinError(min) {
|
|
152
|
+
var entity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : t$2("neetoForm.common.option");
|
|
153
|
+
return t$2("neetoForm.error.selectMin", {
|
|
154
|
+
min: min,
|
|
155
|
+
entity: entity
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
var getInvalidTypeError = function getInvalidTypeError(label, type) {
|
|
159
|
+
return t$2("neetoForm.error.invalidType", {
|
|
160
|
+
label: label,
|
|
161
|
+
type: type
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
var _excluded$4 = ["kind", "customValidator"];
|
|
166
|
+
var _fieldKindValidatorMa;
|
|
167
|
+
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; }
|
|
168
|
+
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), !0).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; }
|
|
169
|
+
var t$1 = clientI18nInstance.t;
|
|
170
|
+
yup.addMethod(yup.array, "unique", function () {
|
|
171
|
+
var field, message;
|
|
172
|
+
if (arguments.length > 1) {
|
|
173
|
+
field = arguments[0];
|
|
174
|
+
message = arguments[1];
|
|
175
|
+
} else {
|
|
176
|
+
message = arguments[0];
|
|
177
|
+
}
|
|
178
|
+
var getValue = function getValue(item) {
|
|
179
|
+
return field ? item[field] : item;
|
|
180
|
+
};
|
|
181
|
+
var valueInLowerCase = pipe(getValue, toLower);
|
|
182
|
+
return this.test("unique", message, function () {
|
|
183
|
+
var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
184
|
+
// ignore destroyed items in the array
|
|
185
|
+
var validItems = reject(prop("_destroy"), array);
|
|
186
|
+
var uniqueItems = new Set(map(valueInLowerCase, validItems));
|
|
187
|
+
|
|
188
|
+
// all items are unique
|
|
189
|
+
if (validItems.length === uniqueItems.size) return true;
|
|
190
|
+
return this.createError({
|
|
191
|
+
path: this.path,
|
|
192
|
+
message: message
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
var isValidDate = function isValidDate(date) {
|
|
197
|
+
return date && dayjs(date).isValid();
|
|
198
|
+
};
|
|
199
|
+
var extractEmailDomain = function extractEmailDomain(email) {
|
|
200
|
+
return email === null || email === void 0 ? void 0 : email.split("@")[1];
|
|
201
|
+
};
|
|
202
|
+
var isEmailFromRestrictedDomain = function isEmailFromRestrictedDomain(email, restrictedDomains) {
|
|
203
|
+
var domain = extractEmailDomain(email);
|
|
204
|
+
return includes(domain, restrictedDomains);
|
|
205
|
+
};
|
|
206
|
+
var validateTextField = function validateTextField(_ref) {
|
|
207
|
+
var kind = _ref.kind,
|
|
208
|
+
label = _ref.label,
|
|
209
|
+
isRequired = _ref.isRequired;
|
|
210
|
+
var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
|
|
211
|
+
if (kind === QUESTION_KIND.PHONE.value) {
|
|
212
|
+
schema = validation(getInvalidFieldError(t$1("neetoForm.common.phoneNumberValidation")));
|
|
213
|
+
}
|
|
214
|
+
if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
|
|
215
|
+
return schema.trim();
|
|
216
|
+
};
|
|
217
|
+
var validateEmailField = function validateEmailField(_ref2) {
|
|
218
|
+
var label = _ref2.label,
|
|
219
|
+
isRequired = _ref2.isRequired,
|
|
220
|
+
restrictedDomains = _ref2.restrictedDomains;
|
|
221
|
+
var schema = yup.string().typeError(getInvalidTypeError(label, "string")).email(getInvalidFieldError("Email")).test("verify domain", function (_ref3) {
|
|
222
|
+
var value = _ref3.value;
|
|
223
|
+
return t$1("neetoForm.error.emailFromRestrictedDomain", {
|
|
224
|
+
domain: extractEmailDomain(value)
|
|
225
|
+
});
|
|
226
|
+
}, function (value) {
|
|
227
|
+
return isNotPresent(value) || !isEmailFromRestrictedDomain(value, restrictedDomains);
|
|
228
|
+
});
|
|
229
|
+
if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
|
|
230
|
+
return schema.trim();
|
|
231
|
+
};
|
|
232
|
+
var validateNameField = function validateNameField(_ref4) {
|
|
233
|
+
var label = _ref4.label,
|
|
234
|
+
isRequired = _ref4.isRequired;
|
|
235
|
+
var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
|
|
236
|
+
if (isRequired) schema = schema.trim().required(getRequiredFieldError(label));
|
|
237
|
+
return schema.trim();
|
|
238
|
+
};
|
|
239
|
+
var validateSingleChoiceField = function validateSingleChoiceField(_ref5) {
|
|
240
|
+
var label = _ref5.label,
|
|
241
|
+
isRequired = _ref5.isRequired;
|
|
242
|
+
var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
|
|
243
|
+
if (isRequired) schema = schema.required(getSelectMinError("an"));
|
|
244
|
+
return schema.trim();
|
|
245
|
+
};
|
|
246
|
+
var validateMultiChoiceField = function validateMultiChoiceField(_ref6) {
|
|
247
|
+
var isRequired = _ref6.isRequired;
|
|
248
|
+
var schema = yup.array().of(yup["boolean"]());
|
|
249
|
+
if (isRequired) schema = schema.compact().min(1, getSelectMinError("an"));
|
|
250
|
+
return schema;
|
|
251
|
+
};
|
|
252
|
+
var validateRatingField = function validateRatingField(_ref7) {
|
|
253
|
+
var label = _ref7.label,
|
|
254
|
+
isRequired = _ref7.isRequired;
|
|
255
|
+
var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
|
|
256
|
+
if (isRequired) schema = schema.required(getSelectMinError("an"));
|
|
257
|
+
return schema.trim();
|
|
258
|
+
};
|
|
259
|
+
var validateStarRatingField = function validateStarRatingField(_ref8) {
|
|
260
|
+
var label = _ref8.label,
|
|
261
|
+
isRequired = _ref8.isRequired;
|
|
262
|
+
var schema = yup.string().typeError(getInvalidTypeError(label, "string"));
|
|
263
|
+
if (isRequired) {
|
|
264
|
+
schema = schema.required(getSelectMinError("a", t$1("neetoForm.common.rating")));
|
|
265
|
+
}
|
|
266
|
+
return schema.trim();
|
|
267
|
+
};
|
|
268
|
+
var validateTermsField = function validateTermsField(_ref9) {
|
|
269
|
+
var _ref9$isRequired = _ref9.isRequired,
|
|
270
|
+
isRequired = _ref9$isRequired === void 0 ? true : _ref9$isRequired;
|
|
271
|
+
return isRequired ? yup["boolean"]().oneOf([true], t$1("neetoForm.common.mustAcceptTermsAndConditions")) : yup["boolean"]().notRequired();
|
|
272
|
+
};
|
|
273
|
+
var validateConditionField = function validateConditionField(_ref10) {
|
|
274
|
+
var _ref10$isRequired = _ref10.isRequired,
|
|
275
|
+
isRequired = _ref10$isRequired === void 0 ? true : _ref10$isRequired;
|
|
276
|
+
return isRequired ? yup["boolean"]().oneOf([true], t$1("neetoForm.common.mustAcceptCondition")) : yup["boolean"]().notRequired();
|
|
277
|
+
};
|
|
278
|
+
var validateDateField = function validateDateField(_ref11) {
|
|
279
|
+
var label = _ref11.label,
|
|
280
|
+
isRequired = _ref11.isRequired;
|
|
281
|
+
var schema = yup.string().test("is valid date", getInvalidTypeError(label, "date"), function (value) {
|
|
282
|
+
return isNotPresent(value) || isValidDate(value);
|
|
283
|
+
});
|
|
284
|
+
if (isRequired) {
|
|
285
|
+
schema = schema.required(getRequiredFieldError(label));
|
|
286
|
+
}
|
|
287
|
+
return schema;
|
|
288
|
+
};
|
|
289
|
+
var validateMultiEmailField = function validateMultiEmailField(_ref12) {
|
|
290
|
+
var isRequired = _ref12.isRequired;
|
|
291
|
+
var schema = yup.array().of(yup.object().shape({
|
|
292
|
+
value: yup.string().email(getInvalidFieldError("Email")).trim()
|
|
293
|
+
})).nullable();
|
|
294
|
+
if (isRequired) {
|
|
295
|
+
schema = schema.compact().min(1, getSelectMinError("an", t$1("neetoForm.common.email")));
|
|
296
|
+
}
|
|
297
|
+
return schema;
|
|
298
|
+
};
|
|
299
|
+
var editorHasValue = function editorHasValue(content) {
|
|
300
|
+
return !isEditorEmpty(content);
|
|
301
|
+
};
|
|
302
|
+
var validateRichTextField = function validateRichTextField(_ref13) {
|
|
303
|
+
var isRequired = _ref13.isRequired;
|
|
304
|
+
var schema = yup.string();
|
|
305
|
+
if (isRequired) {
|
|
306
|
+
schema = schema.test("required", getRequiredFieldError("content"), editorHasValue);
|
|
307
|
+
}
|
|
308
|
+
return schema.trim();
|
|
309
|
+
};
|
|
310
|
+
var validateFileUploadField = function validateFileUploadField(_ref14) {
|
|
311
|
+
var isRequired = _ref14.isRequired,
|
|
312
|
+
multipleFilesAllowed = _ref14.multipleFilesAllowed;
|
|
313
|
+
var files_schema = yup.array();
|
|
314
|
+
if (isRequired) {
|
|
315
|
+
files_schema = files_schema.of(yup.object().shape({
|
|
316
|
+
name: yup.string(),
|
|
317
|
+
signedId: yup.string().required(t$1("neetoForm.fileUpload.validations.waitForUpload")),
|
|
318
|
+
url: yup.string().required(t$1("neetoForm.fileUpload.validations.waitForUpload"))
|
|
319
|
+
})).unique("name", t$1("neetoForm.fileUpload.validations.removeDuplicates")).min(1, multipleFilesAllowed ? t$1("neetoForm.fileUpload.validations.atLeastOneFileRequired") : t$1("neetoForm.fileUpload.validations.fileIsRequired"));
|
|
320
|
+
}
|
|
321
|
+
return yup.object().shape({
|
|
322
|
+
files: files_schema
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
var validateCaptchaField = function validateCaptchaField(_ref15) {
|
|
326
|
+
var variant = _ref15.variant;
|
|
327
|
+
return variant === CAPTCHA_TYPES.MATH_CAPTCHA ? yup.mixed().test("verification failed", t$1("neetoForm.error.captchaVerificationFailed"), function (value) {
|
|
328
|
+
return isNotPresent(value) || value;
|
|
329
|
+
}).transform(function (value) {
|
|
330
|
+
return value === "" ? null : value;
|
|
331
|
+
}).required(t$1("neetoForm.error.incompleteCaptcha")) : yup.string().trim().required(t$1("neetoForm.error.incompleteCaptcha"));
|
|
332
|
+
};
|
|
333
|
+
var fieldKindValidatorMap = (_fieldKindValidatorMa = {}, _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.EMAIL.value, validateEmailField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.NAME.value, validateNameField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.PHONE.value, validateTextField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.TEXT.value, validateTextField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.QUESTION.value, validateTextField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.TEXTAREA.value, validateTextField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.DECIMAL.value, validateTextField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.INTEGER.value, validateTextField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.DROPDOWN.value, validateSingleChoiceField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.RADIO.value, validateSingleChoiceField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.CHECKBOX.value, validateMultiChoiceField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.RATING.value, validateRatingField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.TERMS.value, validateTermsField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.DATE.value, validateDateField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.STAR_RATING.value, validateStarRatingField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.ADDITIONAL_GUESTS.value, validateMultiEmailField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.RICH_TEXT.value, validateRichTextField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.CONDITION.value, validateConditionField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.FILE_UPLOAD.value, validateFileUploadField), _defineProperty(_fieldKindValidatorMa, QUESTION_KIND.CAPTCHA.value, validateCaptchaField), _fieldKindValidatorMa);
|
|
334
|
+
var validateFieldValue = function validateFieldValue(_ref16) {
|
|
335
|
+
var kind = _ref16.kind,
|
|
336
|
+
customValidator = _ref16.customValidator,
|
|
337
|
+
otherProps = _objectWithoutProperties(_ref16, _excluded$4);
|
|
338
|
+
return function (value) {
|
|
339
|
+
if (!(kind in fieldKindValidatorMap)) return;
|
|
340
|
+
var validator = fieldKindValidatorMap[kind];
|
|
341
|
+
var schema = customValidator || validator(_objectSpread$g({
|
|
342
|
+
kind: kind
|
|
343
|
+
}, otherProps));
|
|
344
|
+
|
|
345
|
+
// eslint-disable-next-line consistent-return, no-async-promise-executor
|
|
346
|
+
return new Promise( /*#__PURE__*/function () {
|
|
347
|
+
var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve) {
|
|
348
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
349
|
+
while (1) switch (_context.prev = _context.next) {
|
|
350
|
+
case 0:
|
|
351
|
+
_context.prev = 0;
|
|
352
|
+
_context.next = 3;
|
|
353
|
+
return schema.validate(value);
|
|
354
|
+
case 3:
|
|
355
|
+
resolve(undefined);
|
|
356
|
+
_context.next = 9;
|
|
357
|
+
break;
|
|
358
|
+
case 6:
|
|
359
|
+
_context.prev = 6;
|
|
360
|
+
_context.t0 = _context["catch"](0);
|
|
361
|
+
resolve(_context.t0.message);
|
|
362
|
+
case 9:
|
|
363
|
+
case "end":
|
|
364
|
+
return _context.stop();
|
|
365
|
+
}
|
|
366
|
+
}, _callee, null, [[0, 6]]);
|
|
367
|
+
}));
|
|
368
|
+
return function (_x) {
|
|
369
|
+
return _ref17.apply(this, arguments);
|
|
370
|
+
};
|
|
371
|
+
}());
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
var MultipleEmailInput = function MultipleEmailInput(_ref) {
|
|
376
|
+
var _jsx2;
|
|
377
|
+
var question = _ref.question,
|
|
378
|
+
customValidator = _ref.customValidator;
|
|
379
|
+
var name = question.id,
|
|
380
|
+
kind = question.kind,
|
|
381
|
+
isRequired = question.isRequired,
|
|
382
|
+
nodeId = question.nodeId;
|
|
383
|
+
var label = fieldWithFallback(question, "label");
|
|
384
|
+
var _useTranslation = useTranslation(),
|
|
385
|
+
t = _useTranslation.t;
|
|
386
|
+
var _useField = useField({
|
|
387
|
+
name: name || nodeId,
|
|
388
|
+
validate: validateFieldValue({
|
|
389
|
+
kind: kind,
|
|
390
|
+
label: label,
|
|
391
|
+
isRequired: isRequired,
|
|
392
|
+
customValidator: customValidator
|
|
393
|
+
})
|
|
394
|
+
}),
|
|
395
|
+
_useField2 = _slicedToArray(_useField, 3),
|
|
396
|
+
field = _useField2[0],
|
|
397
|
+
meta = _useField2[1],
|
|
398
|
+
_useField2$ = _useField2[2],
|
|
399
|
+
setValue = _useField2$.setValue,
|
|
400
|
+
setTouched = _useField2$.setTouched;
|
|
401
|
+
var _useState = useState(isPresent(field.value)),
|
|
402
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
403
|
+
isInputVisible = _useState2[0],
|
|
404
|
+
setIsInputVisible = _useState2[1];
|
|
405
|
+
return /*#__PURE__*/jsx("div", {
|
|
406
|
+
className: "neeto-form-engine-input__wrapper",
|
|
407
|
+
children: /*#__PURE__*/jsx("div", {
|
|
408
|
+
className: "neeto-ui-w-full",
|
|
409
|
+
children: isInputVisible ? /*#__PURE__*/jsx(NeetoUIMultiEmailInput, {
|
|
410
|
+
isRequired: isRequired,
|
|
411
|
+
label: label,
|
|
412
|
+
error: meta.touched ? meta.error : "",
|
|
413
|
+
helpText: t("neetoForm.common.addGuestsHelper"),
|
|
414
|
+
name: field.name,
|
|
415
|
+
placeholder: fieldWithFallback(question, "placeholder"),
|
|
416
|
+
value: field.value,
|
|
417
|
+
onBlur: function onBlur() {
|
|
418
|
+
return setTouched(true);
|
|
419
|
+
},
|
|
420
|
+
onChange: setValue
|
|
421
|
+
}) : /*#__PURE__*/jsx(Button, (_jsx2 = {
|
|
422
|
+
label: label
|
|
423
|
+
}, _defineProperty(_jsx2, "label", t("neetoForm.common.addGuests")), _defineProperty(_jsx2, "style", "secondary"), _defineProperty(_jsx2, "onClick", function onClick() {
|
|
424
|
+
return setIsInputVisible(true);
|
|
425
|
+
}), _jsx2))
|
|
426
|
+
})
|
|
427
|
+
});
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
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; }
|
|
431
|
+
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), !0).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; }
|
|
432
|
+
var t = clientI18nInstance.t;
|
|
433
|
+
var toEmailValues = function toEmailValues() {
|
|
434
|
+
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
435
|
+
return values.map(function (value) {
|
|
436
|
+
return {
|
|
437
|
+
label: value,
|
|
438
|
+
value: value,
|
|
439
|
+
valid: true
|
|
440
|
+
};
|
|
441
|
+
});
|
|
442
|
+
};
|
|
443
|
+
var getPhoneNumberFromUrl = function getPhoneNumberFromUrl(fieldCodes, fieldCode) {
|
|
444
|
+
var countryCode = fieldCodes["".concat(fieldCode, ".country")];
|
|
445
|
+
var phoneNumber = fieldCodes["".concat(fieldCode, ".number")];
|
|
446
|
+
if (!countryCode || !phoneNumber) return undefined;
|
|
447
|
+
var formattedValue = getPhoneData(phoneNumber, countryCode);
|
|
448
|
+
if (!formattedValue) return undefined;
|
|
449
|
+
return formattedValue.formatInternational();
|
|
450
|
+
};
|
|
451
|
+
var getOptionFromURL = function getOptionFromURL(_ref) {
|
|
452
|
+
var _findBy;
|
|
453
|
+
var optionsAttributes = _ref.optionsAttributes,
|
|
454
|
+
fieldCodes = _ref.fieldCodes,
|
|
455
|
+
fieldCode = _ref.fieldCode;
|
|
456
|
+
var preFillOption = fieldCodes[fieldCode];
|
|
457
|
+
return (_findBy = findBy({
|
|
458
|
+
label: preFillOption
|
|
459
|
+
}, optionsAttributes)) === null || _findBy === void 0 ? void 0 : _findBy.id;
|
|
460
|
+
};
|
|
461
|
+
var getMultipleOptionsFromURL = function getMultipleOptionsFromURL(_ref2) {
|
|
462
|
+
var optionsAttributes = _ref2.optionsAttributes,
|
|
463
|
+
fieldCodes = _ref2.fieldCodes,
|
|
464
|
+
fieldCode = _ref2.fieldCode;
|
|
465
|
+
var fieldCodeValue = fieldCodes[fieldCode];
|
|
466
|
+
if (!fieldCodeValue) return new Array(optionsAttributes.length).fill(false);
|
|
467
|
+
var allOptions = fieldCodeValue.split(",");
|
|
468
|
+
return optionsAttributes.map(function (option) {
|
|
469
|
+
return allOptions.includes(option.label);
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
var getStarRatingFromUrl = function getStarRatingFromUrl(_ref3) {
|
|
473
|
+
var minValue = _ref3.minValue,
|
|
474
|
+
maxValue = _ref3.maxValue,
|
|
475
|
+
fieldCodes = _ref3.fieldCodes,
|
|
476
|
+
fieldCode = _ref3.fieldCode;
|
|
477
|
+
var fieldCodeValue = fieldCodes[fieldCode];
|
|
478
|
+
var rating = parseInt(fieldCodeValue);
|
|
479
|
+
return isNil(rating) || isNaN(rating) ? "" : clamp(minValue, maxValue, rating);
|
|
480
|
+
};
|
|
481
|
+
var getAdditionalGuestsFromUrl = function getAdditionalGuestsFromUrl(_ref4) {
|
|
482
|
+
var fieldCodes = _ref4.fieldCodes,
|
|
483
|
+
fieldCode = _ref4.fieldCode;
|
|
484
|
+
var fieldCodeValue = fieldCodes[fieldCode];
|
|
485
|
+
var allEmails = fieldCodeValue === null || fieldCodeValue === void 0 ? void 0 : fieldCodeValue.split(",");
|
|
486
|
+
if (!allEmails) return [];
|
|
487
|
+
return allEmails.map(function (email) {
|
|
488
|
+
return {
|
|
489
|
+
label: email,
|
|
490
|
+
value: email,
|
|
491
|
+
valid: EMAIL_REGEX.test(email)
|
|
492
|
+
};
|
|
493
|
+
});
|
|
494
|
+
};
|
|
495
|
+
var getRatingFromUrl = function getRatingFromUrl(_ref5) {
|
|
496
|
+
var fieldCodes = _ref5.fieldCodes,
|
|
497
|
+
fieldCode = _ref5.fieldCode;
|
|
498
|
+
var fieldCodeValue = fieldCodes[fieldCode];
|
|
499
|
+
var allowedValues = Object.values(RATING_VALUES).map(prop("value"));
|
|
500
|
+
return allowedValues.includes(fieldCodeValue) ? fieldCodeValue : "";
|
|
501
|
+
};
|
|
502
|
+
var getNumberFromUrl = function getNumberFromUrl(_ref6) {
|
|
503
|
+
var fieldCodes = _ref6.fieldCodes,
|
|
504
|
+
fieldCode = _ref6.fieldCode,
|
|
505
|
+
kind = _ref6.kind;
|
|
506
|
+
var fieldCodeValue = fieldCodes[fieldCode];
|
|
507
|
+
var parsedValue = kind === QUESTION_KIND.INTEGER.value ? parseInt(fieldCodeValue) : parseFloat(fieldCodeValue);
|
|
508
|
+
return parsedValue || "";
|
|
509
|
+
};
|
|
510
|
+
var getLabel = function getLabel(label, isRequired) {
|
|
511
|
+
return isRequired ? "".concat(label, "*") : label;
|
|
512
|
+
};
|
|
513
|
+
var generateInitValues = function generateInitValues(_ref7) {
|
|
514
|
+
var questions = _ref7.questions,
|
|
515
|
+
_ref7$initialValues = _ref7.initialValues,
|
|
516
|
+
initialValues = _ref7$initialValues === void 0 ? [] : _ref7$initialValues,
|
|
517
|
+
_ref7$localValues = _ref7.localValues,
|
|
518
|
+
localValues = _ref7$localValues === void 0 ? {} : _ref7$localValues,
|
|
519
|
+
_ref7$fieldCodes = _ref7.fieldCodes,
|
|
520
|
+
fieldCodes = _ref7$fieldCodes === void 0 ? {} : _ref7$fieldCodes;
|
|
521
|
+
var initValues = {};
|
|
522
|
+
var valuesMap = {};
|
|
523
|
+
if (initialValues) {
|
|
524
|
+
valuesMap = initialValues.reduce(function (acc, answer) {
|
|
525
|
+
return _objectSpread$f(_objectSpread$f({}, acc), {}, _defineProperty({}, answer.questionId, {
|
|
526
|
+
value: answer.value,
|
|
527
|
+
optionIds: answer.optionIds
|
|
528
|
+
}));
|
|
529
|
+
}, {});
|
|
530
|
+
}
|
|
531
|
+
questions.forEach(function (question) {
|
|
532
|
+
var id = question.id,
|
|
533
|
+
kind = question.kind,
|
|
534
|
+
optionsAttributes = question.optionsAttributes,
|
|
535
|
+
fieldCode = question.fieldCode,
|
|
536
|
+
minValue = question.minValue,
|
|
537
|
+
maxValue = question.maxValue;
|
|
538
|
+
switch (kind) {
|
|
539
|
+
case QUESTION_KIND.CONDITION.value:
|
|
540
|
+
{
|
|
541
|
+
var _valuesMap$id$value, _valuesMap;
|
|
542
|
+
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;
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
case QUESTION_KIND.ADDITIONAL_GUESTS.value:
|
|
546
|
+
{
|
|
547
|
+
var _valuesMap2;
|
|
548
|
+
var emailsFromSubmission = toEmailValues((_valuesMap2 = valuesMap) === null || _valuesMap2 === void 0 || (_valuesMap2 = _valuesMap2[id]) === null || _valuesMap2 === void 0 ? void 0 : _valuesMap2.value);
|
|
549
|
+
initValues[id] = isNotEmpty(emailsFromSubmission) ? emailsFromSubmission : getAdditionalGuestsFromUrl({
|
|
550
|
+
fieldCodes: fieldCodes,
|
|
551
|
+
fieldCode: fieldCode
|
|
552
|
+
});
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
case QUESTION_KIND.CHECKBOX.value:
|
|
556
|
+
{
|
|
557
|
+
var _valuesMap$id;
|
|
558
|
+
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) {
|
|
559
|
+
var _valuesMap$id2;
|
|
560
|
+
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);
|
|
561
|
+
}) : getMultipleOptionsFromURL({
|
|
562
|
+
optionsAttributes: optionsAttributes,
|
|
563
|
+
fieldCodes: fieldCodes,
|
|
564
|
+
fieldCode: fieldCode
|
|
565
|
+
});
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
case QUESTION_KIND.RADIO.value:
|
|
569
|
+
case QUESTION_KIND.DROPDOWN.value:
|
|
570
|
+
{
|
|
571
|
+
var _optionsAttributes$fi;
|
|
572
|
+
initValues[id] = ((_optionsAttributes$fi = optionsAttributes.find(function (option) {
|
|
573
|
+
var _valuesMap$id3;
|
|
574
|
+
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);
|
|
575
|
+
})) === null || _optionsAttributes$fi === void 0 ? void 0 : _optionsAttributes$fi.id) || getOptionFromURL({
|
|
576
|
+
optionsAttributes: optionsAttributes,
|
|
577
|
+
fieldCodes: fieldCodes,
|
|
578
|
+
fieldCode: fieldCode
|
|
579
|
+
});
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
case QUESTION_KIND.INTEGER.value:
|
|
583
|
+
case QUESTION_KIND.DECIMAL.value:
|
|
584
|
+
{
|
|
585
|
+
var _valuesMap3;
|
|
586
|
+
initValues[id] = ((_valuesMap3 = valuesMap) === null || _valuesMap3 === void 0 || (_valuesMap3 = _valuesMap3[id]) === null || _valuesMap3 === void 0 ? void 0 : _valuesMap3.value) || getNumberFromUrl({
|
|
587
|
+
fieldCodes: fieldCodes,
|
|
588
|
+
fieldCode: fieldCode,
|
|
589
|
+
kind: kind
|
|
590
|
+
});
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
case QUESTION_KIND.RATING.value:
|
|
594
|
+
{
|
|
595
|
+
var _valuesMap4;
|
|
596
|
+
initValues[id] = ((_valuesMap4 = valuesMap) === null || _valuesMap4 === void 0 || (_valuesMap4 = _valuesMap4[id]) === null || _valuesMap4 === void 0 ? void 0 : _valuesMap4.value) || getRatingFromUrl({
|
|
597
|
+
fieldCodes: fieldCodes,
|
|
598
|
+
fieldCode: fieldCode
|
|
599
|
+
});
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
case QUESTION_KIND.TERMS.value:
|
|
603
|
+
{
|
|
604
|
+
initValues[id] = false;
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
case QUESTION_KIND.FILE_UPLOAD.value:
|
|
608
|
+
{
|
|
609
|
+
var _valuesMap$id$value2, _valuesMap5;
|
|
610
|
+
initValues[id] = {
|
|
611
|
+
files: (_valuesMap$id$value2 = (_valuesMap5 = valuesMap) === null || _valuesMap5 === void 0 || (_valuesMap5 = _valuesMap5[id]) === null || _valuesMap5 === void 0 ? void 0 : _valuesMap5.value) !== null && _valuesMap$id$value2 !== void 0 ? _valuesMap$id$value2 : []
|
|
612
|
+
};
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
case QUESTION_KIND.PHONE.value:
|
|
616
|
+
{
|
|
617
|
+
var _valuesMap$id$value3, _valuesMap6;
|
|
618
|
+
initValues[id] = (_valuesMap$id$value3 = (_valuesMap6 = valuesMap) === null || _valuesMap6 === void 0 || (_valuesMap6 = _valuesMap6[id]) === null || _valuesMap6 === void 0 ? void 0 : _valuesMap6.value) !== null && _valuesMap$id$value3 !== void 0 ? _valuesMap$id$value3 : getPhoneNumberFromUrl(fieldCodes, fieldCode);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
case QUESTION_KIND.STAR_RATING.value:
|
|
622
|
+
{
|
|
623
|
+
var _valuesMap$id$value4, _valuesMap7;
|
|
624
|
+
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 : getStarRatingFromUrl({
|
|
625
|
+
minValue: minValue,
|
|
626
|
+
maxValue: maxValue,
|
|
627
|
+
fieldCodes: fieldCodes,
|
|
628
|
+
fieldCode: fieldCode
|
|
629
|
+
});
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
default:
|
|
633
|
+
{
|
|
634
|
+
var _valuesMap$id$value5, _valuesMap8;
|
|
635
|
+
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 : fieldCodes[fieldCode] || "";
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
return !isEmptyValues(localValues) ? localValues : initValues;
|
|
641
|
+
};
|
|
642
|
+
var generateFormResponse = function generateFormResponse(response, questions) {
|
|
643
|
+
var formResponse = [];
|
|
644
|
+
questions.forEach(function (question) {
|
|
645
|
+
var id = question.id,
|
|
646
|
+
kind = question.kind,
|
|
647
|
+
optionsAttributes = question.optionsAttributes;
|
|
648
|
+
if (!SCHEMA_LESS_QUESTION_KINDS.includes(kind)) {
|
|
649
|
+
var responseValue = response[id];
|
|
650
|
+
if (kind === QUESTION_KIND.RADIO.value || kind === QUESTION_KIND.DROPDOWN.value) {
|
|
651
|
+
var option = findById(responseValue, optionsAttributes);
|
|
652
|
+
if (option) {
|
|
653
|
+
formResponse.push({
|
|
654
|
+
questionId: id,
|
|
655
|
+
questionOptionId: option.id,
|
|
656
|
+
value: option.label,
|
|
657
|
+
kind: kind
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
} else if (kind === QUESTION_KIND.CHECKBOX.value) {
|
|
661
|
+
responseValue.forEach(function (isChecked, index) {
|
|
662
|
+
if (!isChecked) return;
|
|
663
|
+
var option = optionsAttributes[index];
|
|
664
|
+
formResponse.push({
|
|
665
|
+
questionId: id,
|
|
666
|
+
questionOptionId: option.id,
|
|
667
|
+
value: option.label,
|
|
668
|
+
kind: kind
|
|
669
|
+
});
|
|
670
|
+
});
|
|
671
|
+
} else if (kind === QUESTION_KIND.PHONE.value) {
|
|
672
|
+
formResponse.push({
|
|
673
|
+
questionId: id,
|
|
674
|
+
value: responseValue ? parsePhoneNumber(responseValue).formatInternational() : "",
|
|
675
|
+
kind: kind
|
|
676
|
+
});
|
|
677
|
+
} else if (kind === QUESTION_KIND.ADDITIONAL_GUESTS.value) {
|
|
678
|
+
formResponse.push({
|
|
679
|
+
questionId: id,
|
|
680
|
+
value: responseValue ? pluck("value", responseValue) : null,
|
|
681
|
+
kind: kind
|
|
682
|
+
});
|
|
683
|
+
} else if (kind === QUESTION_KIND.FILE_UPLOAD.value) {
|
|
684
|
+
formResponse.push({
|
|
685
|
+
questionId: id,
|
|
686
|
+
files: isPresent(responseValue) ? responseValue.files : null,
|
|
687
|
+
kind: kind
|
|
688
|
+
});
|
|
689
|
+
} else formResponse.push({
|
|
690
|
+
questionId: id,
|
|
691
|
+
value: responseValue,
|
|
692
|
+
kind: kind
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
return formResponse;
|
|
697
|
+
};
|
|
698
|
+
var mergeRefs = function mergeRefs() {
|
|
699
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
700
|
+
refs[_key] = arguments[_key];
|
|
701
|
+
}
|
|
702
|
+
return function (node) {
|
|
703
|
+
return refs.forEach(function (ref) {
|
|
704
|
+
return typeof ref === "function" ? ref(node) : ref.current = node;
|
|
705
|
+
});
|
|
706
|
+
};
|
|
707
|
+
};
|
|
708
|
+
var getError = function getError(meta) {
|
|
709
|
+
if (meta.error && meta.touched) {
|
|
710
|
+
return typeof meta.error === "string" ? meta.error : "";
|
|
711
|
+
}
|
|
712
|
+
return "";
|
|
713
|
+
};
|
|
714
|
+
var buildAutoCompleteAttribute = function buildAutoCompleteAttribute(kind, autoCompleteKinds, formDomProps) {
|
|
715
|
+
return (formDomProps === null || formDomProps === void 0 ? void 0 : formDomProps.autoComplete) === "off" && includes(kind, autoCompleteKinds) ? "on" : undefined;
|
|
716
|
+
};
|
|
717
|
+
var convertMbToBytes = function convertMbToBytes(mb) {
|
|
718
|
+
return mb * 1024 * 1024;
|
|
719
|
+
};
|
|
720
|
+
var renderErrorMessage = function renderErrorMessage(errorObject, maxFileSize, isMultiple) {
|
|
721
|
+
var error = errorObject.errors[0];
|
|
722
|
+
var file = errorObject.file;
|
|
723
|
+
if (error) {
|
|
724
|
+
var code = error.code;
|
|
725
|
+
switch (code) {
|
|
726
|
+
case ERROR_CODES.FILE_TOO_LARGE:
|
|
727
|
+
return t("neetoForm.fileUpload.dropzone.errors.fileTooLarge", {
|
|
728
|
+
fileName: file.name,
|
|
729
|
+
maxSize: Math.round(maxFileSize / 1048576)
|
|
730
|
+
});
|
|
731
|
+
case ERROR_CODES.FILE_INVALID_TYPE:
|
|
732
|
+
return t("neetoForm.fileUpload.dropzone.errors.fileInvalidType", {
|
|
733
|
+
fileType: path.extname(file.name)
|
|
734
|
+
});
|
|
735
|
+
case ERROR_CODES.TOO_MANY_FILES:
|
|
736
|
+
if (!isMultiple) {
|
|
737
|
+
return t("neetoForm.fileUpload.dropzone.errors.tooManyFiles");
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return t("neetoForm.fileUpload.dropzone.errors.defaultError", {
|
|
742
|
+
fileName: file.name
|
|
743
|
+
});
|
|
744
|
+
};
|
|
745
|
+
var renderButtonsInOrder = function renderButtonsInOrder(buttonsArray, shouldReverse) {
|
|
746
|
+
var orderedButtons = shouldReverse ? buttonsArray.reverse() : buttonsArray;
|
|
747
|
+
return map(identity, orderedButtons);
|
|
748
|
+
};
|
|
749
|
+
var getSelectedRating = function getSelectedRating(value) {
|
|
750
|
+
var parsedValue = parseInt(value);
|
|
751
|
+
return isNaN(parsedValue) ? -1 : parsedValue;
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
var CaptchaField = function CaptchaField(_ref) {
|
|
755
|
+
var question = _ref.question,
|
|
756
|
+
preview = _ref.preview,
|
|
757
|
+
customValidator = _ref.customValidator,
|
|
758
|
+
captchaRef = _ref.captchaRef;
|
|
759
|
+
var name = question.id,
|
|
760
|
+
kind = question.kind,
|
|
761
|
+
isRequired = question.isRequired,
|
|
762
|
+
variant = question.variant,
|
|
763
|
+
nodeId = question.nodeId;
|
|
764
|
+
var label = fieldWithFallback(question, "label");
|
|
765
|
+
var _useField = useField({
|
|
766
|
+
name: name || nodeId,
|
|
767
|
+
validate: validateFieldValue({
|
|
768
|
+
kind: kind,
|
|
769
|
+
label: label,
|
|
770
|
+
isRequired: isRequired,
|
|
771
|
+
customValidator: customValidator,
|
|
772
|
+
variant: variant
|
|
773
|
+
})
|
|
774
|
+
}),
|
|
775
|
+
_useField2 = _slicedToArray(_useField, 3);
|
|
776
|
+
_useField2[0];
|
|
777
|
+
var _useField2$ = _useField2[1],
|
|
778
|
+
touched = _useField2$.touched,
|
|
779
|
+
error = _useField2$.error,
|
|
780
|
+
_useField2$2 = _useField2[2],
|
|
781
|
+
setValue = _useField2$2.setValue,
|
|
782
|
+
setTouched = _useField2$2.setTouched;
|
|
783
|
+
var handleVerifyCaptcha = function handleVerifyCaptcha(response) {
|
|
784
|
+
setTouched(true);
|
|
785
|
+
setValue(response);
|
|
786
|
+
};
|
|
787
|
+
var Component = CAPTCHA_COMPONENT_MAP[variant];
|
|
788
|
+
return /*#__PURE__*/jsxs("div", {
|
|
789
|
+
className: "neeto-form-engine-input__wrapper",
|
|
790
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
791
|
+
className: "neeto-form-engine-input__label-wrapper",
|
|
792
|
+
children: label && /*#__PURE__*/jsx("label", {
|
|
793
|
+
className: "neeto-form-engine-label",
|
|
794
|
+
children: getLabel(label, isRequired)
|
|
795
|
+
})
|
|
796
|
+
}), /*#__PURE__*/jsx("div", {
|
|
797
|
+
className: classnames({
|
|
798
|
+
"pointer-events-none": preview
|
|
799
|
+
}),
|
|
800
|
+
children: /*#__PURE__*/jsx(Component, {
|
|
801
|
+
captchaRef: captchaRef,
|
|
802
|
+
handleVerifyCaptcha: handleVerifyCaptcha,
|
|
803
|
+
handleBlur: function handleBlur() {
|
|
804
|
+
return setTouched(true);
|
|
805
|
+
}
|
|
806
|
+
})
|
|
807
|
+
}), touched && error && /*#__PURE__*/jsx("p", {
|
|
808
|
+
className: "neeto-form-engine-input__error",
|
|
809
|
+
"data-cy": "neeto-form-engine-captcha-error",
|
|
810
|
+
children: error
|
|
811
|
+
})]
|
|
812
|
+
});
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
var MATH_OPERATORS = {
|
|
816
|
+
PLUS: "+",
|
|
817
|
+
MINUS: "-"
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
var generateRandomOperation = function generateRandomOperation() {
|
|
821
|
+
var firstNumber = getRandomInt(1, 50);
|
|
822
|
+
var secondNumber = getRandomInt(1, 50);
|
|
823
|
+
var operator = randomPick.apply(void 0, _toConsumableArray(values(MATH_OPERATORS)));
|
|
824
|
+
return {
|
|
825
|
+
firstNumber: firstNumber,
|
|
826
|
+
secondNumber: secondNumber,
|
|
827
|
+
operator: operator
|
|
828
|
+
};
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
var MathCaptcha = function MathCaptcha(_ref) {
|
|
832
|
+
var captchaRef = _ref.captchaRef,
|
|
833
|
+
handleVerifyCaptcha = _ref.handleVerifyCaptcha,
|
|
834
|
+
handleBlur = _ref.handleBlur;
|
|
835
|
+
var _useState = useState(generateRandomOperation()),
|
|
836
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
837
|
+
operation = _useState2[0],
|
|
838
|
+
setOperation = _useState2[1];
|
|
839
|
+
var _useState3 = useState(""),
|
|
840
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
841
|
+
userInput = _useState4[0],
|
|
842
|
+
setUserInput = _useState4[1];
|
|
843
|
+
var firstNumber = operation.firstNumber,
|
|
844
|
+
secondNumber = operation.secondNumber,
|
|
845
|
+
operator = operation.operator;
|
|
846
|
+
var resetCaptcha = function resetCaptcha() {
|
|
847
|
+
setOperation(generateRandomOperation());
|
|
848
|
+
setUserInput("");
|
|
849
|
+
};
|
|
850
|
+
useImperativeHandle(captchaRef, function () {
|
|
851
|
+
return {
|
|
852
|
+
reset: resetCaptcha
|
|
853
|
+
};
|
|
854
|
+
});
|
|
855
|
+
var calculateResult = function calculateResult() {
|
|
856
|
+
switch (operator) {
|
|
857
|
+
case MATH_OPERATORS.PLUS:
|
|
858
|
+
return firstNumber + secondNumber;
|
|
859
|
+
case MATH_OPERATORS.MINUS:
|
|
860
|
+
return firstNumber - secondNumber;
|
|
861
|
+
default:
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
var verifyCaptcha = function verifyCaptcha() {
|
|
866
|
+
var result = calculateResult();
|
|
867
|
+
if (result === null) return;
|
|
868
|
+
handleVerifyCaptcha(result === Number(userInput));
|
|
869
|
+
};
|
|
870
|
+
useUpdateEffect(function () {
|
|
871
|
+
verifyCaptcha();
|
|
872
|
+
}, [userInput]);
|
|
873
|
+
return /*#__PURE__*/jsxs("div", {
|
|
874
|
+
className: "neeto-form-nano-math-captcha",
|
|
875
|
+
ref: captchaRef,
|
|
876
|
+
children: [/*#__PURE__*/jsx("button", {
|
|
877
|
+
className: "neeto-form-nano-math-captcha__button",
|
|
878
|
+
type: "button",
|
|
879
|
+
onClick: resetCaptcha,
|
|
880
|
+
children: /*#__PURE__*/jsx(Refresh, {})
|
|
881
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
882
|
+
className: "neeto-form-nano-math-captcha__equation",
|
|
883
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
884
|
+
children: firstNumber
|
|
885
|
+
}), /*#__PURE__*/jsx("span", {
|
|
886
|
+
children: operator
|
|
887
|
+
}), /*#__PURE__*/jsx("span", {
|
|
888
|
+
children: secondNumber
|
|
889
|
+
}), /*#__PURE__*/jsx("span", {
|
|
890
|
+
children: "="
|
|
891
|
+
})]
|
|
892
|
+
}), /*#__PURE__*/jsx(Input, {
|
|
893
|
+
required: true,
|
|
894
|
+
className: "neeto-form-nano-math-captcha__input",
|
|
895
|
+
value: userInput,
|
|
896
|
+
onBlur: handleBlur,
|
|
897
|
+
onChange: withEventTargetValue(setUserInput)
|
|
898
|
+
})]
|
|
899
|
+
});
|
|
900
|
+
};
|
|
901
|
+
|
|
902
|
+
var Recaptcha = function Recaptcha(_ref) {
|
|
903
|
+
var captchaRef = _ref.captchaRef,
|
|
904
|
+
handleVerifyCaptcha = _ref.handleVerifyCaptcha;
|
|
905
|
+
var verifyRecaptcha = function verifyRecaptcha(response) {
|
|
906
|
+
if (response === null) {
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
handleVerifyCaptcha(response);
|
|
910
|
+
};
|
|
911
|
+
var expiredRecaptcha = function expiredRecaptcha() {
|
|
912
|
+
var _captchaRef$current;
|
|
913
|
+
captchaRef === null || captchaRef === void 0 || (_captchaRef$current = captchaRef.current) === null || _captchaRef$current === void 0 || _captchaRef$current.reset();
|
|
914
|
+
handleVerifyCaptcha("");
|
|
915
|
+
};
|
|
916
|
+
return /*#__PURE__*/jsx(ReCAPTCHA, {
|
|
917
|
+
hl: clientI18nInstance.language,
|
|
918
|
+
ref: captchaRef,
|
|
919
|
+
sitekey: globalProps.formNanoRecaptchaV2SiteKey,
|
|
920
|
+
onChange: verifyRecaptcha,
|
|
921
|
+
onErrored: noop,
|
|
922
|
+
onExpired: expiredRecaptcha
|
|
923
|
+
}, clientI18nInstance.language);
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
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; }
|
|
927
|
+
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), !0).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; }
|
|
928
|
+
var ConditionField = function ConditionField(_ref) {
|
|
929
|
+
var question = _ref.question,
|
|
930
|
+
customValidator = _ref.customValidator;
|
|
931
|
+
var name = question.id,
|
|
932
|
+
kind = question.kind,
|
|
933
|
+
isRequired = question.isRequired,
|
|
934
|
+
nodeId = question.nodeId;
|
|
935
|
+
var label = fieldWithFallback(question, "label");
|
|
936
|
+
return /*#__PURE__*/jsx(Field, {
|
|
937
|
+
name: name || nodeId,
|
|
938
|
+
validate: validateFieldValue({
|
|
939
|
+
kind: kind,
|
|
940
|
+
label: label,
|
|
941
|
+
isRequired: isRequired,
|
|
942
|
+
customValidator: customValidator
|
|
943
|
+
}),
|
|
944
|
+
children: function children(_ref2) {
|
|
945
|
+
var meta = _ref2.meta,
|
|
946
|
+
field = _ref2.field;
|
|
947
|
+
return /*#__PURE__*/jsx(Checkbox, _objectSpread$e(_objectSpread$e({}, _objectSpread$e(_objectSpread$e({}, field), {}, {
|
|
948
|
+
label: label,
|
|
949
|
+
name: name
|
|
950
|
+
})), {}, {
|
|
951
|
+
checked: field.value,
|
|
952
|
+
error: meta.touched ? meta.error : "",
|
|
953
|
+
required: isRequired
|
|
954
|
+
}));
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
var _excluded$3 = ["value"];
|
|
960
|
+
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; }
|
|
961
|
+
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), !0).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; }
|
|
962
|
+
dayjs.extend(weekOfYear);
|
|
963
|
+
dayjs.extend(weekday);
|
|
964
|
+
dayjs.extend(localeData);
|
|
965
|
+
dayjs.extend(utc);
|
|
966
|
+
var DateField = function DateField(_ref) {
|
|
967
|
+
var question = _ref.question,
|
|
968
|
+
customValidator = _ref.customValidator;
|
|
969
|
+
var name = question.id,
|
|
970
|
+
kind = question.kind,
|
|
971
|
+
isRequired = question.isRequired,
|
|
972
|
+
nodeId = question.nodeId;
|
|
973
|
+
var label = fieldWithFallback(question, "label");
|
|
974
|
+
var _QUESTION_KIND$kind$t = QUESTION_KIND[kind.toUpperCase()].type,
|
|
975
|
+
type = _QUESTION_KIND$kind$t === void 0 ? "date" : _QUESTION_KIND$kind$t;
|
|
976
|
+
return /*#__PURE__*/jsxs("div", {
|
|
977
|
+
className: "neeto-form-engine-input__wrapper",
|
|
978
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
979
|
+
className: "neeto-form-engine-input__label-wrapper",
|
|
980
|
+
children: label && /*#__PURE__*/jsx("label", {
|
|
981
|
+
className: "neeto-form-engine-label",
|
|
982
|
+
children: getLabel(label, isRequired)
|
|
983
|
+
})
|
|
984
|
+
}), /*#__PURE__*/jsx("div", {
|
|
985
|
+
className: "neeto-form-engine-date-picker",
|
|
986
|
+
children: /*#__PURE__*/jsx(Field, {
|
|
987
|
+
name: name || nodeId,
|
|
988
|
+
validate: validateFieldValue({
|
|
989
|
+
kind: kind,
|
|
990
|
+
label: label,
|
|
991
|
+
isRequired: isRequired,
|
|
992
|
+
customValidator: customValidator
|
|
993
|
+
}),
|
|
994
|
+
children: function children(_ref2) {
|
|
995
|
+
var meta = _ref2.meta,
|
|
996
|
+
_ref2$field = _ref2.field,
|
|
997
|
+
value = _ref2$field.value,
|
|
998
|
+
field = _objectWithoutProperties(_ref2$field, _excluded$3),
|
|
999
|
+
form = _ref2.form;
|
|
1000
|
+
return /*#__PURE__*/jsx(DatePicker, _objectSpread$d(_objectSpread$d({}, _objectSpread$d(_objectSpread$d({}, field), {}, {
|
|
1001
|
+
type: type
|
|
1002
|
+
})), {}, {
|
|
1003
|
+
dateFormat: "MMM D, YYYY",
|
|
1004
|
+
error: meta.touched ? meta.error : "",
|
|
1005
|
+
placeholder: fieldWithFallback(question, "placeholder"),
|
|
1006
|
+
popupClassName: "neeto-form-engine-date-picker-popup",
|
|
1007
|
+
required: isRequired,
|
|
1008
|
+
size: "small",
|
|
1009
|
+
value: getValidDate(value),
|
|
1010
|
+
onChange: function onChange(date) {
|
|
1011
|
+
form.setFieldValue(name, date ? date.toISOString() : "");
|
|
1012
|
+
}
|
|
1013
|
+
}));
|
|
1014
|
+
}
|
|
1015
|
+
})
|
|
1016
|
+
})]
|
|
1017
|
+
});
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
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; }
|
|
1021
|
+
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), !0).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; }
|
|
1022
|
+
var EmailField = function EmailField(_ref) {
|
|
1023
|
+
var question = _ref.question,
|
|
1024
|
+
customValidator = _ref.customValidator,
|
|
1025
|
+
autoComplete = _ref.autoComplete;
|
|
1026
|
+
var name = question.id,
|
|
1027
|
+
kind = question.kind,
|
|
1028
|
+
isRequired = question.isRequired,
|
|
1029
|
+
isDomainRestrictionEnabled = question.isDomainRestrictionEnabled,
|
|
1030
|
+
restrictedDomains = question.restrictedDomains,
|
|
1031
|
+
nodeId = question.nodeId;
|
|
1032
|
+
var label = fieldWithFallback(question, "label");
|
|
1033
|
+
var type = QUESTION_KIND[kind.toUpperCase()].type;
|
|
1034
|
+
var _useField = useField({
|
|
1035
|
+
name: name || nodeId,
|
|
1036
|
+
validate: validateFieldValue({
|
|
1037
|
+
kind: kind,
|
|
1038
|
+
label: label,
|
|
1039
|
+
isRequired: isRequired,
|
|
1040
|
+
customValidator: customValidator,
|
|
1041
|
+
restrictedDomains: isDomainRestrictionEnabled ? restrictedDomains : []
|
|
1042
|
+
})
|
|
1043
|
+
}),
|
|
1044
|
+
_useField2 = _slicedToArray(_useField, 3),
|
|
1045
|
+
field = _useField2[0],
|
|
1046
|
+
_useField2$ = _useField2[1],
|
|
1047
|
+
touched = _useField2$.touched,
|
|
1048
|
+
error = _useField2$.error,
|
|
1049
|
+
_useField2$2 = _useField2[2],
|
|
1050
|
+
setValue = _useField2$2.setValue,
|
|
1051
|
+
setTouched = _useField2$2.setTouched;
|
|
1052
|
+
var handleFieldChange = withEventTargetValue(setValue);
|
|
1053
|
+
return /*#__PURE__*/jsx(Input, _objectSpread$c(_objectSpread$c({}, _objectSpread$c(_objectSpread$c({
|
|
1054
|
+
type: type
|
|
1055
|
+
}, field), {}, {
|
|
1056
|
+
autoComplete: autoComplete,
|
|
1057
|
+
label: label
|
|
1058
|
+
})), {}, {
|
|
1059
|
+
error: touched ? error : "",
|
|
1060
|
+
name: kind,
|
|
1061
|
+
placeholder: fieldWithFallback(question, "placeholder"),
|
|
1062
|
+
required: isRequired,
|
|
1063
|
+
onBlur: function onBlur() {
|
|
1064
|
+
return setTouched(true);
|
|
1065
|
+
},
|
|
1066
|
+
onChange: handleFieldChange
|
|
1067
|
+
}));
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
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; }
|
|
1071
|
+
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), !0).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; }
|
|
1072
|
+
var useFileUpload = function useFileUpload(_ref) {
|
|
1073
|
+
var disabled = _ref.disabled,
|
|
1074
|
+
accept = _ref.accept,
|
|
1075
|
+
multiple = _ref.multiple,
|
|
1076
|
+
name = _ref.name,
|
|
1077
|
+
maxFileSize = _ref.maxFileSize;
|
|
1078
|
+
var _useState = useState({}),
|
|
1079
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1080
|
+
uploadProgress = _useState2[0],
|
|
1081
|
+
setUploadProgress = _useState2[1];
|
|
1082
|
+
var _useState3 = useState(""),
|
|
1083
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
1084
|
+
uploadError = _useState4[0],
|
|
1085
|
+
setUploadError = _useState4[1];
|
|
1086
|
+
var _useField = useField(name),
|
|
1087
|
+
_useField2 = _slicedToArray(_useField, 3);
|
|
1088
|
+
_useField2[0];
|
|
1089
|
+
var value = _useField2[1].value,
|
|
1090
|
+
_useField2$ = _useField2[2],
|
|
1091
|
+
setValue = _useField2$.setValue,
|
|
1092
|
+
setError = _useField2$.setError,
|
|
1093
|
+
setTouched = _useField2$.setTouched;
|
|
1094
|
+
var filesRef = useRef(value === null || value === void 0 ? void 0 : value.files);
|
|
1095
|
+
filesRef.current = value === null || value === void 0 ? void 0 : value.files;
|
|
1096
|
+
var cancel = useCallback(function (index) {
|
|
1097
|
+
return function () {
|
|
1098
|
+
var _value$files;
|
|
1099
|
+
setUploadProgress(assoc(value.files[index].name, null));
|
|
1100
|
+
var newFiles = (_value$files = value.files) === null || _value$files === void 0 ? void 0 : _value$files.filter(function (_, idx) {
|
|
1101
|
+
return idx !== index;
|
|
1102
|
+
});
|
|
1103
|
+
setValue({
|
|
1104
|
+
files: newFiles
|
|
1105
|
+
});
|
|
1106
|
+
};
|
|
1107
|
+
}, [value]);
|
|
1108
|
+
useEffect(function () {
|
|
1109
|
+
uploadError && setError(uploadError);
|
|
1110
|
+
}, [uploadError]);
|
|
1111
|
+
var onDropAccepted = /*#__PURE__*/function () {
|
|
1112
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(acceptedFiles) {
|
|
1113
|
+
var initialFiles, updatedFiles, newFiles;
|
|
1114
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1115
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1116
|
+
case 0:
|
|
1117
|
+
setTouched(false);
|
|
1118
|
+
setUploadError("");
|
|
1119
|
+
initialFiles = acceptedFiles.map(function (file) {
|
|
1120
|
+
return {
|
|
1121
|
+
name: file.name,
|
|
1122
|
+
size: file.size
|
|
1123
|
+
};
|
|
1124
|
+
});
|
|
1125
|
+
updatedFiles = multiple ? [].concat(_toConsumableArray(value.files || []), _toConsumableArray(initialFiles)) : initialFiles;
|
|
1126
|
+
setValue({
|
|
1127
|
+
files: updatedFiles
|
|
1128
|
+
});
|
|
1129
|
+
_context.next = 7;
|
|
1130
|
+
return new Promise(function (resolve) {
|
|
1131
|
+
var files = [];
|
|
1132
|
+
acceptedFiles.forEach(function (file) {
|
|
1133
|
+
setUploadProgress(assoc(file.name, 0));
|
|
1134
|
+
var upload = new DirectUpload(file, DIRECT_UPLOAD_URL, {
|
|
1135
|
+
directUploadWillStoreFileWithXHR: function directUploadWillStoreFileWithXHR(xhr) {
|
|
1136
|
+
xhr.upload.addEventListener("progress", function (event) {
|
|
1137
|
+
var percentComplete = Math.round(event.loaded / event.total * 100);
|
|
1138
|
+
setUploadProgress(assoc(file.name, percentComplete));
|
|
1139
|
+
});
|
|
1140
|
+
xhr.upload.addEventListener("load", function () {
|
|
1141
|
+
setUploadProgress(assoc(file.name, undefined));
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
upload.create(function (error, blob) {
|
|
1146
|
+
if (error) {
|
|
1147
|
+
return setUploadError(error);
|
|
1148
|
+
}
|
|
1149
|
+
files.push({
|
|
1150
|
+
url: blob.blob_url,
|
|
1151
|
+
name: blob.filename,
|
|
1152
|
+
signedId: blob.signed_id
|
|
1153
|
+
});
|
|
1154
|
+
var isUploadCompleted = multiple ? acceptedFiles.length === files.length : files.length === 1;
|
|
1155
|
+
if (isUploadCompleted) {
|
|
1156
|
+
return resolve(files);
|
|
1157
|
+
}
|
|
1158
|
+
return "";
|
|
1159
|
+
});
|
|
1160
|
+
});
|
|
1161
|
+
return files;
|
|
1162
|
+
});
|
|
1163
|
+
case 7:
|
|
1164
|
+
newFiles = _context.sent;
|
|
1165
|
+
if (multiple) {
|
|
1166
|
+
setValue({
|
|
1167
|
+
files: filesRef.current.map(function (file) {
|
|
1168
|
+
var uploadedFile = findBy({
|
|
1169
|
+
name: file.name
|
|
1170
|
+
}, newFiles);
|
|
1171
|
+
return _objectSpread$b(_objectSpread$b({}, file), uploadedFile);
|
|
1172
|
+
})
|
|
1173
|
+
});
|
|
1174
|
+
} else {
|
|
1175
|
+
setValue({
|
|
1176
|
+
files: newFiles
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
case 9:
|
|
1180
|
+
case "end":
|
|
1181
|
+
return _context.stop();
|
|
1182
|
+
}
|
|
1183
|
+
}, _callee);
|
|
1184
|
+
}));
|
|
1185
|
+
return function onDropAccepted(_x) {
|
|
1186
|
+
return _ref2.apply(this, arguments);
|
|
1187
|
+
};
|
|
1188
|
+
}();
|
|
1189
|
+
var onDropRejected = function onDropRejected(fileRejections) {
|
|
1190
|
+
fileRejections.forEach(function (fileObject) {
|
|
1191
|
+
setTouched(true);
|
|
1192
|
+
setUploadError(renderErrorMessage(fileObject, maxFileSize, multiple));
|
|
1193
|
+
});
|
|
1194
|
+
};
|
|
1195
|
+
var _useDropzone = useDropzone({
|
|
1196
|
+
disabled: disabled,
|
|
1197
|
+
accept: accept,
|
|
1198
|
+
multiple: multiple,
|
|
1199
|
+
onDropAccepted: onDropAccepted,
|
|
1200
|
+
onDropRejected: onDropRejected,
|
|
1201
|
+
maxSize: convertMbToBytes(maxFileSize)
|
|
1202
|
+
}),
|
|
1203
|
+
getRootProps = _useDropzone.getRootProps,
|
|
1204
|
+
getInputProps = _useDropzone.getInputProps,
|
|
1205
|
+
isDragActive = _useDropzone.isDragActive,
|
|
1206
|
+
fileRejections = _useDropzone.fileRejections;
|
|
1207
|
+
return {
|
|
1208
|
+
files: value === null || value === void 0 ? void 0 : value.files,
|
|
1209
|
+
progress: uploadProgress,
|
|
1210
|
+
cancel: cancel,
|
|
1211
|
+
getRootProps: getRootProps,
|
|
1212
|
+
getInputProps: getInputProps,
|
|
1213
|
+
isDragActive: isDragActive,
|
|
1214
|
+
fileRejections: fileRejections
|
|
1215
|
+
};
|
|
1216
|
+
};
|
|
1217
|
+
|
|
1218
|
+
var _path;
|
|
1219
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
1220
|
+
const SvgFileUpload = props => /*#__PURE__*/React.createElement("svg", _extends({
|
|
1221
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1222
|
+
width: 48,
|
|
1223
|
+
height: 36,
|
|
1224
|
+
fill: "none"
|
|
1225
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
1226
|
+
fill: "currentColor",
|
|
1227
|
+
d: "M32 26h-6v10h-4V26h-6l8-8 8 8zm6.958-11.816C38.534 6.282 32.012 0 24 0S9.466 6.282 9.042 14.184C3.902 15.11 0 19.596 0 25c0 6.074 4.926 11 11 11h7v-4h-7c-3.86 0-7-3.14-7-7 0-5.594 4.958-7.666 8.866-7.44C12.532 9.124 17.282 4 24 4c6.906 0 11.782 5.594 11.134 13.56C38.624 17.468 44 19.062 44 25c0 3.86-3.14 7-7 7h-7v4h7c6.074 0 11-4.926 11-11 0-5.404-3.902-9.89-9.042-10.816z"
|
|
1228
|
+
})));
|
|
1229
|
+
|
|
1230
|
+
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; }
|
|
1231
|
+
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), !0).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; }
|
|
1232
|
+
var DropZone = function DropZone(_ref) {
|
|
1233
|
+
var isDragActive = _ref.isDragActive,
|
|
1234
|
+
getRootProps = _ref.getRootProps,
|
|
1235
|
+
getInputProps = _ref.getInputProps,
|
|
1236
|
+
multipleFilesAllowed = _ref.multipleFilesAllowed,
|
|
1237
|
+
_ref$hasFileSizeLimit = _ref.hasFileSizeLimit,
|
|
1238
|
+
hasFileSizeLimit = _ref$hasFileSizeLimit === void 0 ? true : _ref$hasFileSizeLimit,
|
|
1239
|
+
maxFileSize = _ref.maxFileSize,
|
|
1240
|
+
allowedFileTypes = _ref.allowedFileTypes;
|
|
1241
|
+
var _useTranslation = useTranslation(),
|
|
1242
|
+
t = _useTranslation.t;
|
|
1243
|
+
var shouldShowFileSizeLimit = hasFileSizeLimit && maxFileSize;
|
|
1244
|
+
return /*#__PURE__*/jsx("div", _objectSpread$a(_objectSpread$a({}, getRootProps({
|
|
1245
|
+
className: classnames(["neeto-form-engine-file-upload__dropzone"], {
|
|
1246
|
+
"neeto-form-engine-file-upload__dropzone--drag-active": isDragActive
|
|
1247
|
+
})
|
|
1248
|
+
})), {}, {
|
|
1249
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
1250
|
+
className: "neeto-form-engine-file-upload__dropzone-inner",
|
|
1251
|
+
"data-cy": "file-upload-body",
|
|
1252
|
+
children: [/*#__PURE__*/jsx(SvgFileUpload, {
|
|
1253
|
+
className: "neeto-form-engine-file-upload__upload-icon"
|
|
1254
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
1255
|
+
className: "neeto-form-engine-file-upload__dropzone-content",
|
|
1256
|
+
children: [/*#__PURE__*/jsxs("label", {
|
|
1257
|
+
className: "neeto-form-engine-file-upload__upload-label",
|
|
1258
|
+
htmlFor: "file-upload",
|
|
1259
|
+
children: [/*#__PURE__*/jsx(Trans, {
|
|
1260
|
+
i18nKey: "neetoForm.fileUpload.dropzone.chooseOrDragFile",
|
|
1261
|
+
components: {
|
|
1262
|
+
typography: /*#__PURE__*/jsx(Typography, {
|
|
1263
|
+
component: "span",
|
|
1264
|
+
weight: "semibold"
|
|
1265
|
+
}),
|
|
1266
|
+
span: /*#__PURE__*/jsx(Typography, {
|
|
1267
|
+
component: "span",
|
|
1268
|
+
weight: "normal"
|
|
1269
|
+
})
|
|
1270
|
+
}
|
|
1271
|
+
}), /*#__PURE__*/jsx("input", _objectSpread$a(_objectSpread$a({}, getInputProps()), {}, {
|
|
1272
|
+
"data-cy": "file-browse-button"
|
|
1273
|
+
}))]
|
|
1274
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
1275
|
+
className: "neeto-form-engine-file-upload__dropzone-helper-block",
|
|
1276
|
+
children: [!multipleFilesAllowed && /*#__PURE__*/jsx(Typography, {
|
|
1277
|
+
className: "neeto-form-engine-file-upload__dropzone-helper-text",
|
|
1278
|
+
"data-cy": "upload-only-one-file-text",
|
|
1279
|
+
style: "body3",
|
|
1280
|
+
children: t("neetoForm.fileUpload.dropzone.oneFileAllowed")
|
|
1281
|
+
}), shouldShowFileSizeLimit && /*#__PURE__*/jsx(Typography, {
|
|
1282
|
+
className: "neeto-form-engine-file-upload__dropzone-helper-text",
|
|
1283
|
+
"data-cy": "maximum-allowed-size-text",
|
|
1284
|
+
style: "body3",
|
|
1285
|
+
children: t("neetoForm.fileUpload.dropzone.maxFileSize", {
|
|
1286
|
+
size: maxFileSize,
|
|
1287
|
+
unit: t("neetoForm.fileUpload.mb")
|
|
1288
|
+
})
|
|
1289
|
+
}), allowedFileTypes && /*#__PURE__*/jsx(Typography, {
|
|
1290
|
+
className: "neeto-form-engine-file-upload__dropzone-helper-text",
|
|
1291
|
+
"data-cy": "allowed-files-types-text",
|
|
1292
|
+
style: "body3",
|
|
1293
|
+
children: t("neetoForm.fileUpload.dropzone.allowedFileTypes", {
|
|
1294
|
+
types: allowedFileTypes
|
|
1295
|
+
})
|
|
1296
|
+
})]
|
|
1297
|
+
})]
|
|
1298
|
+
})]
|
|
1299
|
+
})
|
|
1300
|
+
}));
|
|
1301
|
+
};
|
|
1302
|
+
|
|
1303
|
+
var Progress = function Progress(_ref) {
|
|
1304
|
+
var percents = _ref.percents,
|
|
1305
|
+
_ref$stroke = _ref.stroke,
|
|
1306
|
+
stroke = _ref$stroke === void 0 ? "blue" : _ref$stroke,
|
|
1307
|
+
_ref$emptyStroke = _ref.emptyStroke,
|
|
1308
|
+
emptyStroke = _ref$emptyStroke === void 0 ? stroke : _ref$emptyStroke,
|
|
1309
|
+
_ref$emptyStrokeOpaci = _ref.emptyStrokeOpacity,
|
|
1310
|
+
emptyStrokeOpacity = _ref$emptyStrokeOpaci === void 0 ? 0.25 : _ref$emptyStrokeOpaci,
|
|
1311
|
+
_ref$duration = _ref.duration,
|
|
1312
|
+
duration = _ref$duration === void 0 ? 0.5 : _ref$duration,
|
|
1313
|
+
_ref$delay = _ref.delay,
|
|
1314
|
+
delay = _ref$delay === void 0 ? 0 : _ref$delay,
|
|
1315
|
+
_ref$size = _ref.size,
|
|
1316
|
+
size = _ref$size === void 0 ? 100 : _ref$size,
|
|
1317
|
+
_ref$strokeWidth = _ref.strokeWidth,
|
|
1318
|
+
strokeWidth = _ref$strokeWidth === void 0 ? 12 : _ref$strokeWidth;
|
|
1319
|
+
var radius = 45;
|
|
1320
|
+
var circumference = Math.ceil(2 * Math.PI * radius);
|
|
1321
|
+
var fillPercents = Math.abs(Math.ceil(circumference / 100 * (percents - 100)));
|
|
1322
|
+
var transition = {
|
|
1323
|
+
duration: duration,
|
|
1324
|
+
delay: delay
|
|
1325
|
+
};
|
|
1326
|
+
var variants = {
|
|
1327
|
+
hidden: {
|
|
1328
|
+
strokeDashoffset: circumference,
|
|
1329
|
+
transition: transition
|
|
1330
|
+
},
|
|
1331
|
+
show: {
|
|
1332
|
+
strokeDashoffset: fillPercents,
|
|
1333
|
+
transition: transition
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
return /*#__PURE__*/jsx("div", {
|
|
1337
|
+
className: "neeto-form-engine-progress__circle",
|
|
1338
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
1339
|
+
className: "neeto-form-engine-progress__circle-wrapper",
|
|
1340
|
+
style: {
|
|
1341
|
+
height: size
|
|
1342
|
+
},
|
|
1343
|
+
children: [/*#__PURE__*/jsx("svg", {
|
|
1344
|
+
height: size,
|
|
1345
|
+
version: "1.1",
|
|
1346
|
+
viewBox: "0 0 100 100",
|
|
1347
|
+
width: size,
|
|
1348
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1349
|
+
children: /*#__PURE__*/jsx("circle", {
|
|
1350
|
+
strokeWidth: strokeWidth,
|
|
1351
|
+
className: "circle",
|
|
1352
|
+
cx: "50",
|
|
1353
|
+
cy: "50",
|
|
1354
|
+
fill: "transparent",
|
|
1355
|
+
r: radius,
|
|
1356
|
+
stroke: emptyStroke,
|
|
1357
|
+
strokeOpacity: emptyStrokeOpacity
|
|
1358
|
+
})
|
|
1359
|
+
}), /*#__PURE__*/jsx("svg", {
|
|
1360
|
+
height: size,
|
|
1361
|
+
viewBox: "0 0 100 100",
|
|
1362
|
+
width: size,
|
|
1363
|
+
style: {
|
|
1364
|
+
position: "absolute",
|
|
1365
|
+
transform: "rotate(-90deg)",
|
|
1366
|
+
overflow: "visible",
|
|
1367
|
+
top: 0
|
|
1368
|
+
},
|
|
1369
|
+
children: /*#__PURE__*/jsx(motion.circle, {
|
|
1370
|
+
stroke: stroke,
|
|
1371
|
+
strokeWidth: strokeWidth,
|
|
1372
|
+
variants: variants,
|
|
1373
|
+
animate: "show",
|
|
1374
|
+
cx: "50",
|
|
1375
|
+
cy: "50",
|
|
1376
|
+
fill: "transparent",
|
|
1377
|
+
initial: "hidden",
|
|
1378
|
+
r: radius,
|
|
1379
|
+
strokeDasharray: circumference,
|
|
1380
|
+
strokeDashoffset: fillPercents
|
|
1381
|
+
})
|
|
1382
|
+
})]
|
|
1383
|
+
})
|
|
1384
|
+
});
|
|
1385
|
+
};
|
|
1386
|
+
|
|
1387
|
+
var FILE_MIME_TYPES = {
|
|
1388
|
+
pdf: ["application/pdf"],
|
|
1389
|
+
doc: ["application/msword", "application/wps-writer"],
|
|
1390
|
+
docx: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
|
|
1391
|
+
xls: ["application/vnd.ms-excel"],
|
|
1392
|
+
xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
|
|
1393
|
+
csv: ["text/csv"],
|
|
1394
|
+
txt: ["text/plain"],
|
|
1395
|
+
rtf: ["application/rtf", "text/rtf"],
|
|
1396
|
+
html: ["text/html"],
|
|
1397
|
+
htm: ["text/html"],
|
|
1398
|
+
md: ["text/markdown", "text/x-markdown"],
|
|
1399
|
+
zip: ["application/zip"],
|
|
1400
|
+
mp3: ["audio/mpeg"],
|
|
1401
|
+
wma: ["audio/x-ms-wma", "video/x-ms-asf"],
|
|
1402
|
+
mp4: ["video/mp4"],
|
|
1403
|
+
webm: ["video/webm"],
|
|
1404
|
+
mpg: ["video/mpeg"],
|
|
1405
|
+
mpeg: ["video/mpeg"],
|
|
1406
|
+
flv: ["video/x-flv"],
|
|
1407
|
+
avi: ["video/x-msvideo"],
|
|
1408
|
+
jpg: ["image/jpeg"],
|
|
1409
|
+
jpeg: ["image/jpeg"],
|
|
1410
|
+
png: ["image/png"],
|
|
1411
|
+
gif: ["image/gif"]
|
|
1412
|
+
};
|
|
1413
|
+
|
|
1414
|
+
var getAcceptedFileTypes = function getAcceptedFileTypes(allowedFileTypes) {
|
|
1415
|
+
var accepted = {};
|
|
1416
|
+
allowedFileTypes.split(", ").forEach(function (type) {
|
|
1417
|
+
var mimeTypes = FILE_MIME_TYPES[type];
|
|
1418
|
+
var extension = ".".concat(type);
|
|
1419
|
+
if (isNotPresent(type) || isNotPresent(mimeTypes)) return;
|
|
1420
|
+
mimeTypes.forEach(function (mimeType) {
|
|
1421
|
+
if (accepted[mimeType]) accepted[mimeType].push(extension);else accepted[mimeType] = [extension];
|
|
1422
|
+
});
|
|
1423
|
+
});
|
|
1424
|
+
return accepted;
|
|
1425
|
+
};
|
|
1426
|
+
var convertBytesToMb = function convertBytesToMb(bytes) {
|
|
1427
|
+
return (bytes / (1024 * 1024)).toFixed(2);
|
|
1428
|
+
};
|
|
1429
|
+
|
|
1430
|
+
var FilePreview = withT(function (_ref) {
|
|
1431
|
+
var t = _ref.t,
|
|
1432
|
+
file = _ref.file,
|
|
1433
|
+
isUploading = _ref.isUploading,
|
|
1434
|
+
cancel = _ref.cancel,
|
|
1435
|
+
progress = _ref.progress;
|
|
1436
|
+
return /*#__PURE__*/jsxs("li", {
|
|
1437
|
+
className: "neeto-form-engine-file-upload__uploaded-list-item",
|
|
1438
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
1439
|
+
className: "neeto-form-engine-file-upload__file-preview",
|
|
1440
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
1441
|
+
className: classnames("p-0", {
|
|
1442
|
+
invisible: isUploading
|
|
1443
|
+
}),
|
|
1444
|
+
href: file.url,
|
|
1445
|
+
icon: FileGeneric,
|
|
1446
|
+
iconSize: 24,
|
|
1447
|
+
rel: "noreferrer",
|
|
1448
|
+
size: "large",
|
|
1449
|
+
style: "text",
|
|
1450
|
+
target: "_blank"
|
|
1451
|
+
}), isUploading && /*#__PURE__*/jsx("div", {
|
|
1452
|
+
className: "neeto-form-engine-progress",
|
|
1453
|
+
children: /*#__PURE__*/jsx(Progress, {
|
|
1454
|
+
percents: progress || 0,
|
|
1455
|
+
size: 20
|
|
1456
|
+
})
|
|
1457
|
+
})]
|
|
1458
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
1459
|
+
className: "flex min-w-0 grow flex-col break-words",
|
|
1460
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
1461
|
+
className: "neeto-form-engine-file-upload__file-info-name",
|
|
1462
|
+
style: "body2",
|
|
1463
|
+
children: file.name
|
|
1464
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
1465
|
+
className: "neeto-form-engine-file-upload__file-info-size",
|
|
1466
|
+
style: "body3",
|
|
1467
|
+
children: file.size ? t("neetoForm.fileUpload.fileSizeInMb", {
|
|
1468
|
+
fileSize: convertBytesToMb(file.size)
|
|
1469
|
+
}) : ""
|
|
1470
|
+
})]
|
|
1471
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
1472
|
+
className: "neeto-form-engine-file-upload__actions",
|
|
1473
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
1474
|
+
className: classnames("neeto-form-engine-file-upload__success-indicator", {
|
|
1475
|
+
"neeto-form-engine-file-upload__success-indicator--active": file.url
|
|
1476
|
+
}),
|
|
1477
|
+
children: file.url && /*#__PURE__*/jsx(Check, {})
|
|
1478
|
+
}), /*#__PURE__*/jsx("button", {
|
|
1479
|
+
className: "neeto-form-engine-file-upload__button--red neeto-form-engine-file-upload__remove-button",
|
|
1480
|
+
type: "button",
|
|
1481
|
+
onClick: cancel,
|
|
1482
|
+
children: /*#__PURE__*/jsx(Close, {})
|
|
1483
|
+
})]
|
|
1484
|
+
})]
|
|
1485
|
+
}, file.url);
|
|
1486
|
+
});
|
|
1487
|
+
|
|
1488
|
+
var FileUploadField = function FileUploadField(_ref) {
|
|
1489
|
+
var question = _ref.question,
|
|
1490
|
+
_ref$preview = _ref.preview,
|
|
1491
|
+
preview = _ref$preview === void 0 ? false : _ref$preview,
|
|
1492
|
+
customValidator = _ref.customValidator;
|
|
1493
|
+
var name = question.id,
|
|
1494
|
+
kind = question.kind,
|
|
1495
|
+
isRequired = question.isRequired,
|
|
1496
|
+
nodeId = question.nodeId,
|
|
1497
|
+
allowedFileTypes = question.allowedFileTypes,
|
|
1498
|
+
multipleFilesAllowed = question.multipleFilesAllowed,
|
|
1499
|
+
maxFileSize = question.maxFileSize;
|
|
1500
|
+
var label = fieldWithFallback(question, "label");
|
|
1501
|
+
var _useField = useField({
|
|
1502
|
+
name: name || nodeId,
|
|
1503
|
+
validate: validateFieldValue({
|
|
1504
|
+
kind: kind,
|
|
1505
|
+
label: label,
|
|
1506
|
+
isRequired: isRequired,
|
|
1507
|
+
customValidator: customValidator,
|
|
1508
|
+
multipleFilesAllowed: multipleFilesAllowed
|
|
1509
|
+
})
|
|
1510
|
+
}),
|
|
1511
|
+
_useField2 = _slicedToArray(_useField, 2);
|
|
1512
|
+
_useField2[0];
|
|
1513
|
+
var _useField2$ = _useField2[1],
|
|
1514
|
+
touched = _useField2$.touched,
|
|
1515
|
+
error = _useField2$.error;
|
|
1516
|
+
var _useFileUpload = useFileUpload({
|
|
1517
|
+
disabled: preview,
|
|
1518
|
+
accept: getAcceptedFileTypes(allowedFileTypes),
|
|
1519
|
+
multiple: multipleFilesAllowed,
|
|
1520
|
+
name: name || nodeId,
|
|
1521
|
+
maxFileSize: maxFileSize
|
|
1522
|
+
}),
|
|
1523
|
+
files = _useFileUpload.files,
|
|
1524
|
+
progress = _useFileUpload.progress,
|
|
1525
|
+
cancel = _useFileUpload.cancel,
|
|
1526
|
+
getRootProps = _useFileUpload.getRootProps,
|
|
1527
|
+
getInputProps = _useFileUpload.getInputProps,
|
|
1528
|
+
isDragActive = _useFileUpload.isDragActive,
|
|
1529
|
+
fileRejections = _useFileUpload.fileRejections;
|
|
1530
|
+
var shouldShowError = touched && error && isEmpty(fileRejections);
|
|
1531
|
+
var maxFileSizeInBytes = convertMbToBytes(maxFileSize);
|
|
1532
|
+
var isUploadingFile = function isUploadingFile(file) {
|
|
1533
|
+
return isNotNil(progress[file.name]) && (progress[file.name] !== 100 || !file.url);
|
|
1534
|
+
};
|
|
1535
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1536
|
+
className: "neeto-form-engine-input__wrapper",
|
|
1537
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
1538
|
+
className: "neeto-form-engine-input__label-wrapper",
|
|
1539
|
+
children: /*#__PURE__*/jsx(Label, {
|
|
1540
|
+
className: "neeto-form-engine-label",
|
|
1541
|
+
required: isRequired,
|
|
1542
|
+
children: label
|
|
1543
|
+
})
|
|
1544
|
+
}), /*#__PURE__*/jsx(DropZone, {
|
|
1545
|
+
allowedFileTypes: allowedFileTypes,
|
|
1546
|
+
getInputProps: getInputProps,
|
|
1547
|
+
getRootProps: getRootProps,
|
|
1548
|
+
isDragActive: isDragActive,
|
|
1549
|
+
maxFileSize: maxFileSize,
|
|
1550
|
+
multipleFilesAllowed: multipleFilesAllowed
|
|
1551
|
+
}), isNotEmpty(files) && /*#__PURE__*/jsx("ul", {
|
|
1552
|
+
className: "neeto-form-engine-file-upload__uploaded-list",
|
|
1553
|
+
children: files === null || files === void 0 ? void 0 : files.map(function (file, idx) {
|
|
1554
|
+
return /*#__PURE__*/createElement(FilePreview, {
|
|
1555
|
+
file: file,
|
|
1556
|
+
cancel: cancel(idx),
|
|
1557
|
+
isUploading: isUploadingFile(file),
|
|
1558
|
+
key: idx,
|
|
1559
|
+
progress: progress[file.name]
|
|
1560
|
+
});
|
|
1561
|
+
})
|
|
1562
|
+
}), isNotEmpty(fileRejections) && fileRejections.map(function (file, index) {
|
|
1563
|
+
return /*#__PURE__*/jsx(Typography, {
|
|
1564
|
+
className: "neeto-ui-text-error-800 neeto-ui-bg-pastel-red neeto-ui-rounded-sm mt-2 inline-block w-full p-1 text-sm",
|
|
1565
|
+
children: renderErrorMessage(file, maxFileSizeInBytes, false)
|
|
1566
|
+
}, index);
|
|
1567
|
+
}), shouldShowError && /*#__PURE__*/jsx(Typography, {
|
|
1568
|
+
className: "neeto-ui-text-error-800 neeto-ui-bg-pastel-red neeto-ui-rounded-sm mt-2 inline-block w-full p-1 text-sm",
|
|
1569
|
+
children: error
|
|
1570
|
+
})]
|
|
1571
|
+
});
|
|
1572
|
+
};
|
|
1573
|
+
|
|
1574
|
+
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; }
|
|
1575
|
+
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), !0).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; }
|
|
1576
|
+
var NameField = function NameField(_ref) {
|
|
1577
|
+
var question = _ref.question,
|
|
1578
|
+
customValidator = _ref.customValidator,
|
|
1579
|
+
autoComplete = _ref.autoComplete;
|
|
1580
|
+
var name = question.id,
|
|
1581
|
+
kind = question.kind,
|
|
1582
|
+
isRequired = question.isRequired,
|
|
1583
|
+
nodeId = question.nodeId;
|
|
1584
|
+
var label = fieldWithFallback(question, "label");
|
|
1585
|
+
var _QUESTION_KIND$kind$t = QUESTION_KIND[kind.toUpperCase()].type,
|
|
1586
|
+
type = _QUESTION_KIND$kind$t === void 0 ? "text" : _QUESTION_KIND$kind$t;
|
|
1587
|
+
var _useField = useField({
|
|
1588
|
+
name: name || nodeId,
|
|
1589
|
+
validate: validateFieldValue({
|
|
1590
|
+
kind: kind,
|
|
1591
|
+
label: label,
|
|
1592
|
+
isRequired: isRequired,
|
|
1593
|
+
customValidator: customValidator
|
|
1594
|
+
})
|
|
1595
|
+
}),
|
|
1596
|
+
_useField2 = _slicedToArray(_useField, 3),
|
|
1597
|
+
field = _useField2[0],
|
|
1598
|
+
_useField2$ = _useField2[1],
|
|
1599
|
+
touched = _useField2$.touched,
|
|
1600
|
+
error = _useField2$.error,
|
|
1601
|
+
_useField2$2 = _useField2[2],
|
|
1602
|
+
setValue = _useField2$2.setValue,
|
|
1603
|
+
setTouched = _useField2$2.setTouched;
|
|
1604
|
+
var handleFieldChange = withEventTargetValue(setValue);
|
|
1605
|
+
return /*#__PURE__*/jsx(Input, _objectSpread$9(_objectSpread$9({}, _objectSpread$9(_objectSpread$9({
|
|
1606
|
+
type: type
|
|
1607
|
+
}, field), {}, {
|
|
1608
|
+
autoComplete: autoComplete,
|
|
1609
|
+
label: label
|
|
1610
|
+
})), {}, {
|
|
1611
|
+
error: touched ? error : "",
|
|
1612
|
+
name: kind,
|
|
1613
|
+
placeholder: fieldWithFallback(question, "placeholder"),
|
|
1614
|
+
required: isRequired,
|
|
1615
|
+
onBlur: function onBlur() {
|
|
1616
|
+
return setTouched(true);
|
|
1617
|
+
},
|
|
1618
|
+
onChange: handleFieldChange
|
|
1619
|
+
}));
|
|
1620
|
+
};
|
|
1621
|
+
|
|
1622
|
+
var Choices = function Choices(_ref) {
|
|
1623
|
+
var label = _ref.label,
|
|
1624
|
+
options = _ref.options,
|
|
1625
|
+
type = _ref.type,
|
|
1626
|
+
name = _ref.name,
|
|
1627
|
+
value = _ref.value,
|
|
1628
|
+
onChange = _ref.onChange,
|
|
1629
|
+
error = _ref.error;
|
|
1630
|
+
var isCheckBox = type === "checkbox";
|
|
1631
|
+
var ChoiceWrapper = isCheckBox ? "div" : Radio;
|
|
1632
|
+
var Component = isCheckBox ? Checkbox : Radio.Item;
|
|
1633
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1634
|
+
className: "neeto-form-engine-choices__wrapper",
|
|
1635
|
+
"data-cy": "".concat(hyphenate(label), "-select-container-wrapper"),
|
|
1636
|
+
children: [/*#__PURE__*/jsx("label", {
|
|
1637
|
+
className: "neeto-form-engine-label",
|
|
1638
|
+
children: label
|
|
1639
|
+
}), /*#__PURE__*/jsx(ChoiceWrapper, {
|
|
1640
|
+
className: "neeto-form-engine-choices",
|
|
1641
|
+
stacked: !isCheckBox,
|
|
1642
|
+
children: options.map(function (option, index) {
|
|
1643
|
+
var _value$index;
|
|
1644
|
+
return /*#__PURE__*/jsx("label", {
|
|
1645
|
+
htmlFor: option.id,
|
|
1646
|
+
className: classnames("neeto-form-engine-choice", {
|
|
1647
|
+
active: false
|
|
1648
|
+
}),
|
|
1649
|
+
children: /*#__PURE__*/jsx(Component, {
|
|
1650
|
+
onChange: onChange,
|
|
1651
|
+
type: type,
|
|
1652
|
+
id: option.id,
|
|
1653
|
+
label: option.label,
|
|
1654
|
+
name: isCheckBox ? "".concat(name, ".").concat(index) : name,
|
|
1655
|
+
value: option.id,
|
|
1656
|
+
checked: isCheckBox ? (_value$index = value === null || value === void 0 ? void 0 : value[index]) !== null && _value$index !== void 0 ? _value$index : false : value === option.id
|
|
1657
|
+
})
|
|
1658
|
+
}, option.id);
|
|
1659
|
+
})
|
|
1660
|
+
}), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
|
|
1661
|
+
className: "neeto-form-engine-input__error",
|
|
1662
|
+
"data-cy": "neeto-form-engine-".concat(type, "-error"),
|
|
1663
|
+
children: error
|
|
1664
|
+
})]
|
|
1665
|
+
});
|
|
1666
|
+
};
|
|
1667
|
+
var Choices$1 = /*#__PURE__*/memo(Choices);
|
|
1668
|
+
|
|
1669
|
+
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; }
|
|
1670
|
+
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), !0).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; }
|
|
1671
|
+
var OptionsField = function OptionsField(_ref) {
|
|
1672
|
+
var question = _ref.question,
|
|
1673
|
+
customValidator = _ref.customValidator;
|
|
1674
|
+
var _useFormikContext = useFormikContext(),
|
|
1675
|
+
setFieldTouched = _useFormikContext.setFieldTouched,
|
|
1676
|
+
setFieldValue = _useFormikContext.setFieldValue,
|
|
1677
|
+
validateField = _useFormikContext.validateField;
|
|
1678
|
+
var name = question.id,
|
|
1679
|
+
kind = question.kind,
|
|
1680
|
+
isRequired = question.isRequired,
|
|
1681
|
+
_question$optionsAttr = question.optionsAttributes,
|
|
1682
|
+
options = _question$optionsAttr === void 0 ? [] : _question$optionsAttr;
|
|
1683
|
+
var isDropdown = kind === QUESTION_KIND.DROPDOWN.value;
|
|
1684
|
+
var label = fieldWithFallback(question, "label");
|
|
1685
|
+
var Component = isDropdown ? Select : Choices$1;
|
|
1686
|
+
var transformedOptions = isDropdown ? options.map(function (option) {
|
|
1687
|
+
return {
|
|
1688
|
+
label: fieldWithFallback(option, "label"),
|
|
1689
|
+
displayOrder: option.displayOrder,
|
|
1690
|
+
value: option.id
|
|
1691
|
+
};
|
|
1692
|
+
}) : options.map(function (option) {
|
|
1693
|
+
return _objectSpread$8(_objectSpread$8({}, option), {}, {
|
|
1694
|
+
label: fieldWithFallback(option, "label")
|
|
1695
|
+
});
|
|
1696
|
+
});
|
|
1697
|
+
var handleSelect = function handleSelect(option) {
|
|
1698
|
+
setFieldValue(name, option.value, false);
|
|
1699
|
+
setFieldTouched(name, true, false);
|
|
1700
|
+
setTimeout(function () {
|
|
1701
|
+
return validateField(name);
|
|
1702
|
+
});
|
|
1703
|
+
};
|
|
1704
|
+
return /*#__PURE__*/jsx(Field, {
|
|
1705
|
+
name: name,
|
|
1706
|
+
validate: validateFieldValue({
|
|
1707
|
+
kind: kind,
|
|
1708
|
+
label: label,
|
|
1709
|
+
isRequired: isRequired,
|
|
1710
|
+
customValidator: customValidator
|
|
1711
|
+
}),
|
|
1712
|
+
children: function children(_ref2) {
|
|
1713
|
+
var meta = _ref2.meta,
|
|
1714
|
+
field = _ref2.field;
|
|
1715
|
+
var onChange = field.onChange,
|
|
1716
|
+
value = field.value;
|
|
1717
|
+
return /*#__PURE__*/jsx(Component, {
|
|
1718
|
+
isRequired: isRequired,
|
|
1719
|
+
name: name,
|
|
1720
|
+
error: getError(meta),
|
|
1721
|
+
label: getLabel(label, isRequired),
|
|
1722
|
+
options: transformedOptions,
|
|
1723
|
+
type: kind,
|
|
1724
|
+
value: isDropdown ? findBy({
|
|
1725
|
+
value: value
|
|
1726
|
+
}, transformedOptions) || null : value,
|
|
1727
|
+
onChange: isDropdown ? handleSelect : onChange
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1730
|
+
});
|
|
1731
|
+
};
|
|
1732
|
+
|
|
1733
|
+
var PhoneNumberField = function PhoneNumberField(_ref) {
|
|
1734
|
+
var _getPhoneData;
|
|
1735
|
+
var question = _ref.question,
|
|
1736
|
+
autoComplete = _ref.autoComplete;
|
|
1737
|
+
var name = question.id,
|
|
1738
|
+
kind = question.kind,
|
|
1739
|
+
isRequired = question.isRequired,
|
|
1740
|
+
nodeId = question.nodeId;
|
|
1741
|
+
var label = fieldWithFallback(question, "label");
|
|
1742
|
+
var _useField = useField({
|
|
1743
|
+
name: name || nodeId,
|
|
1744
|
+
validate: validateFieldValue({
|
|
1745
|
+
kind: kind,
|
|
1746
|
+
label: label,
|
|
1747
|
+
isRequired: isRequired
|
|
1748
|
+
})
|
|
1749
|
+
}),
|
|
1750
|
+
_useField2 = _slicedToArray(_useField, 3),
|
|
1751
|
+
value = _useField2[0].value,
|
|
1752
|
+
_useField2$ = _useField2[1],
|
|
1753
|
+
touched = _useField2$.touched,
|
|
1754
|
+
error = _useField2$.error,
|
|
1755
|
+
_useField2$2 = _useField2[2],
|
|
1756
|
+
setValue = _useField2$2.setValue,
|
|
1757
|
+
setTouched = _useField2$2.setTouched;
|
|
1758
|
+
return /*#__PURE__*/jsx(PhoneNumberInput, {
|
|
1759
|
+
autoComplete: autoComplete,
|
|
1760
|
+
label: label,
|
|
1761
|
+
value: value,
|
|
1762
|
+
className: "neeto-form-engine-input__wrapper items-stretch",
|
|
1763
|
+
error: touched ? error : "",
|
|
1764
|
+
initialCountryCode: (_getPhoneData = getPhoneData(value)) === null || _getPhoneData === void 0 ? void 0 : _getPhoneData.country,
|
|
1765
|
+
placeholder: fieldWithFallback(question, "placeholder"),
|
|
1766
|
+
required: isRequired,
|
|
1767
|
+
onBlur: function onBlur() {
|
|
1768
|
+
return setTouched(true);
|
|
1769
|
+
},
|
|
1770
|
+
onChange: setValue
|
|
1771
|
+
});
|
|
1772
|
+
};
|
|
1773
|
+
|
|
1774
|
+
var _excluded$2 = ["name", "label", "error", "lowestRatingLabel", "averageRatingLabel", "highestRatingLabel", "value"];
|
|
1775
|
+
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; }
|
|
1776
|
+
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), !0).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; }
|
|
1777
|
+
var Rating = function Rating(_ref) {
|
|
1778
|
+
var name = _ref.name,
|
|
1779
|
+
label = _ref.label,
|
|
1780
|
+
error = _ref.error,
|
|
1781
|
+
lowestRatingLabel = _ref.lowestRatingLabel,
|
|
1782
|
+
averageRatingLabel = _ref.averageRatingLabel,
|
|
1783
|
+
highestRatingLabel = _ref.highestRatingLabel,
|
|
1784
|
+
value = _ref.value,
|
|
1785
|
+
other = _objectWithoutProperties(_ref, _excluded$2);
|
|
1786
|
+
var handleClick = function handleClick(e) {
|
|
1787
|
+
return e.currentTarget.nextElementSibling.click();
|
|
1788
|
+
};
|
|
1789
|
+
var render = function render() {
|
|
1790
|
+
var labels = [highestRatingLabel, averageRatingLabel, lowestRatingLabel];
|
|
1791
|
+
return RATING_OPTIONS.map(function (_ref2, index) {
|
|
1792
|
+
var Icon = _ref2.icon,
|
|
1793
|
+
modifier = _ref2.modifier,
|
|
1794
|
+
rating = _ref2.value;
|
|
1795
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
1796
|
+
children: [/*#__PURE__*/jsxs("button", {
|
|
1797
|
+
type: "button",
|
|
1798
|
+
className: classnames("neeto-form-engine-rating__item neeto-form-engine-rating__item--".concat(modifier), {
|
|
1799
|
+
active: rating === value
|
|
1800
|
+
}),
|
|
1801
|
+
onClick: handleClick,
|
|
1802
|
+
children: [/*#__PURE__*/jsx(Icon, {}), /*#__PURE__*/jsx("label", {
|
|
1803
|
+
className: "neeto-form-engine-label",
|
|
1804
|
+
children: labels[index]
|
|
1805
|
+
})]
|
|
1806
|
+
}), /*#__PURE__*/jsx("input", _objectSpread$7({
|
|
1807
|
+
name: name,
|
|
1808
|
+
hidden: true,
|
|
1809
|
+
checked: rating === value,
|
|
1810
|
+
type: "radio",
|
|
1811
|
+
value: rating
|
|
1812
|
+
}, other))]
|
|
1813
|
+
}, rating);
|
|
1814
|
+
});
|
|
1815
|
+
};
|
|
1816
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1817
|
+
className: "neeto-form-engine-rating",
|
|
1818
|
+
children: [/*#__PURE__*/jsx("label", {
|
|
1819
|
+
className: "neeto-form-engine-label",
|
|
1820
|
+
children: label
|
|
1821
|
+
}), /*#__PURE__*/jsx("div", {
|
|
1822
|
+
className: "neeto-form-engine-rating__row",
|
|
1823
|
+
children: render()
|
|
1824
|
+
}), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
|
|
1825
|
+
className: "neeto-form-engine-input__error",
|
|
1826
|
+
"data-cy": "neeto-form-engine-rating-error",
|
|
1827
|
+
children: error
|
|
1828
|
+
})]
|
|
1829
|
+
});
|
|
1830
|
+
};
|
|
1831
|
+
var Rating$1 = /*#__PURE__*/memo(Rating);
|
|
1832
|
+
|
|
1833
|
+
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; }
|
|
1834
|
+
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), !0).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; }
|
|
1835
|
+
var RatingField = function RatingField(_ref) {
|
|
1836
|
+
var question = _ref.question,
|
|
1837
|
+
customValidator = _ref.customValidator;
|
|
1838
|
+
var name = question.id,
|
|
1839
|
+
kind = question.kind,
|
|
1840
|
+
isRequired = question.isRequired;
|
|
1841
|
+
var label = fieldWithFallback(question, "label");
|
|
1842
|
+
return /*#__PURE__*/jsx(Field, {
|
|
1843
|
+
name: name,
|
|
1844
|
+
validate: validateFieldValue({
|
|
1845
|
+
kind: kind,
|
|
1846
|
+
label: label,
|
|
1847
|
+
isRequired: isRequired,
|
|
1848
|
+
customValidator: customValidator
|
|
1849
|
+
}),
|
|
1850
|
+
children: function children(_ref2) {
|
|
1851
|
+
var meta = _ref2.meta,
|
|
1852
|
+
field = _ref2.field;
|
|
1853
|
+
return /*#__PURE__*/jsx(Rating$1, _objectSpread$6(_objectSpread$6({}, field), {}, {
|
|
1854
|
+
error: meta.touched ? meta.error : "",
|
|
1855
|
+
label: getLabel(label, isRequired),
|
|
1856
|
+
averageRatingLabel: fieldWithFallback(question, "averageRatingLabel") || RATING_VALUES.AVERAGE.label,
|
|
1857
|
+
highestRatingLabel: fieldWithFallback(question, "highestRatingLabel") || RATING_VALUES.GOOD.label,
|
|
1858
|
+
lowestRatingLabel: fieldWithFallback(question, "lowestRatingLabel") || RATING_VALUES.BAD.label
|
|
1859
|
+
}));
|
|
1860
|
+
}
|
|
1861
|
+
});
|
|
1862
|
+
};
|
|
1863
|
+
|
|
1864
|
+
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; }
|
|
1865
|
+
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), !0).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; }
|
|
1866
|
+
var RichTextEditor = function RichTextEditor(_ref) {
|
|
1867
|
+
var editorRef = _ref.editorRef,
|
|
1868
|
+
question = _ref.question,
|
|
1869
|
+
_ref$editorProps = _ref.editorProps,
|
|
1870
|
+
editorProps = _ref$editorProps === void 0 ? {} : _ref$editorProps;
|
|
1871
|
+
var _useFormikContext = useFormikContext(),
|
|
1872
|
+
errors = _useFormikContext.errors,
|
|
1873
|
+
touched = _useFormikContext.touched;
|
|
1874
|
+
var name = question.id,
|
|
1875
|
+
kind = question.kind,
|
|
1876
|
+
isRequired = question.isRequired,
|
|
1877
|
+
nodeId = question.nodeId;
|
|
1878
|
+
var label = fieldWithFallback(question, "label");
|
|
1879
|
+
var debouncedPlaceholder = useDebounce(fieldWithFallback(question, "placeholder"), 300);
|
|
1880
|
+
var propsToCompare = ["debouncedPlaceholder", "error", "touched"];
|
|
1881
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1882
|
+
className: "neeto-form-engine-input__wrapper",
|
|
1883
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
1884
|
+
className: "neeto-form-engine-input__label-wrapper",
|
|
1885
|
+
children: label && /*#__PURE__*/jsx("label", {
|
|
1886
|
+
className: "neeto-form-engine-label",
|
|
1887
|
+
children: getLabel(label, isRequired)
|
|
1888
|
+
})
|
|
1889
|
+
}), /*#__PURE__*/jsx(FastField, {
|
|
1890
|
+
debouncedPlaceholder: debouncedPlaceholder,
|
|
1891
|
+
error: errors[name],
|
|
1892
|
+
name: name || nodeId,
|
|
1893
|
+
shouldUpdate: isPropsUnequal(propsToCompare),
|
|
1894
|
+
touched: touched[name],
|
|
1895
|
+
validate: validateFieldValue({
|
|
1896
|
+
kind: kind,
|
|
1897
|
+
label: label,
|
|
1898
|
+
isRequired: isRequired
|
|
1899
|
+
}),
|
|
1900
|
+
children: function children(_ref2) {
|
|
1901
|
+
var field = _ref2.field,
|
|
1902
|
+
form = _ref2.form,
|
|
1903
|
+
meta = _ref2.meta;
|
|
1904
|
+
return /*#__PURE__*/jsx(NeetoEditor, _objectSpread$5({
|
|
1905
|
+
className: "neeto-form-engine-rich-text-input",
|
|
1906
|
+
error: meta.touched ? meta.error : "",
|
|
1907
|
+
initialValue: field.value,
|
|
1908
|
+
placeholder: debouncedPlaceholder,
|
|
1909
|
+
ref: editorRef,
|
|
1910
|
+
addons: ["attachments", "block-quote", "code-block", "image-upload"],
|
|
1911
|
+
onBlur: function onBlur() {
|
|
1912
|
+
return form.setFieldTouched(name, true);
|
|
1913
|
+
},
|
|
1914
|
+
onChange: function onChange(value) {
|
|
1915
|
+
return form.setFieldValue(name, value);
|
|
1916
|
+
}
|
|
1917
|
+
}, editorProps), debouncedPlaceholder);
|
|
1918
|
+
}
|
|
1919
|
+
})]
|
|
1920
|
+
});
|
|
1921
|
+
};
|
|
1922
|
+
|
|
1923
|
+
var _excluded$1 = ["value", "iconType", "label", "rating"];
|
|
1924
|
+
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; }
|
|
1925
|
+
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), !0).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; }
|
|
1926
|
+
var RatingButton = function RatingButton(_ref) {
|
|
1927
|
+
var _ref$value = _ref.value,
|
|
1928
|
+
value = _ref$value === void 0 ? 0 : _ref$value,
|
|
1929
|
+
iconType = _ref.iconType,
|
|
1930
|
+
label = _ref.label,
|
|
1931
|
+
rating = _ref.rating,
|
|
1932
|
+
otherProps = _objectWithoutProperties(_ref, _excluded$1);
|
|
1933
|
+
var handleClick = function handleClick(e) {
|
|
1934
|
+
return e.currentTarget.nextElementSibling.click();
|
|
1935
|
+
};
|
|
1936
|
+
var Icon = ICONS_MAP[iconType];
|
|
1937
|
+
var selectedRating = getSelectedRating(value);
|
|
1938
|
+
return /*#__PURE__*/jsxs(Fragment$1, {
|
|
1939
|
+
children: [/*#__PURE__*/jsxs("button", {
|
|
1940
|
+
className: classnames({
|
|
1941
|
+
active: rating === value
|
|
1942
|
+
}),
|
|
1943
|
+
type: "button",
|
|
1944
|
+
onClick: handleClick,
|
|
1945
|
+
children: [/*#__PURE__*/jsx(Icon, {
|
|
1946
|
+
size: 24,
|
|
1947
|
+
className: classnames("neeto-form-engine-star-rating__icon", {
|
|
1948
|
+
"neeto-form-engine-star-rating__icon--active": rating <= selectedRating
|
|
1949
|
+
})
|
|
1950
|
+
}), /*#__PURE__*/jsx("label", {
|
|
1951
|
+
className: "neeto-form-engine-label",
|
|
1952
|
+
children: label
|
|
1953
|
+
})]
|
|
1954
|
+
}), /*#__PURE__*/jsx("input", _objectSpread$4({
|
|
1955
|
+
hidden: true,
|
|
1956
|
+
checked: equals(rating, value),
|
|
1957
|
+
type: "radio",
|
|
1958
|
+
value: rating
|
|
1959
|
+
}, otherProps))]
|
|
1960
|
+
});
|
|
1961
|
+
};
|
|
1962
|
+
var RatingButton$1 = /*#__PURE__*/memo(RatingButton);
|
|
1963
|
+
|
|
1964
|
+
var _excluded = ["label", "minValue", "maxValue", "error"];
|
|
1965
|
+
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; }
|
|
1966
|
+
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), !0).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; }
|
|
1967
|
+
var StarRating = function StarRating(_ref) {
|
|
1968
|
+
var label = _ref.label,
|
|
1969
|
+
minValue = _ref.minValue,
|
|
1970
|
+
maxValue = _ref.maxValue,
|
|
1971
|
+
error = _ref.error,
|
|
1972
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
1973
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1974
|
+
className: "neeto-form-engine-input__wrapper neeto-form-engine-star-rating",
|
|
1975
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
1976
|
+
className: "neeto-form-engine-input__label-wrapper",
|
|
1977
|
+
children: /*#__PURE__*/jsx("label", {
|
|
1978
|
+
className: "neeto-form-engine-label",
|
|
1979
|
+
children: label
|
|
1980
|
+
})
|
|
1981
|
+
}), /*#__PURE__*/jsx("div", {
|
|
1982
|
+
className: "neeto-form-engine-star-rating__row",
|
|
1983
|
+
children: generateArray(minValue, maxValue).map(function (index) {
|
|
1984
|
+
return /*#__PURE__*/jsx(RatingButton$1, _objectSpread$3({
|
|
1985
|
+
label: index,
|
|
1986
|
+
rating: index
|
|
1987
|
+
}, props), index);
|
|
1988
|
+
})
|
|
1989
|
+
}), !!error && typeof error === "string" && /*#__PURE__*/jsx("p", {
|
|
1990
|
+
className: "neeto-form-engine-input__error",
|
|
1991
|
+
"data-cy": "neeto-form-engine-star-rating-error",
|
|
1992
|
+
children: error
|
|
1993
|
+
})]
|
|
1994
|
+
});
|
|
1995
|
+
};
|
|
1996
|
+
var StarRating$1 = /*#__PURE__*/memo(StarRating);
|
|
1997
|
+
|
|
1998
|
+
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; }
|
|
1999
|
+
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), !0).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; }
|
|
2000
|
+
var StarRatingField = function StarRatingField(_ref) {
|
|
2001
|
+
var question = _ref.question,
|
|
2002
|
+
customValidator = _ref.customValidator;
|
|
2003
|
+
var name = question.id,
|
|
2004
|
+
kind = question.kind,
|
|
2005
|
+
isRequired = question.isRequired,
|
|
2006
|
+
minValue = question.minValue,
|
|
2007
|
+
maxValue = question.maxValue,
|
|
2008
|
+
iconType = question.iconType;
|
|
2009
|
+
var label = fieldWithFallback(question, "label");
|
|
2010
|
+
return /*#__PURE__*/jsx(Field, {
|
|
2011
|
+
name: name,
|
|
2012
|
+
validate: validateFieldValue({
|
|
2013
|
+
kind: kind,
|
|
2014
|
+
label: label,
|
|
2015
|
+
isRequired: isRequired,
|
|
2016
|
+
customValidator: customValidator
|
|
2017
|
+
}),
|
|
2018
|
+
children: function children(_ref2) {
|
|
2019
|
+
var meta = _ref2.meta,
|
|
2020
|
+
field = _ref2.field;
|
|
2021
|
+
return /*#__PURE__*/jsx(StarRating$1, _objectSpread$2({
|
|
2022
|
+
iconType: iconType,
|
|
2023
|
+
maxValue: maxValue,
|
|
2024
|
+
minValue: minValue,
|
|
2025
|
+
name: name,
|
|
2026
|
+
error: meta.touched ? meta.error : "",
|
|
2027
|
+
label: getLabel(label, isRequired)
|
|
2028
|
+
}, field));
|
|
2029
|
+
}
|
|
2030
|
+
});
|
|
2031
|
+
};
|
|
2032
|
+
|
|
2033
|
+
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; }
|
|
2034
|
+
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), !0).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; }
|
|
2035
|
+
var TermsField = function TermsField(_ref) {
|
|
2036
|
+
var question = _ref.question,
|
|
2037
|
+
customValidator = _ref.customValidator;
|
|
2038
|
+
var name = question.id,
|
|
2039
|
+
kind = question.kind,
|
|
2040
|
+
isRequired = question.isRequired,
|
|
2041
|
+
nodeId = question.nodeId;
|
|
2042
|
+
var label = fieldWithFallback(question, "label", true);
|
|
2043
|
+
return /*#__PURE__*/jsx(Field, {
|
|
2044
|
+
name: name || nodeId,
|
|
2045
|
+
validate: validateFieldValue({
|
|
2046
|
+
kind: kind,
|
|
2047
|
+
label: label,
|
|
2048
|
+
isRequired: isRequired,
|
|
2049
|
+
customValidator: customValidator
|
|
2050
|
+
}),
|
|
2051
|
+
children: function children(_ref2) {
|
|
2052
|
+
var meta = _ref2.meta,
|
|
2053
|
+
field = _ref2.field;
|
|
2054
|
+
return /*#__PURE__*/jsx("div", {
|
|
2055
|
+
className: "neeto-form-engine-terms",
|
|
2056
|
+
children: /*#__PURE__*/jsx(Checkbox, _objectSpread$1(_objectSpread$1({}, _objectSpread$1(_objectSpread$1({}, field), {}, {
|
|
2057
|
+
name: name
|
|
2058
|
+
})), {}, {
|
|
2059
|
+
checked: field.value,
|
|
2060
|
+
error: meta.touched ? meta.error : "",
|
|
2061
|
+
children: /*#__PURE__*/jsx(EditorContent, {
|
|
2062
|
+
content: label
|
|
2063
|
+
})
|
|
2064
|
+
}))
|
|
2065
|
+
});
|
|
2066
|
+
}
|
|
2067
|
+
});
|
|
2068
|
+
};
|
|
2069
|
+
|
|
2070
|
+
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; }
|
|
2071
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).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; }
|
|
2072
|
+
var TextField = function TextField(_ref) {
|
|
2073
|
+
var _otherProps$onChange;
|
|
2074
|
+
var question = _ref.question,
|
|
2075
|
+
customValidator = _ref.customValidator,
|
|
2076
|
+
autoComplete = _ref.autoComplete;
|
|
2077
|
+
var name = question.id,
|
|
2078
|
+
kind = question.kind,
|
|
2079
|
+
isRequired = question.isRequired,
|
|
2080
|
+
nodeId = question.nodeId;
|
|
2081
|
+
var label = fieldWithFallback(question, "label");
|
|
2082
|
+
var _QUESTION_KIND$kind$t = QUESTION_KIND[kind.toUpperCase()],
|
|
2083
|
+
_QUESTION_KIND$kind$t2 = _QUESTION_KIND$kind$t.type,
|
|
2084
|
+
type = _QUESTION_KIND$kind$t2 === void 0 ? "text" : _QUESTION_KIND$kind$t2,
|
|
2085
|
+
onKeyDown = _QUESTION_KIND$kind$t.onKeyDown,
|
|
2086
|
+
otherProps = _QUESTION_KIND$kind$t.otherProps;
|
|
2087
|
+
var Component = kind === QUESTION_KIND.TEXTAREA.value ? Textarea : Input;
|
|
2088
|
+
var _useField = useField({
|
|
2089
|
+
name: name || nodeId,
|
|
2090
|
+
validate: validateFieldValue({
|
|
2091
|
+
kind: kind,
|
|
2092
|
+
label: label,
|
|
2093
|
+
isRequired: isRequired,
|
|
2094
|
+
customValidator: customValidator
|
|
2095
|
+
})
|
|
2096
|
+
}),
|
|
2097
|
+
_useField2 = _slicedToArray(_useField, 3),
|
|
2098
|
+
field = _useField2[0],
|
|
2099
|
+
_useField2$ = _useField2[1],
|
|
2100
|
+
touched = _useField2$.touched,
|
|
2101
|
+
error = _useField2$.error,
|
|
2102
|
+
_useField2$2 = _useField2[2],
|
|
2103
|
+
setValue = _useField2$2.setValue,
|
|
2104
|
+
setTouched = _useField2$2.setTouched;
|
|
2105
|
+
var handleFieldChange = withEventTargetValue(setValue);
|
|
2106
|
+
return /*#__PURE__*/jsx(Component, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({
|
|
2107
|
+
type: type
|
|
2108
|
+
}, field), {}, {
|
|
2109
|
+
autoComplete: autoComplete,
|
|
2110
|
+
label: label,
|
|
2111
|
+
onKeyDown: onKeyDown
|
|
2112
|
+
})), {}, {
|
|
2113
|
+
error: touched ? error : "",
|
|
2114
|
+
name: slugify(label),
|
|
2115
|
+
placeholder: fieldWithFallback(question, "placeholder"),
|
|
2116
|
+
required: isRequired,
|
|
2117
|
+
onBlur: function onBlur() {
|
|
2118
|
+
return setTouched(true);
|
|
2119
|
+
},
|
|
2120
|
+
onChange: (_otherProps$onChange = otherProps === null || otherProps === void 0 ? void 0 : otherProps.onChange(handleFieldChange)) !== null && _otherProps$onChange !== void 0 ? _otherProps$onChange : handleFieldChange
|
|
2121
|
+
}));
|
|
2122
|
+
};
|
|
2123
|
+
|
|
2124
|
+
var _QUESTION_TO_COMPONEN, _CAPTCHA_COMPONENT_MA;
|
|
2125
|
+
var QUESTION_TO_COMPONENT_MAP = (_QUESTION_TO_COMPONEN = {}, _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.TEXT.value, TextField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.NAME.value, NameField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.EMAIL.value, EmailField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.INTEGER.value, TextField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.DECIMAL.value, TextField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.PHONE.value, PhoneNumberField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.QUESTION.value, TextField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.TEXTAREA.value, TextField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.CHECKBOX.value, OptionsField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.RADIO.value, OptionsField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.DROPDOWN.value, OptionsField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.RATING.value, RatingField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.PARAGRAPH.value, function (_ref) {
|
|
2126
|
+
var question = _ref.question;
|
|
2127
|
+
return /*#__PURE__*/jsx(EditorContent, {
|
|
2128
|
+
content: fieldWithFallback(question, "label", true)
|
|
2129
|
+
});
|
|
2130
|
+
}), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.TERMS.value, TermsField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.DATE.value, DateField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.STAR_RATING.value, StarRatingField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.ADDITIONAL_GUESTS.value, MultipleEmailInput), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.RICH_TEXT.value, RichTextEditor), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.CONDITION.value, ConditionField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.FILE_UPLOAD.value, FileUploadField), _defineProperty(_QUESTION_TO_COMPONEN, QUESTION_KIND.CAPTCHA.value, CaptchaField), _QUESTION_TO_COMPONEN);
|
|
2131
|
+
var CAPTCHA_COMPONENT_MAP = (_CAPTCHA_COMPONENT_MA = {}, _defineProperty(_CAPTCHA_COMPONENT_MA, CAPTCHA_TYPES.RECAPTCHA_V2, Recaptcha), _defineProperty(_CAPTCHA_COMPONENT_MA, CAPTCHA_TYPES.MATH_CAPTCHA, MathCaptcha), _CAPTCHA_COMPONENT_MA);
|
|
2132
|
+
|
|
2133
|
+
var getFieldComponent = function getFieldComponent(_ref) {
|
|
2134
|
+
var kind = _ref.kind;
|
|
2135
|
+
if (kind in QUESTION_TO_COMPONENT_MAP) return QUESTION_TO_COMPONENT_MAP[kind];
|
|
2136
|
+
return function () {
|
|
2137
|
+
return null;
|
|
2138
|
+
};
|
|
2139
|
+
};
|
|
2140
|
+
var isPropsUnequal = function isPropsUnequal(props) {
|
|
2141
|
+
return function (nextProps, prevProps) {
|
|
2142
|
+
return notEqualsDeep(pick(props, nextProps), pick(props, prevProps));
|
|
2143
|
+
};
|
|
2144
|
+
};
|
|
2145
|
+
var getValidDate = function getValidDate(date) {
|
|
2146
|
+
if (!date) return "";
|
|
2147
|
+
return dayjs(date).isValid() ? dayjs(date) : "";
|
|
2148
|
+
};
|
|
2149
|
+
var getPhoneData = function getPhoneData(value, countryCode) {
|
|
2150
|
+
try {
|
|
2151
|
+
return parsePhoneNumber(value, countryCode);
|
|
2152
|
+
} catch (_unused) {
|
|
2153
|
+
return undefined;
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
2156
|
+
|
|
2157
|
+
export { FormikWrap as F, generateInitValues as a, getFieldComponent as b, clientI18nInstance as c, buildAutoCompleteAttribute as d, generateFormResponse as e, clearLocalStorageValues as f, getWithExpiry as g, mergeRefs as m, renderButtonsInOrder as r };
|
|
2158
|
+
//# sourceMappingURL=utils-1ab9e83f.js.map
|