@bigbinary/neeto-form-frontend 3.13.9 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -81
- package/app/javascript/src/translations/ar.json +9 -1
- package/app/javascript/src/translations/bg.json +207 -0
- package/app/javascript/src/translations/ca.json +207 -0
- package/app/javascript/src/translations/cs.json +9 -1
- package/app/javascript/src/translations/da.json +207 -0
- package/app/javascript/src/translations/de.json +9 -1
- package/app/javascript/src/translations/en.json +10 -1
- package/app/javascript/src/translations/es-MX.json +207 -0
- package/app/javascript/src/translations/es.json +9 -1
- package/app/javascript/src/translations/et.json +207 -0
- package/app/javascript/src/translations/fi.json +207 -0
- package/app/javascript/src/translations/fil.json +207 -0
- package/app/javascript/src/translations/fr.json +9 -1
- package/app/javascript/src/translations/hi.json +207 -0
- package/app/javascript/src/translations/hr.json +207 -0
- package/app/javascript/src/translations/id.json +207 -0
- package/app/javascript/src/translations/it.json +9 -1
- package/app/javascript/src/translations/ja.json +207 -0
- package/app/javascript/src/translations/ko.json +207 -0
- package/app/javascript/src/translations/nl.json +9 -1
- package/app/javascript/src/translations/pl.json +9 -1
- package/app/javascript/src/translations/pt-BR.json +207 -0
- package/app/javascript/src/translations/pt.json +9 -1
- package/app/javascript/src/translations/ro.json +9 -1
- package/app/javascript/src/translations/ru.json +9 -1
- package/app/javascript/src/translations/sk.json +207 -0
- package/app/javascript/src/translations/sl.json +207 -0
- package/app/javascript/src/translations/sv.json +207 -0
- package/app/javascript/src/translations/th.json +207 -0
- package/app/javascript/src/translations/tr.json +207 -0
- package/app/javascript/src/translations/uk.json +207 -0
- package/app/javascript/src/translations/vi.json +207 -0
- package/app/javascript/src/translations/zh-CN.json +207 -0
- package/app/javascript/src/translations/zh-TW.json +207 -0
- package/dist/BuildForm.js +32 -7
- package/dist/BuildForm.js.map +1 -1
- package/dist/ExternalForm.js +39 -32
- package/dist/ExternalForm.js.map +1 -1
- package/dist/Submission.js +1 -1
- package/dist/UrlBuilder.js +10 -6
- package/dist/UrlBuilder.js.map +1 -1
- package/dist/{buildForm-miMj_S28.js → buildForm-CXy5L1RP.js} +2 -2
- package/dist/{buildForm-miMj_S28.js.map → buildForm-CXy5L1RP.js.map} +1 -1
- package/dist/{buildForm-DQ2wgwuW.js → buildForm-DNCW7prR.js} +2 -2
- package/dist/{buildForm-DQ2wgwuW.js.map → buildForm-DNCW7prR.js.map} +1 -1
- package/dist/cjs/BuildForm.js +32 -7
- package/dist/cjs/BuildForm.js.map +1 -1
- package/dist/cjs/ExternalForm.js +38 -31
- package/dist/cjs/ExternalForm.js.map +1 -1
- package/dist/cjs/Submission.js +1 -1
- package/dist/cjs/UrlBuilder.js +10 -6
- package/dist/cjs/UrlBuilder.js.map +1 -1
- package/dist/cjs/hooks.js +4 -4
- package/dist/cjs/index.js +8 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/{constants-Dq9-rvtB.js → constants-BVZZfXua.js} +5 -1
- package/dist/constants-BVZZfXua.js.map +1 -0
- package/dist/{constants-R6y-Scns.js → constants-Bw2NSI7-.js} +5 -4
- package/dist/constants-Bw2NSI7-.js.map +1 -0
- package/dist/{constants-CDhYxmSQ.js → constants-VzpftVgP.js} +5 -3
- package/dist/constants-VzpftVgP.js.map +1 -0
- package/dist/{constants-DBuFEVFA.js → constants-b1EQ6-AS.js} +4 -2
- package/dist/constants-b1EQ6-AS.js.map +1 -0
- package/dist/hooks.js +4 -4
- package/dist/{index-CAtNQTCZ.js → index-BARvqe7c.js} +2 -2
- package/dist/{index-CAtNQTCZ.js.map → index-BARvqe7c.js.map} +1 -1
- package/dist/{index-BGEdOqsc.js → index-BkNaYmLc.js} +2 -2
- package/dist/{index-BGEdOqsc.js.map → index-BkNaYmLc.js.map} +1 -1
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/{useFormSubmission-Bor3TuEO.js → useFormSubmission-CYqHLtkA.js} +2 -2
- package/dist/{useFormSubmission-Bor3TuEO.js.map → useFormSubmission-CYqHLtkA.js.map} +1 -1
- package/dist/{useFormSubmission-D3Bxhy6g.js → useFormSubmission-DMoyM44A.js} +2 -2
- package/dist/{useFormSubmission-D3Bxhy6g.js.map → useFormSubmission-DMoyM44A.js.map} +1 -1
- package/dist/{utils-BThu7JWp.js → utils-BjgmM0Qs.js} +521 -55
- package/dist/utils-BjgmM0Qs.js.map +1 -0
- package/dist/{utils-1blEk5zb.js → utils-DdrUdmyb.js} +512 -45
- package/dist/utils-DdrUdmyb.js.map +1 -0
- package/package.json +15 -15
- package/dist/constants-CDhYxmSQ.js.map +0 -1
- package/dist/constants-DBuFEVFA.js.map +0 -1
- package/dist/constants-Dq9-rvtB.js.map +0 -1
- package/dist/constants-R6y-Scns.js.map +0 -1
- package/dist/utils-1blEk5zb.js.map +0 -1
- package/dist/utils-BThu7JWp.js.map +0 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { useEffect, useState, useImperativeHandle, memo, Fragment } from 'react';
|
|
1
|
+
import { useEffect, useState, useImperativeHandle, memo, Fragment as Fragment$1 } from 'react';
|
|
2
2
|
import { useFormikContext, useField, Field as Field$1, FastField } from 'formik';
|
|
3
|
-
import { isPresent, isNotEmpty, findBy, findById, isNotPresent, getRandomInt, randomPick, noop, hyphenate, slugify, notEqualsDeep } from '@bigbinary/neeto-cist';
|
|
4
|
-
import { i as isFunction, b as isEmptyValues, f as fieldWithFallback } from './index-
|
|
5
|
-
import { dayjs, withEventTargetValue } from '@bigbinary/neeto-commons-frontend/utils';
|
|
3
|
+
import { isPresent, isNotEmpty, findBy, filterBy, findById, isNotPresent, getRandomInt, randomPick, noop, hyphenate, slugify, notEqualsDeep } from '@bigbinary/neeto-cist';
|
|
4
|
+
import { i as isFunction, b as isEmptyValues, f as fieldWithFallback } from './index-BkNaYmLc.js';
|
|
5
|
+
import { dayjs, getFromLocalStorage, setToLocalStorage, removeFromLocalStorage, withEventTargetValue, buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
|
|
6
6
|
import { parsePhoneNumber } from 'libphonenumber-js';
|
|
7
|
-
import { includes, __, isNil, clamp, prop, map, identity, pluck, pipe, toLower, reject,
|
|
7
|
+
import { pick, mergeRight, omit, isEmpty, max, includes, __, mergeLeft, isNil, clamp, prop, map, zipObj, identity, pluck, pipe, toLower, reject, values, dec, equals } from 'ramda';
|
|
8
8
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
9
9
|
import EditorContent from '@bigbinary/neeto-editor/EditorContent';
|
|
10
|
-
import { C as CAPTCHA_TYPES } from './constants-
|
|
10
|
+
import { Q as QUESTION_TYPES, C as CAPTCHA_TYPES, E as EMAIL_VERIFICATIONS_CREATE_URL, j as EMAIL_VERIFICATIONS_VERIFY_URL } from './constants-b1EQ6-AS.js';
|
|
11
11
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
12
12
|
import Plus from '@bigbinary/neeto-icons/Plus';
|
|
13
13
|
import Button from '@bigbinary/neetoui/Button';
|
|
14
14
|
import NeetoUIMultiEmailInput from '@bigbinary/neetoui/MultiEmailInput';
|
|
15
|
-
import { useTranslation } from 'react-i18next';
|
|
15
|
+
import { useTranslation, Trans } from 'react-i18next';
|
|
16
16
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
17
17
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
18
18
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
@@ -20,10 +20,10 @@ import { isEditorEmpty } from '@bigbinary/neeto-editor/utils';
|
|
|
20
20
|
import { validation, PhoneNumberInput } from '@bigbinary/neeto-molecules/PhoneNumber';
|
|
21
21
|
import * as yup from 'yup';
|
|
22
22
|
import i18next from 'i18next';
|
|
23
|
-
import { jsx, jsxs, Fragment
|
|
24
|
-
import { a as QUESTION_KIND, E as EMAIL_REGEX, R as RATING_VALUES, S as SCHEMA_LESS_QUESTION_KINDS, L as LABEL_FIELDS,
|
|
23
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
24
|
+
import { a as QUESTION_KIND, E as EMAIL_REGEX, R as RATING_VALUES, S as SCHEMA_LESS_QUESTION_KINDS, c as SIX_DIGIT_NUMBER_REGEX, L as LABEL_FIELDS, d as RATING_OPTIONS, I as ICONS_MAP, g as generateArray } from './constants-Bw2NSI7-.js';
|
|
25
25
|
import classnames from 'classnames';
|
|
26
|
-
import { useUpdateEffect, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
26
|
+
import { useUpdateEffect, useStateWithDependency, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
27
27
|
import Refresh from '@bigbinary/neeto-icons/Refresh';
|
|
28
28
|
import Input from '@bigbinary/neetoui/Input';
|
|
29
29
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
@@ -31,6 +31,12 @@ import { globalProps } from '@bigbinary/neeto-commons-frontend/initializers';
|
|
|
31
31
|
import ReCAPTCHA from 'react-google-recaptcha';
|
|
32
32
|
import Checkbox from '@bigbinary/neetoui/Checkbox';
|
|
33
33
|
import DatePicker from '@bigbinary/neetoui/DatePicker';
|
|
34
|
+
import Toastr from '@bigbinary/neetoui/Toastr';
|
|
35
|
+
import { useMutation } from '@tanstack/react-query';
|
|
36
|
+
import axios from 'axios';
|
|
37
|
+
import CheckCircle from '@bigbinary/neeto-icons/CheckCircle';
|
|
38
|
+
import Spinner from '@bigbinary/neetoui/Spinner';
|
|
39
|
+
import NeetoUICallout from '@bigbinary/neetoui/Callout';
|
|
34
40
|
import { FileUpload } from '@bigbinary/neeto-molecules/FileUpload';
|
|
35
41
|
import Label from '@bigbinary/neetoui/Label';
|
|
36
42
|
import Select from '@bigbinary/neetoui/Select';
|
|
@@ -124,6 +130,76 @@ var FormikWrap = function FormikWrap(_ref) {
|
|
|
124
130
|
return children;
|
|
125
131
|
};
|
|
126
132
|
|
|
133
|
+
var RESEND_DELAY = 120;
|
|
134
|
+
var ONE_SECOND = 1000;
|
|
135
|
+
var EMAIL_VERIFICATION_FIELD_NAME_PREFIX = "verificationCode_";
|
|
136
|
+
var EMAIL_VERIFICATION_PREFIX = "neeto_form_nano_email_verification_details_";
|
|
137
|
+
var EMAIL_VERIFICATION_KEYS = {
|
|
138
|
+
EMAIL: "email",
|
|
139
|
+
TOKEN: "token",
|
|
140
|
+
VERIFIED: "verified",
|
|
141
|
+
CODE: "code",
|
|
142
|
+
CODE_SENT_AT: "code-sent-at"
|
|
143
|
+
};
|
|
144
|
+
var CALLOUT_STYLES = {
|
|
145
|
+
WARNING: "warning",
|
|
146
|
+
ERROR: "danger"
|
|
147
|
+
};
|
|
148
|
+
var DEFAULT_CALLOUT_DETAILS = {
|
|
149
|
+
message: "",
|
|
150
|
+
style: ""
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
var getEmailVerificationKey = function getEmailVerificationKey(formId) {
|
|
154
|
+
return "".concat(EMAIL_VERIFICATION_PREFIX, "-").concat(formId);
|
|
155
|
+
};
|
|
156
|
+
var getEmailVerificationDetails = function getEmailVerificationDetails(formId) {
|
|
157
|
+
return getFromLocalStorage(getEmailVerificationKey(formId)) || {};
|
|
158
|
+
};
|
|
159
|
+
var buildVerificationFieldName = function buildVerificationFieldName(questionId) {
|
|
160
|
+
return "".concat(EMAIL_VERIFICATION_FIELD_NAME_PREFIX, "-").concat(questionId);
|
|
161
|
+
};
|
|
162
|
+
var getLastVerificationCodeSentAt = function getLastVerificationCodeSentAt(formId, questionId) {
|
|
163
|
+
var codeSentAt = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.CODE_SENT_AT);
|
|
164
|
+
return Number(codeSentAt) || 0;
|
|
165
|
+
};
|
|
166
|
+
var storeLastVerificationCodeSentAt = function storeLastVerificationCodeSentAt(formId, questionId) {
|
|
167
|
+
var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
168
|
+
return setEmailVerificationDetail(formId, questionId, _defineProperty({}, EMAIL_VERIFICATION_KEYS.CODE_SENT_AT, Date.now() - offset));
|
|
169
|
+
};
|
|
170
|
+
var getRemainingTime = function getRemainingTime(formId, questionId) {
|
|
171
|
+
var elapsedTime = Math.floor((Date.now() - getLastVerificationCodeSentAt(formId, questionId)) / ONE_SECOND);
|
|
172
|
+
return max(RESEND_DELAY - elapsedTime, 0);
|
|
173
|
+
};
|
|
174
|
+
var getEmailVerificationDetail = function getEmailVerificationDetail(formId, questionId) {
|
|
175
|
+
var _questionDetails$keys;
|
|
176
|
+
var allDetails = getEmailVerificationDetails(formId);
|
|
177
|
+
var questionDetails = allDetails[questionId] || {};
|
|
178
|
+
for (var _len = arguments.length, keys = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
179
|
+
keys[_key - 2] = arguments[_key];
|
|
180
|
+
}
|
|
181
|
+
return keys.length === 1 ? (_questionDetails$keys = questionDetails[keys[0]]) !== null && _questionDetails$keys !== void 0 ? _questionDetails$keys : "" : pick(keys, allDetails);
|
|
182
|
+
};
|
|
183
|
+
var setEmailVerificationDetail = function setEmailVerificationDetail(formId, questionId, data) {
|
|
184
|
+
var storageKey = getEmailVerificationKey(formId);
|
|
185
|
+
var allDetails = getEmailVerificationDetails(formId);
|
|
186
|
+
allDetails[questionId] = mergeRight(allDetails[questionId] || {}, data);
|
|
187
|
+
setToLocalStorage(storageKey, allDetails);
|
|
188
|
+
};
|
|
189
|
+
var removeEmailVerificationDetail = function removeEmailVerificationDetail(formId, questionId) {
|
|
190
|
+
var storageKey = getEmailVerificationKey(formId);
|
|
191
|
+
var allDetails = getEmailVerificationDetails(formId);
|
|
192
|
+
for (var _len2 = arguments.length, keys = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
193
|
+
keys[_key2 - 2] = arguments[_key2];
|
|
194
|
+
}
|
|
195
|
+
allDetails[questionId] = omit(keys, allDetails[questionId]);
|
|
196
|
+
if (isEmpty(allDetails[questionId])) delete allDetails[questionId];
|
|
197
|
+
isEmpty(allDetails) ? removeFromLocalStorage(storageKey) : setToLocalStorage(storageKey, allDetails);
|
|
198
|
+
};
|
|
199
|
+
var clearEmailVerificationDetails = function clearEmailVerificationDetails(formId) {
|
|
200
|
+
removeFromLocalStorage(getEmailVerificationKey(formId));
|
|
201
|
+
};
|
|
202
|
+
|
|
127
203
|
var t$1 = clientI18nInstance.t;
|
|
128
204
|
var getInvalidFieldError = function getInvalidFieldError(label) {
|
|
129
205
|
return t$1("neetoForm.error.invalidField", {
|
|
@@ -149,8 +225,8 @@ var getInvalidTypeError = function getInvalidTypeError(label, type) {
|
|
|
149
225
|
});
|
|
150
226
|
};
|
|
151
227
|
|
|
152
|
-
function ownKeys$
|
|
153
|
-
function _objectSpread$
|
|
228
|
+
function ownKeys$h(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
229
|
+
function _objectSpread$h(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$h(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$h(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
154
230
|
var toEmailValues = function toEmailValues() {
|
|
155
231
|
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
156
232
|
return values.map(function (value) {
|
|
@@ -241,22 +317,34 @@ var getNameFromUrl = function getNameFromUrl(_ref7, fieldCodes) {
|
|
|
241
317
|
fullName: fieldCodes[fieldCode] || ""
|
|
242
318
|
};
|
|
243
319
|
};
|
|
320
|
+
var buildEmailVerificationEntries = function buildEmailVerificationEntries() {
|
|
321
|
+
var questions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
322
|
+
var emailQuestionsRequiringVerification = filterBy({
|
|
323
|
+
kind: QUESTION_TYPES.EMAIL,
|
|
324
|
+
isVerificationEnabled: true
|
|
325
|
+
}, questions);
|
|
326
|
+
var fieldNames = map(function (_ref8) {
|
|
327
|
+
var id = _ref8.id;
|
|
328
|
+
return buildVerificationFieldName(id);
|
|
329
|
+
}, emailQuestionsRequiringVerification);
|
|
330
|
+
return zipObj(fieldNames, Array(fieldNames.length).fill(""));
|
|
331
|
+
};
|
|
244
332
|
var getLabel = function getLabel(label, isRequired) {
|
|
245
333
|
return isRequired ? "".concat(label, "*") : label;
|
|
246
334
|
};
|
|
247
|
-
var generateInitValues = function generateInitValues(
|
|
248
|
-
var questions =
|
|
249
|
-
|
|
250
|
-
initialValues =
|
|
251
|
-
|
|
252
|
-
localValues =
|
|
253
|
-
|
|
254
|
-
fieldCodes =
|
|
335
|
+
var generateInitValues = function generateInitValues(_ref9) {
|
|
336
|
+
var questions = _ref9.questions,
|
|
337
|
+
_ref9$initialValues = _ref9.initialValues,
|
|
338
|
+
initialValues = _ref9$initialValues === void 0 ? [] : _ref9$initialValues,
|
|
339
|
+
_ref9$localValues = _ref9.localValues,
|
|
340
|
+
localValues = _ref9$localValues === void 0 ? {} : _ref9$localValues,
|
|
341
|
+
_ref9$fieldCodes = _ref9.fieldCodes,
|
|
342
|
+
fieldCodes = _ref9$fieldCodes === void 0 ? {} : _ref9$fieldCodes;
|
|
255
343
|
var initValues = {};
|
|
256
344
|
var valuesMap = {};
|
|
257
345
|
if (initialValues) {
|
|
258
346
|
valuesMap = initialValues.reduce(function (acc, answer) {
|
|
259
|
-
return _objectSpread$
|
|
347
|
+
return _objectSpread$h(_objectSpread$h({}, acc), {}, _defineProperty({}, answer.questionId, {
|
|
260
348
|
value: answer.value,
|
|
261
349
|
optionIds: answer.optionIds
|
|
262
350
|
}));
|
|
@@ -378,7 +466,8 @@ var generateInitValues = function generateInitValues(_ref8) {
|
|
|
378
466
|
}
|
|
379
467
|
}
|
|
380
468
|
});
|
|
381
|
-
|
|
469
|
+
var formInitialValues = !isEmptyValues(localValues) ? localValues : initValues;
|
|
470
|
+
return mergeLeft(formInitialValues, buildEmailVerificationEntries(questions));
|
|
382
471
|
};
|
|
383
472
|
var generateFormResponse = function generateFormResponse(response, questions) {
|
|
384
473
|
var formResponse = [];
|
|
@@ -476,8 +565,8 @@ var isPhoneNumberField = includes(__, [QUESTION_KIND.PHONE.value, QUESTION_KIND.
|
|
|
476
565
|
|
|
477
566
|
var _excluded$4 = ["kind", "customValidator"];
|
|
478
567
|
var _fieldKindValidatorMa;
|
|
479
|
-
function ownKeys$
|
|
480
|
-
function _objectSpread$
|
|
568
|
+
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; }
|
|
569
|
+
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; }
|
|
481
570
|
var t = clientI18nInstance.t;
|
|
482
571
|
yup.addMethod(yup.array, "unique", function () {
|
|
483
572
|
var field, message;
|
|
@@ -656,7 +745,7 @@ var validateFieldValue = function validateFieldValue(_ref16) {
|
|
|
656
745
|
return function (value) {
|
|
657
746
|
if (!(kind in fieldKindValidatorMap)) return;
|
|
658
747
|
var validator = fieldKindValidatorMap[kind];
|
|
659
|
-
var schema = customValidator || validator(_objectSpread$
|
|
748
|
+
var schema = customValidator || validator(_objectSpread$g({
|
|
660
749
|
kind: kind
|
|
661
750
|
}, otherProps));
|
|
662
751
|
|
|
@@ -689,6 +778,61 @@ var validateFieldValue = function validateFieldValue(_ref16) {
|
|
|
689
778
|
}());
|
|
690
779
|
};
|
|
691
780
|
};
|
|
781
|
+
var validateVerificationCode = function validateVerificationCode(context) {
|
|
782
|
+
return function (value) {
|
|
783
|
+
var entity = t("neetoForm.emailVerification.verificationCode");
|
|
784
|
+
var schema = yup.string().trim().when("$isVerificationEnabled", {
|
|
785
|
+
is: true,
|
|
786
|
+
then: function then(schema) {
|
|
787
|
+
return schema.when("$isRequired", {
|
|
788
|
+
is: true,
|
|
789
|
+
then: function then(s) {
|
|
790
|
+
return s.required(getRequiredFieldError(entity));
|
|
791
|
+
}
|
|
792
|
+
}).when("$email", function (email, s) {
|
|
793
|
+
if (email !== null && email !== void 0 && email.trim()) {
|
|
794
|
+
return s.required(getRequiredFieldError(entity));
|
|
795
|
+
}
|
|
796
|
+
return s;
|
|
797
|
+
}).test("is-6-digit-number", t("neetoForm.error.mustBeASixDigitNumber", {
|
|
798
|
+
entity: entity
|
|
799
|
+
}), function (value) {
|
|
800
|
+
return isNotPresent(value) || SIX_DIGIT_NUMBER_REGEX.test(value);
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
806
|
+
return new Promise(/*#__PURE__*/function () {
|
|
807
|
+
var _ref18 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve) {
|
|
808
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
809
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
810
|
+
case 0:
|
|
811
|
+
_context2.prev = 0;
|
|
812
|
+
_context2.next = 3;
|
|
813
|
+
return schema.validate(value, {
|
|
814
|
+
context: context
|
|
815
|
+
});
|
|
816
|
+
case 3:
|
|
817
|
+
resolve(undefined);
|
|
818
|
+
_context2.next = 9;
|
|
819
|
+
break;
|
|
820
|
+
case 6:
|
|
821
|
+
_context2.prev = 6;
|
|
822
|
+
_context2.t0 = _context2["catch"](0);
|
|
823
|
+
resolve(_context2.t0.message);
|
|
824
|
+
case 9:
|
|
825
|
+
case "end":
|
|
826
|
+
return _context2.stop();
|
|
827
|
+
}
|
|
828
|
+
}, _callee2, null, [[0, 6]]);
|
|
829
|
+
}));
|
|
830
|
+
return function (_x2) {
|
|
831
|
+
return _ref18.apply(this, arguments);
|
|
832
|
+
};
|
|
833
|
+
}());
|
|
834
|
+
};
|
|
835
|
+
};
|
|
692
836
|
|
|
693
837
|
var MultipleEmailInput = function MultipleEmailInput(_ref) {
|
|
694
838
|
var question = _ref.question,
|
|
@@ -935,8 +1079,8 @@ var Recaptcha = function Recaptcha(_ref) {
|
|
|
935
1079
|
}, clientI18nInstance.language);
|
|
936
1080
|
};
|
|
937
1081
|
|
|
938
|
-
function ownKeys$
|
|
939
|
-
function _objectSpread$
|
|
1082
|
+
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; }
|
|
1083
|
+
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; }
|
|
940
1084
|
var ConditionField = function ConditionField(_ref) {
|
|
941
1085
|
var question = _ref.question,
|
|
942
1086
|
customValidator = _ref.customValidator;
|
|
@@ -956,7 +1100,7 @@ var ConditionField = function ConditionField(_ref) {
|
|
|
956
1100
|
children: function children(_ref2) {
|
|
957
1101
|
var meta = _ref2.meta,
|
|
958
1102
|
field = _ref2.field;
|
|
959
|
-
return /*#__PURE__*/jsx(Checkbox, _objectSpread$
|
|
1103
|
+
return /*#__PURE__*/jsx(Checkbox, _objectSpread$f(_objectSpread$f({}, _objectSpread$f(_objectSpread$f({}, field), {}, {
|
|
960
1104
|
label: label,
|
|
961
1105
|
name: name
|
|
962
1106
|
})), {}, {
|
|
@@ -969,8 +1113,8 @@ var ConditionField = function ConditionField(_ref) {
|
|
|
969
1113
|
};
|
|
970
1114
|
|
|
971
1115
|
var _excluded$3 = ["value"];
|
|
972
|
-
function ownKeys$
|
|
973
|
-
function _objectSpread$
|
|
1116
|
+
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; }
|
|
1117
|
+
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; }
|
|
974
1118
|
var DateField = function DateField(_ref) {
|
|
975
1119
|
var question = _ref.question,
|
|
976
1120
|
customValidator = _ref.customValidator;
|
|
@@ -1007,7 +1151,7 @@ var DateField = function DateField(_ref) {
|
|
|
1007
1151
|
value = _ref2$field.value,
|
|
1008
1152
|
field = _objectWithoutProperties(_ref2$field, _excluded$3),
|
|
1009
1153
|
form = _ref2.form;
|
|
1010
|
-
return /*#__PURE__*/jsx(DatePicker, _objectSpread$
|
|
1154
|
+
return /*#__PURE__*/jsx(DatePicker, _objectSpread$e(_objectSpread$e({}, _objectSpread$e(_objectSpread$e({}, field), {}, {
|
|
1011
1155
|
type: type
|
|
1012
1156
|
})), {}, {
|
|
1013
1157
|
"data-cy": "".concat(hyphenate(label), "-input-field"),
|
|
@@ -1029,13 +1173,239 @@ var DateField = function DateField(_ref) {
|
|
|
1029
1173
|
});
|
|
1030
1174
|
};
|
|
1031
1175
|
|
|
1176
|
+
var create = function create(_ref) {
|
|
1177
|
+
var formId = _ref.formId,
|
|
1178
|
+
questionId = _ref.questionId,
|
|
1179
|
+
payload = _ref.payload;
|
|
1180
|
+
return axios.post(buildUrl(EMAIL_VERIFICATIONS_CREATE_URL, {
|
|
1181
|
+
formId: formId,
|
|
1182
|
+
questionId: questionId
|
|
1183
|
+
}), payload, {
|
|
1184
|
+
showToastr: false
|
|
1185
|
+
});
|
|
1186
|
+
};
|
|
1187
|
+
var verify = function verify(_ref2) {
|
|
1188
|
+
var formId = _ref2.formId,
|
|
1189
|
+
questionId = _ref2.questionId,
|
|
1190
|
+
payload = _ref2.payload;
|
|
1191
|
+
return axios.post(buildUrl(EMAIL_VERIFICATIONS_VERIFY_URL, {
|
|
1192
|
+
formId: formId,
|
|
1193
|
+
questionId: questionId
|
|
1194
|
+
}), payload, {
|
|
1195
|
+
showToastr: false
|
|
1196
|
+
});
|
|
1197
|
+
};
|
|
1198
|
+
var emailVerificationsApi = {
|
|
1199
|
+
create: create,
|
|
1200
|
+
verify: verify
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1203
|
+
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; }
|
|
1204
|
+
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; }
|
|
1205
|
+
var getMutationCallbacks = function getMutationCallbacks(options) {
|
|
1206
|
+
return {
|
|
1207
|
+
onSuccess: function onSuccess() {
|
|
1208
|
+
var _options$onSuccess;
|
|
1209
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1210
|
+
args[_key] = arguments[_key];
|
|
1211
|
+
}
|
|
1212
|
+
return (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 ? void 0 : _options$onSuccess.call.apply(_options$onSuccess, [options].concat(args));
|
|
1213
|
+
},
|
|
1214
|
+
onError: function onError() {
|
|
1215
|
+
var _options$onError;
|
|
1216
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1217
|
+
args[_key2] = arguments[_key2];
|
|
1218
|
+
}
|
|
1219
|
+
return (_options$onError = options.onError) === null || _options$onError === void 0 ? void 0 : _options$onError.call.apply(_options$onError, [options].concat(args));
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
};
|
|
1223
|
+
var useSendEmailVerificationCode = function useSendEmailVerificationCode(formId, questionId) {
|
|
1224
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1225
|
+
return useMutation(_objectSpread$d(_objectSpread$d({
|
|
1226
|
+
mutationFn: function mutationFn(payload) {
|
|
1227
|
+
return emailVerificationsApi.create({
|
|
1228
|
+
formId: formId,
|
|
1229
|
+
questionId: questionId,
|
|
1230
|
+
payload: payload
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
}, options), getMutationCallbacks(options)));
|
|
1234
|
+
};
|
|
1235
|
+
var useVerifyEmailVerificationCode = function useVerifyEmailVerificationCode(formId, questionId) {
|
|
1236
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1237
|
+
return useMutation(_objectSpread$d(_objectSpread$d({
|
|
1238
|
+
mutationFn: function mutationFn(payload) {
|
|
1239
|
+
return emailVerificationsApi.verify({
|
|
1240
|
+
formId: formId,
|
|
1241
|
+
questionId: questionId,
|
|
1242
|
+
payload: payload
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
}, options), getMutationCallbacks(options)));
|
|
1246
|
+
};
|
|
1247
|
+
|
|
1248
|
+
var SendCodeButton = function SendCodeButton(_ref) {
|
|
1249
|
+
var isCodeVerified = _ref.isCodeVerified,
|
|
1250
|
+
isSendingVerificationCode = _ref.isSendingVerificationCode,
|
|
1251
|
+
handleClick = _ref.handleClick,
|
|
1252
|
+
isDisabled = _ref.isDisabled;
|
|
1253
|
+
var _useTranslation = useTranslation(),
|
|
1254
|
+
t = _useTranslation.t;
|
|
1255
|
+
if (isCodeVerified) {
|
|
1256
|
+
return /*#__PURE__*/jsx(CheckCircle, {});
|
|
1257
|
+
}
|
|
1258
|
+
return /*#__PURE__*/jsx(Button, {
|
|
1259
|
+
disabled: isDisabled,
|
|
1260
|
+
size: "small",
|
|
1261
|
+
style: "secondary",
|
|
1262
|
+
onClick: handleClick,
|
|
1263
|
+
children: isSendingVerificationCode ? /*#__PURE__*/jsx(Spinner, {
|
|
1264
|
+
size: "16"
|
|
1265
|
+
}) : t("neetoForm.emailVerification.sendCode")
|
|
1266
|
+
});
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
var ResendVerificationCode = function ResendVerificationCode(_ref) {
|
|
1270
|
+
var formId = _ref.formId,
|
|
1271
|
+
questionId = _ref.questionId,
|
|
1272
|
+
sendVerificationCode = _ref.sendVerificationCode,
|
|
1273
|
+
isResendDisabled = _ref.isResendDisabled;
|
|
1274
|
+
var _useState = useState(getRemainingTime(formId, questionId)),
|
|
1275
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1276
|
+
secondsLeft = _useState2[0],
|
|
1277
|
+
setSecondsLeft = _useState2[1];
|
|
1278
|
+
var _useTranslation = useTranslation(),
|
|
1279
|
+
t = _useTranslation.t;
|
|
1280
|
+
useEffect(function () {
|
|
1281
|
+
if (secondsLeft <= 0) return undefined;
|
|
1282
|
+
var interval = setTimeout(function () {
|
|
1283
|
+
setSecondsLeft(pipe(dec, max(0)));
|
|
1284
|
+
}, ONE_SECOND);
|
|
1285
|
+
return function () {
|
|
1286
|
+
return clearTimeout(interval);
|
|
1287
|
+
};
|
|
1288
|
+
}, [secondsLeft]);
|
|
1289
|
+
var handleResendClick = function handleResendClick() {
|
|
1290
|
+
if (secondsLeft !== 0) return;
|
|
1291
|
+
sendVerificationCode();
|
|
1292
|
+
setSecondsLeft(RESEND_DELAY);
|
|
1293
|
+
storeLastVerificationCodeSentAt(formId, questionId);
|
|
1294
|
+
};
|
|
1295
|
+
return /*#__PURE__*/jsx("p", {
|
|
1296
|
+
children: !isResendDisabled && secondsLeft > 0 ? t("neetoForm.emailVerification.resendInSeconds", {
|
|
1297
|
+
secondsLeft: secondsLeft
|
|
1298
|
+
}) : /*#__PURE__*/jsx(Trans, {
|
|
1299
|
+
i18nKey: "neetoForm.emailVerification.resendCode",
|
|
1300
|
+
components: {
|
|
1301
|
+
button: /*#__PURE__*/jsx(Button, {
|
|
1302
|
+
disabled: isResendDisabled,
|
|
1303
|
+
size: "small",
|
|
1304
|
+
style: "link",
|
|
1305
|
+
onClick: handleResendClick
|
|
1306
|
+
})
|
|
1307
|
+
}
|
|
1308
|
+
})
|
|
1309
|
+
});
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
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; }
|
|
1313
|
+
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; }
|
|
1314
|
+
var VerifyCode = function VerifyCode(_ref) {
|
|
1315
|
+
var formId = _ref.formId,
|
|
1316
|
+
questionId = _ref.questionId,
|
|
1317
|
+
email = _ref.email,
|
|
1318
|
+
emailVerificationToken = _ref.emailVerificationToken,
|
|
1319
|
+
setIsCodeVerified = _ref.setIsCodeVerified,
|
|
1320
|
+
handleResponseError = _ref.handleResponseError,
|
|
1321
|
+
hasSentVerificationCode = _ref.hasSentVerificationCode,
|
|
1322
|
+
calloutDetails = _ref.calloutDetails,
|
|
1323
|
+
handleSendVerificationCode = _ref.handleSendVerificationCode,
|
|
1324
|
+
isRequired = _ref.isRequired,
|
|
1325
|
+
isVerificationEnabled = _ref.isVerificationEnabled;
|
|
1326
|
+
var _useTranslation = useTranslation(),
|
|
1327
|
+
t = _useTranslation.t;
|
|
1328
|
+
var verificationFieldName = buildVerificationFieldName(questionId);
|
|
1329
|
+
var _useField = useField({
|
|
1330
|
+
name: verificationFieldName,
|
|
1331
|
+
validate: validateVerificationCode({
|
|
1332
|
+
isVerificationEnabled: isVerificationEnabled,
|
|
1333
|
+
isRequired: isRequired,
|
|
1334
|
+
email: email
|
|
1335
|
+
})
|
|
1336
|
+
}),
|
|
1337
|
+
_useField2 = _slicedToArray(_useField, 3),
|
|
1338
|
+
field = _useField2[0],
|
|
1339
|
+
_useField2$ = _useField2[1],
|
|
1340
|
+
touched = _useField2$.touched,
|
|
1341
|
+
error = _useField2$.error,
|
|
1342
|
+
_useField2$2 = _useField2[2],
|
|
1343
|
+
setValue = _useField2$2.setValue,
|
|
1344
|
+
setTouched = _useField2$2.setTouched;
|
|
1345
|
+
var code = field.value;
|
|
1346
|
+
var _useState = useState(code),
|
|
1347
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1348
|
+
previousCode = _useState2[0],
|
|
1349
|
+
setPreviousCode = _useState2[1];
|
|
1350
|
+
var _useVerifyEmailVerifi = useVerifyEmailVerificationCode(formId, questionId, {
|
|
1351
|
+
onSuccess: function onSuccess(_, _ref2) {
|
|
1352
|
+
var emailVerifications = _ref2.emailVerifications;
|
|
1353
|
+
setIsCodeVerified(true);
|
|
1354
|
+
setPreviousCode(emailVerifications.otp);
|
|
1355
|
+
setEmailVerificationDetail(formId, questionId, _defineProperty(_defineProperty(_defineProperty({}, EMAIL_VERIFICATION_KEYS.EMAIL, emailVerifications.email), EMAIL_VERIFICATION_KEYS.CODE, emailVerifications.otp), EMAIL_VERIFICATION_KEYS.VERIFIED, true));
|
|
1356
|
+
},
|
|
1357
|
+
onError: handleResponseError
|
|
1358
|
+
}),
|
|
1359
|
+
verifyCode = _useVerifyEmailVerifi.mutate,
|
|
1360
|
+
isVerifyingCode = _useVerifyEmailVerifi.isPending;
|
|
1361
|
+
var hasError = isPresent(error);
|
|
1362
|
+
useEffect(function () {
|
|
1363
|
+
var handleVerifyCode = function handleVerifyCode() {
|
|
1364
|
+
if (equals(code, previousCode) || hasError || (code === null || code === void 0 ? void 0 : code.length) !== 6) {
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
verifyCode({
|
|
1368
|
+
emailVerifications: {
|
|
1369
|
+
email: email,
|
|
1370
|
+
token: emailVerificationToken,
|
|
1371
|
+
otp: code
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
};
|
|
1375
|
+
handleVerifyCode();
|
|
1376
|
+
}, [code, hasError]);
|
|
1377
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
1378
|
+
children: [/*#__PURE__*/jsx(Input, _objectSpread$c(_objectSpread$c({}, _objectSpread$c({}, field)), {}, {
|
|
1379
|
+
disabled: isVerifyingCode,
|
|
1380
|
+
error: touched ? error : "",
|
|
1381
|
+
loading: isVerifyingCode,
|
|
1382
|
+
name: verificationFieldName,
|
|
1383
|
+
placeholder: t("neetoForm.emailVerification.verificationCode"),
|
|
1384
|
+
size: "small",
|
|
1385
|
+
onBlur: function onBlur() {
|
|
1386
|
+
return setTouched(true);
|
|
1387
|
+
},
|
|
1388
|
+
onChange: withEventTargetValue(setValue)
|
|
1389
|
+
})), hasSentVerificationCode && /*#__PURE__*/jsx(ResendVerificationCode, {
|
|
1390
|
+
formId: formId,
|
|
1391
|
+
questionId: questionId,
|
|
1392
|
+
isResendDisabled: calloutDetails.style === CALLOUT_STYLES.ERROR,
|
|
1393
|
+
sendVerificationCode: handleSendVerificationCode
|
|
1394
|
+
}), calloutDetails.message && /*#__PURE__*/jsx(NeetoUICallout, {
|
|
1395
|
+
style: calloutDetails.style,
|
|
1396
|
+
children: calloutDetails.message
|
|
1397
|
+
})]
|
|
1398
|
+
});
|
|
1399
|
+
};
|
|
1400
|
+
|
|
1032
1401
|
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; }
|
|
1033
1402
|
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; }
|
|
1034
1403
|
var EmailField = function EmailField(_ref) {
|
|
1035
1404
|
var question = _ref.question,
|
|
1036
1405
|
customValidator = _ref.customValidator,
|
|
1037
|
-
autoComplete = _ref.autoComplete
|
|
1038
|
-
|
|
1406
|
+
autoComplete = _ref.autoComplete,
|
|
1407
|
+
isPreview = _ref.preview;
|
|
1408
|
+
var questionId = question.id,
|
|
1039
1409
|
kind = question.kind,
|
|
1040
1410
|
isRequired = question.isRequired,
|
|
1041
1411
|
isReadOnly = question.isReadOnly,
|
|
@@ -1043,11 +1413,26 @@ var EmailField = function EmailField(_ref) {
|
|
|
1043
1413
|
whitelistedDomains = question.whitelistedDomains,
|
|
1044
1414
|
isDomainBlacklistingEnabled = question.isDomainBlacklistingEnabled,
|
|
1045
1415
|
blacklistedDomains = question.blacklistedDomains,
|
|
1046
|
-
|
|
1416
|
+
isVerificationEnabled = question.isVerificationEnabled,
|
|
1417
|
+
nodeId = question.nodeId,
|
|
1418
|
+
formId = question.formId;
|
|
1047
1419
|
var label = fieldWithFallback(question, "label");
|
|
1420
|
+
var _useState = useState(DEFAULT_CALLOUT_DETAILS),
|
|
1421
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1422
|
+
calloutDetails = _useState2[0],
|
|
1423
|
+
setCalloutDetails = _useState2[1];
|
|
1048
1424
|
var type = QUESTION_KIND[kind.toUpperCase()].type;
|
|
1425
|
+
var _useState3 = useState(getLastVerificationCodeSentAt(questionId) > 0),
|
|
1426
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
1427
|
+
hasSentVerificationCode = _useState4[0],
|
|
1428
|
+
setHasSentVerificationCode = _useState4[1];
|
|
1429
|
+
var verificationStatus = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.VERIFIED);
|
|
1430
|
+
var _useStateWithDependen = useStateWithDependency(verificationStatus, [verificationStatus]),
|
|
1431
|
+
_useStateWithDependen2 = _slicedToArray(_useStateWithDependen, 2),
|
|
1432
|
+
isCodeVerified = _useStateWithDependen2[0],
|
|
1433
|
+
setIsCodeVerified = _useStateWithDependen2[1];
|
|
1049
1434
|
var _useField = useField({
|
|
1050
|
-
name:
|
|
1435
|
+
name: questionId || nodeId,
|
|
1051
1436
|
validate: validateFieldValue({
|
|
1052
1437
|
kind: kind,
|
|
1053
1438
|
label: label,
|
|
@@ -1065,23 +1450,104 @@ var EmailField = function EmailField(_ref) {
|
|
|
1065
1450
|
_useField2$2 = _useField2[2],
|
|
1066
1451
|
setValue = _useField2$2.setValue,
|
|
1067
1452
|
setTouched = _useField2$2.setTouched;
|
|
1453
|
+
var _useFormikContext = useFormikContext(),
|
|
1454
|
+
setFieldValue = _useFormikContext.setFieldValue;
|
|
1455
|
+
var email = field.value;
|
|
1456
|
+
var emailVerificationToken = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.TOKEN);
|
|
1457
|
+
var handleResponseError = function handleResponseError(error) {
|
|
1458
|
+
var _error$response;
|
|
1459
|
+
var message = error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 || (_error$response = _error$response.data) === null || _error$response === void 0 ? void 0 : _error$response.error;
|
|
1460
|
+
if ((error === null || error === void 0 ? void 0 : error.status) === 429) {
|
|
1461
|
+
setCalloutDetails({
|
|
1462
|
+
message: message,
|
|
1463
|
+
style: CALLOUT_STYLES.ERROR
|
|
1464
|
+
});
|
|
1465
|
+
storeLastVerificationCodeSentAt(formId, questionId, RESEND_DELAY * ONE_SECOND);
|
|
1466
|
+
} else {
|
|
1467
|
+
Toastr.error(message);
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
// TODO backend validation
|
|
1472
|
+
var _useSendEmailVerifica = useSendEmailVerificationCode(formId, questionId, {
|
|
1473
|
+
onSuccess: function onSuccess(_ref2) {
|
|
1474
|
+
var token = _ref2.token,
|
|
1475
|
+
message = _ref2.message;
|
|
1476
|
+
setHasSentVerificationCode(true);
|
|
1477
|
+
storeLastVerificationCodeSentAt(formId, questionId);
|
|
1478
|
+
if (!emailVerificationToken) {
|
|
1479
|
+
setEmailVerificationDetail(formId, questionId, _defineProperty({}, EMAIL_VERIFICATION_KEYS.TOKEN, token));
|
|
1480
|
+
}
|
|
1481
|
+
if (message) {
|
|
1482
|
+
setCalloutDetails({
|
|
1483
|
+
message: message,
|
|
1484
|
+
style: CALLOUT_STYLES.WARNING
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
},
|
|
1488
|
+
onError: handleResponseError
|
|
1489
|
+
}),
|
|
1490
|
+
sendVerificationCode = _useSendEmailVerifica.mutate,
|
|
1491
|
+
isSendingVerificationCode = _useSendEmailVerifica.isPending;
|
|
1492
|
+
var resetVerifiedData = function resetVerifiedData(email) {
|
|
1493
|
+
var verifiedEmail = getEmailVerificationDetail(formId, questionId, EMAIL_VERIFICATION_KEYS.EMAIL);
|
|
1494
|
+
if (email !== verifiedEmail) {
|
|
1495
|
+
removeEmailVerificationDetail(formId, questionId, values(omit(["TOKEN"], EMAIL_VERIFICATION_KEYS)));
|
|
1496
|
+
setIsCodeVerified(false);
|
|
1497
|
+
setFieldValue(buildVerificationFieldName(questionId), "");
|
|
1498
|
+
setHasSentVerificationCode(false);
|
|
1499
|
+
setCalloutDetails(DEFAULT_CALLOUT_DETAILS);
|
|
1500
|
+
}
|
|
1501
|
+
};
|
|
1068
1502
|
var handleFieldChange = withEventTargetValue(setValue);
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
},
|
|
1083
|
-
|
|
1084
|
-
|
|
1503
|
+
var handleSendVerificationCode = function handleSendVerificationCode() {
|
|
1504
|
+
return sendVerificationCode({
|
|
1505
|
+
emailVerifications: {
|
|
1506
|
+
email: email,
|
|
1507
|
+
token: emailVerificationToken
|
|
1508
|
+
}
|
|
1509
|
+
});
|
|
1510
|
+
};
|
|
1511
|
+
var shouldShowVerifyButton = isVerificationEnabled && (isPreview || isPresent(email) && isNotPresent(error));
|
|
1512
|
+
return /*#__PURE__*/jsxs("div", {
|
|
1513
|
+
className: "flex-col space-y-2",
|
|
1514
|
+
children: [/*#__PURE__*/jsx(Input, _objectSpread$b(_objectSpread$b({}, _objectSpread$b(_objectSpread$b({
|
|
1515
|
+
type: type
|
|
1516
|
+
}, field), {}, {
|
|
1517
|
+
autoComplete: autoComplete,
|
|
1518
|
+
label: label
|
|
1519
|
+
}, shouldShowVerifyButton && {
|
|
1520
|
+
suffix: /*#__PURE__*/jsx(SendCodeButton, {
|
|
1521
|
+
isCodeVerified: isCodeVerified,
|
|
1522
|
+
isSendingVerificationCode: isSendingVerificationCode,
|
|
1523
|
+
handleClick: isPreview ? noop : handleSendVerificationCode,
|
|
1524
|
+
isDisabled: isCodeVerified || hasSentVerificationCode
|
|
1525
|
+
})
|
|
1526
|
+
})), {}, {
|
|
1527
|
+
disabled: isReadOnly,
|
|
1528
|
+
error: touched && !isCodeVerified ? error : "",
|
|
1529
|
+
name: kind,
|
|
1530
|
+
placeholder: fieldWithFallback(question, "placeholder"),
|
|
1531
|
+
required: isRequired,
|
|
1532
|
+
onBlur: function onBlur() {
|
|
1533
|
+
return setTouched(true);
|
|
1534
|
+
},
|
|
1535
|
+
onBlurCapture: withEventTargetValue(resetVerifiedData),
|
|
1536
|
+
onChange: handleFieldChange
|
|
1537
|
+
})), shouldShowVerifyButton && !isCodeVerified && /*#__PURE__*/jsx(VerifyCode, {
|
|
1538
|
+
calloutDetails: calloutDetails,
|
|
1539
|
+
email: email,
|
|
1540
|
+
emailVerificationToken: emailVerificationToken,
|
|
1541
|
+
formId: formId,
|
|
1542
|
+
handleResponseError: handleResponseError,
|
|
1543
|
+
handleSendVerificationCode: handleSendVerificationCode,
|
|
1544
|
+
hasSentVerificationCode: hasSentVerificationCode,
|
|
1545
|
+
isRequired: isRequired,
|
|
1546
|
+
isVerificationEnabled: isVerificationEnabled,
|
|
1547
|
+
questionId: questionId,
|
|
1548
|
+
setIsCodeVerified: setIsCodeVerified
|
|
1549
|
+
})]
|
|
1550
|
+
});
|
|
1085
1551
|
};
|
|
1086
1552
|
|
|
1087
1553
|
var FileUploadField = function FileUploadField(_ref) {
|
|
@@ -1417,7 +1883,7 @@ var Rating = function Rating(_ref) {
|
|
|
1417
1883
|
var Icon = _ref2.icon,
|
|
1418
1884
|
modifier = _ref2.modifier,
|
|
1419
1885
|
rating = _ref2.value;
|
|
1420
|
-
return /*#__PURE__*/jsxs(Fragment, {
|
|
1886
|
+
return /*#__PURE__*/jsxs(Fragment$1, {
|
|
1421
1887
|
children: [/*#__PURE__*/jsxs("button", {
|
|
1422
1888
|
disabled: disabled,
|
|
1423
1889
|
type: "button",
|
|
@@ -1575,7 +2041,7 @@ var RatingButton = function RatingButton(_ref) {
|
|
|
1575
2041
|
};
|
|
1576
2042
|
var Icon = ICONS_MAP[iconType];
|
|
1577
2043
|
var selectedRating = getSelectedRating(value);
|
|
1578
|
-
return /*#__PURE__*/jsxs(Fragment
|
|
2044
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
1579
2045
|
children: [/*#__PURE__*/jsxs("button", {
|
|
1580
2046
|
className: classnames({
|
|
1581
2047
|
active: rating === value
|
|
@@ -1804,5 +2270,5 @@ var containsIgnoreCase = function containsIgnoreCase(string, substring) {
|
|
|
1804
2270
|
return string.toLowerCase().includes(substring.toLowerCase());
|
|
1805
2271
|
};
|
|
1806
2272
|
|
|
1807
|
-
export { FormikWrap as F, getFieldComponent as a, buildAutoCompleteAttribute as b, clientI18nInstance as c, getWithExpiry as d,
|
|
1808
|
-
//# sourceMappingURL=utils-
|
|
2273
|
+
export { FormikWrap as F, getFieldComponent as a, buildAutoCompleteAttribute as b, clientI18nInstance as c, getWithExpiry as d, clearEmailVerificationDetails as e, generateFormResponse as f, generateInitValues as g, clearLocalStorageValues as h, mergeRefs as m, renderButtonsInOrder as r };
|
|
2274
|
+
//# sourceMappingURL=utils-BjgmM0Qs.js.map
|