@bigbinary/neeto-form-frontend 4.4.8 → 4.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/app/javascript/src/translations/ar.json +10 -1
  2. package/app/javascript/src/translations/bg.json +10 -1
  3. package/app/javascript/src/translations/ca.json +10 -1
  4. package/app/javascript/src/translations/cs.json +10 -1
  5. package/app/javascript/src/translations/da.json +10 -1
  6. package/app/javascript/src/translations/de.json +10 -1
  7. package/app/javascript/src/translations/es-MX.json +10 -1
  8. package/app/javascript/src/translations/es.json +10 -1
  9. package/app/javascript/src/translations/et.json +10 -1
  10. package/app/javascript/src/translations/fi.json +10 -1
  11. package/app/javascript/src/translations/fil.json +10 -1
  12. package/app/javascript/src/translations/fr.json +10 -1
  13. package/app/javascript/src/translations/he.json +10 -1
  14. package/app/javascript/src/translations/hi.json +10 -1
  15. package/app/javascript/src/translations/hr.json +10 -1
  16. package/app/javascript/src/translations/hu.json +10 -1
  17. package/app/javascript/src/translations/id.json +10 -1
  18. package/app/javascript/src/translations/it.json +10 -1
  19. package/app/javascript/src/translations/ja.json +10 -1
  20. package/app/javascript/src/translations/ko.json +10 -1
  21. package/app/javascript/src/translations/nl.json +10 -1
  22. package/app/javascript/src/translations/pl.json +10 -1
  23. package/app/javascript/src/translations/pt-BR.json +10 -1
  24. package/app/javascript/src/translations/pt.json +10 -1
  25. package/app/javascript/src/translations/ro.json +10 -1
  26. package/app/javascript/src/translations/ru.json +10 -1
  27. package/app/javascript/src/translations/sk.json +10 -1
  28. package/app/javascript/src/translations/sl.json +10 -1
  29. package/app/javascript/src/translations/sv.json +10 -1
  30. package/app/javascript/src/translations/th.json +10 -1
  31. package/app/javascript/src/translations/tr.json +10 -1
  32. package/app/javascript/src/translations/uk.json +10 -1
  33. package/app/javascript/src/translations/vi.json +10 -1
  34. package/app/javascript/src/translations/zh-CN.json +10 -1
  35. package/app/javascript/src/translations/zh-TW.json +10 -1
  36. package/package.json +1 -1
  37. package/dist/BuildForm.js +0 -3077
  38. package/dist/BuildForm.js.map +0 -1
  39. package/dist/ExternalForm.js +0 -647
  40. package/dist/ExternalForm.js.map +0 -1
  41. package/dist/NeetoFormProvider.js +0 -11
  42. package/dist/NeetoFormProvider.js.map +0 -1
  43. package/dist/Submission.js +0 -2832
  44. package/dist/Submission.js.map +0 -1
  45. package/dist/UrlBuilder.js +0 -317
  46. package/dist/UrlBuilder.js.map +0 -1
  47. package/dist/buildForm-CrOWLvLE.js +0 -35
  48. package/dist/buildForm-CrOWLvLE.js.map +0 -1
  49. package/dist/buildForm-DfMpfuSp.js +0 -38
  50. package/dist/buildForm-DfMpfuSp.js.map +0 -1
  51. package/dist/cjs/BuildForm.js +0 -3098
  52. package/dist/cjs/BuildForm.js.map +0 -1
  53. package/dist/cjs/ExternalForm.js +0 -649
  54. package/dist/cjs/ExternalForm.js.map +0 -1
  55. package/dist/cjs/NeetoFormProvider.js +0 -13
  56. package/dist/cjs/NeetoFormProvider.js.map +0 -1
  57. package/dist/cjs/Submission.js +0 -2834
  58. package/dist/cjs/Submission.js.map +0 -1
  59. package/dist/cjs/UrlBuilder.js +0 -319
  60. package/dist/cjs/UrlBuilder.js.map +0 -1
  61. package/dist/cjs/hooks.js +0 -33
  62. package/dist/cjs/hooks.js.map +0 -1
  63. package/dist/cjs/index.js +0 -113
  64. package/dist/cjs/index.js.map +0 -1
  65. package/dist/constants-Cj0XxE8a.js +0 -494
  66. package/dist/constants-Cj0XxE8a.js.map +0 -1
  67. package/dist/constants-D5JlvWws.js +0 -513
  68. package/dist/constants-D5JlvWws.js.map +0 -1
  69. package/dist/hooks.js +0 -20
  70. package/dist/hooks.js.map +0 -1
  71. package/dist/index-Beo6ztaM.js +0 -51
  72. package/dist/index-Beo6ztaM.js.map +0 -1
  73. package/dist/index-DhtQJpD_.js +0 -43
  74. package/dist/index-DhtQJpD_.js.map +0 -1
  75. package/dist/index.js +0 -95
  76. package/dist/index.js.map +0 -1
  77. package/dist/main.css +0 -2
  78. package/dist/main.css.map +0 -1
  79. package/dist/useFormSubmission-D3O7sDHp.js +0 -24
  80. package/dist/useFormSubmission-D3O7sDHp.js.map +0 -1
  81. package/dist/useFormSubmission-PLRMfzJ3.js +0 -22
  82. package/dist/useFormSubmission-PLRMfzJ3.js.map +0 -1
  83. package/dist/utils-CI844li1.js +0 -2718
  84. package/dist/utils-CI844li1.js.map +0 -1
  85. package/dist/utils-baAzU7l8.js +0 -2749
  86. package/dist/utils-baAzU7l8.js.map +0 -1
  87. package/dist/yup-CSYHMEsr.js +0 -1014
  88. package/dist/yup-CSYHMEsr.js.map +0 -1
  89. package/dist/yup-DMlViLLB.js +0 -1097
  90. package/dist/yup-DMlViLLB.js.map +0 -1
@@ -1,647 +0,0 @@
1
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
- import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
3
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
- import _regeneratorRuntime from '@babel/runtime/regenerator';
5
- import { memo, useRef, useEffect, useState } from 'react';
6
- import { useQueryClient } from '@tanstack/react-query';
7
- import classnames from 'classnames';
8
- import { Formik, Form } from 'formik';
9
- import i18next from 'i18next';
10
- import { isPresent, noop, removeBy } from '@bigbinary/neeto-cist';
11
- import useHotkeys from '@bigbinary/neeto-hotkeys';
12
- import Warning from '@bigbinary/neeto-icons/Warning';
13
- import Typography from '@bigbinary/neetoui/Typography';
14
- import Button$1 from '@bigbinary/neetoui/Button';
15
- import Spinner$2 from '@bigbinary/neetoui/Spinner';
16
- import NeetoUICallout from '@bigbinary/neetoui/Callout';
17
- import NoData from '@bigbinary/neetoui/NoData';
18
- import { not, path, equals, isEmpty } from 'ramda';
19
- import { I18nextProvider, useTranslation } from 'react-i18next';
20
- import { d as usePublicForm, g as useCreateSubmission, h as useUpdateSubmission, f as useSubmission, i as QUERY_KEYS } from './constants-Cj0XxE8a.js';
21
- import Close from '@bigbinary/neeto-icons/Close';
22
- import { a as isBlank, g as getComponentDisplayName, p as parseServerError } from './index-DhtQJpD_.js';
23
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
24
- import Check from '@bigbinary/neeto-icons/Check';
25
- import { jsx, jsxs } from 'react/jsx-runtime';
26
- import { C as CALLOUT_POSITIONS, b as CALLOUT_STYLES, L as LAST_ELEMENTS_THRESHOLD, a as QUESTION_KIND } from './yup-CSYHMEsr.js';
27
- import { c as clientI18nInstance, d as getWithExpiry, e as clearEmailVerificationDetails, F as FormikWrap, g as getFieldComponent, b as buildAutoCompleteAttribute, r as renderButtonsInOrder, m as mergeRefs, a as generateInitValues, f as generateFormResponse, h as clearLocalStorageValues } from './utils-CI844li1.js';
28
- import { getQueryParams } from '@bigbinary/neeto-commons-frontend/utils';
29
- import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
30
- import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
31
- import '@babel/runtime/helpers/toConsumableArray';
32
- import '@bigbinary/neeto-commons-frontend/constants';
33
- import 'axios';
34
- import '@babel/runtime/helpers/typeof';
35
- import '@bigbinary/neeto-editor/utils';
36
- import 'dompurify';
37
- import '@bigbinary/neeto-icons/Plus';
38
- import 'yup';
39
- import 'libphonenumber-js';
40
- import '@bigbinary/neeto-editor/EditorContent';
41
- import '@bigbinary/neetoui/MultiEmailInput';
42
- import '@bigbinary/neeto-molecules/PhoneNumber';
43
- import '@babel/runtime/helpers/toArray';
44
- import '@bigbinary/neetoui/Select';
45
- import '@bigbinary/neetoui/Input';
46
- import '@bigbinary/neeto-icons/Refresh';
47
- import '@bigbinary/neeto-commons-frontend/initializers';
48
- import 'react-google-recaptcha';
49
- import '@bigbinary/neetoui/Checkbox';
50
- import '@bigbinary/neetoui/DatePicker';
51
- import '@bigbinary/neetoui/Toastr';
52
- import '@bigbinary/neeto-icons/CheckCircle';
53
- import '@bigbinary/neeto-molecules/FileUpload';
54
- import '@bigbinary/neetoui/Label';
55
- import '@bigbinary/neetoui/Radio';
56
- import '@bigbinary/neeto-icons/Image';
57
- import '@bigbinary/neeto-editor/Editor';
58
- import '@bigbinary/neeto-icons/Info';
59
- import '@bigbinary/neetoui/Textarea';
60
- import '@bigbinary/neetoui/Tag';
61
-
62
- var Spinner$1 = function Spinner(_ref) {
63
- var _ref$size = _ref.size,
64
- size = _ref$size === void 0 ? 24 : _ref$size;
65
- return /*#__PURE__*/jsx("div", {
66
- className: "neeto-form-engine-spinner",
67
- children: /*#__PURE__*/jsx("svg", {
68
- fill: "none",
69
- height: size,
70
- viewBox: "0 0 25 24",
71
- width: size,
72
- xmlns: "http://www.w3.org/2000/svg",
73
- children: /*#__PURE__*/jsx("path", {
74
- d: "M12.5 5.00098V8.75M17.4401 7.04867L14.9888 9.5M19.5008 11.9994H15.5M17.4401 16.9372L14.9888 14.4859M12.5023 18.9979V15M7.5516 16.9372L10.4888 14M5.50391 11.9994H9.5M7.5516 7.04867L10.0029 9.5",
75
- stroke: "#87929D",
76
- strokeLinecap: "round",
77
- strokeLinejoin: "round",
78
- strokeWidth: "1.5"
79
- })
80
- })
81
- });
82
- };
83
- var Spinner = /*#__PURE__*/memo(Spinner$1);
84
-
85
- var _excluded = ["label", "loading", "success", "className"];
86
- 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; }
87
- function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
88
- var Button = function Button(_ref) {
89
- var label = _ref.label,
90
- _ref$loading = _ref.loading,
91
- loading = _ref$loading === void 0 ? false : _ref$loading,
92
- _ref$success = _ref.success,
93
- success = _ref$success === void 0 ? false : _ref$success,
94
- _ref$className = _ref.className,
95
- className = _ref$className === void 0 ? "" : _ref$className,
96
- otherProps = _objectWithoutProperties(_ref, _excluded);
97
- return /*#__PURE__*/jsxs("button", _objectSpread$2(_objectSpread$2({
98
- className: classnames("neeto-form-engine-button", className)
99
- }, otherProps), {}, {
100
- children: [loading && /*#__PURE__*/jsx(ButtonLoader, {}), success && /*#__PURE__*/jsx(Success$2, {}), label]
101
- }));
102
- };
103
- var ButtonLoader = function ButtonLoader() {
104
- return /*#__PURE__*/jsx("div", {
105
- className: "neeto-form-engine-button__loader",
106
- children: /*#__PURE__*/jsx(Spinner, {})
107
- });
108
- };
109
- var Success$2 = function Success() {
110
- return /*#__PURE__*/jsx("div", {
111
- className: "neeto-form-engine-button__success",
112
- children: /*#__PURE__*/jsx(Check, {})
113
- });
114
- };
115
-
116
- var Callout = function Callout(_ref) {
117
- var _ref$style = _ref.style,
118
- style = _ref$style === void 0 ? CALLOUT_STYLES.ERROR : _ref$style,
119
- _ref$position = _ref.position,
120
- position = _ref$position === void 0 ? CALLOUT_POSITIONS.ABSOLUTE : _ref$position,
121
- _ref$callout = _ref.callout,
122
- callout = _ref$callout === void 0 ? {} : _ref$callout,
123
- children = _ref.children,
124
- className = _ref.className,
125
- onClose = _ref.onClose;
126
- var isVisible = callout.isVisible,
127
- title = callout.title,
128
- message = callout.message,
129
- primaryButton = callout.primaryButton,
130
- secondaryButton = callout.secondaryButton;
131
- if (!isVisible) return null;
132
- return /*#__PURE__*/jsxs("div", {
133
- className: classnames("neeto-form-engine-callout", _defineProperty({
134
- "neeto-form-engine-callout--error": style === CALLOUT_STYLES.ERROR,
135
- "neeto-form-engine-callout--info": style === CALLOUT_STYLES.INFO,
136
- "neeto-form-engine-callout--static": position === CALLOUT_POSITIONS.STATIC,
137
- "neeto-form-engine-callout--absolute": position === CALLOUT_POSITIONS.ABSOLUTE
138
- }, className, className)),
139
- children: [isPresent(onClose) && /*#__PURE__*/jsx("button", {
140
- className: "neeto-form-engine-callout__close",
141
- onClick: onClose,
142
- children: /*#__PURE__*/jsx(Close, {
143
- size: 16
144
- })
145
- }), /*#__PURE__*/jsxs("div", {
146
- className: "neeto-form-engine-callout__content",
147
- children: [not(isBlank(title)) && /*#__PURE__*/jsx("h5", {
148
- children: title
149
- }), /*#__PURE__*/jsx("p", {
150
- children: message
151
- })]
152
- }), primaryButton && /*#__PURE__*/jsx(Button, {
153
- label: primaryButton.label,
154
- size: "small",
155
- onClick: primaryButton.onClick
156
- }), secondaryButton && /*#__PURE__*/jsx(Button, {
157
- label: secondaryButton.label,
158
- size: "small",
159
- onClick: secondaryButton.onClick
160
- }), children]
161
- });
162
- };
163
-
164
- 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; }
165
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
166
- var withI18nInstance = function withI18nInstance(Component, i18n) {
167
- var I18nWrapper = function I18nWrapper(props) {
168
- return /*#__PURE__*/jsx(I18nextProvider, {
169
- i18n: i18n,
170
- children: /*#__PURE__*/jsx(Component, _objectSpread$1({}, props))
171
- });
172
- };
173
- I18nWrapper.displayName = "I18nWrapper(".concat(getComponentDisplayName(Component), ")");
174
- return I18nWrapper;
175
- };
176
-
177
- var useIsMounted = function useIsMounted() {
178
- var isMounted = useRef(true);
179
- useEffect(function () {
180
- return function () {
181
- isMounted.current = false;
182
- };
183
- }, []);
184
- return function () {
185
- return isMounted.current;
186
- };
187
- };
188
-
189
- var Success$1 = withT(function (_ref) {
190
- var t = _ref.t;
191
- return /*#__PURE__*/jsxs("div", {
192
- className: "neeto-form-nano-external-form-thank-you flex h-full w-full flex-col items-center justify-center space-y-3 py-20",
193
- children: [/*#__PURE__*/jsx(Typography, {
194
- style: "h1",
195
- children: "\uD83C\uDF89"
196
- }), /*#__PURE__*/jsx(Typography, {
197
- className: "text-center",
198
- style: "h2",
199
- children: t("neetoForm.successPage.title1")
200
- }), /*#__PURE__*/jsx(Typography, {
201
- className: "text-center",
202
- style: "body2",
203
- children: t("neetoForm.successPage.title2")
204
- })]
205
- });
206
- });
207
- var Success = /*#__PURE__*/memo(Success$1);
208
-
209
- 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; }
210
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
211
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: true } : { done: false, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = true, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
212
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
213
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
214
- var ExternalForm = function ExternalForm(_ref) {
215
- var _path, _formikInnerRef$curre;
216
- var _ref$size = _ref.size,
217
- size = _ref$size === void 0 ? "medium" : _ref$size,
218
- _ref$preview = _ref.preview,
219
- preview = _ref$preview === void 0 ? false : _ref$preview,
220
- formId = _ref.formId,
221
- submissionId = _ref.submissionId,
222
- customSubmitHandler = _ref.customSubmitHandler,
223
- onBeforeSubmit = _ref.onBeforeSubmit,
224
- onSubmitSuccess = _ref.onSubmitSuccess,
225
- _ref$showTitle = _ref.showTitle,
226
- showTitle = _ref$showTitle === void 0 ? true : _ref$showTitle,
227
- formTitle = _ref.formTitle,
228
- submitButtonProps = _ref.submitButtonProps,
229
- cancelButtonProps = _ref.cancelButtonProps,
230
- resetButtonProps = _ref.resetButtonProps,
231
- _ref$displayThankYou = _ref.displayThankYou,
232
- displayThankYou = _ref$displayThankYou === void 0 ? true : _ref$displayThankYou,
233
- _ref$showEmptyState = _ref.showEmptyState,
234
- showEmptyState = _ref$showEmptyState === void 0 ? true : _ref$showEmptyState,
235
- className = _ref.className,
236
- _ref$preserveValues = _ref.preserveValues,
237
- preserveValues = _ref$preserveValues === void 0 ? false : _ref$preserveValues,
238
- _ref$clearValuesOnRes = _ref.clearValuesOnReset,
239
- clearValuesOnReset = _ref$clearValuesOnRes === void 0 ? false : _ref$clearValuesOnRes,
240
- _ref$clearValuesOnSub = _ref.clearValuesOnSubmit,
241
- clearValuesOnSubmit = _ref$clearValuesOnSub === void 0 ? false : _ref$clearValuesOnSub,
242
- _ref$initialValues = _ref.initialValues,
243
- initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
244
- onChange = _ref.onChange,
245
- formDomProps = _ref.formDomProps,
246
- _ref$editorProps = _ref.editorProps,
247
- editorProps = _ref$editorProps === void 0 ? {} : _ref$editorProps,
248
- customValidator = _ref.customValidator,
249
- _ref$autoCompleteKind = _ref.autoCompleteKinds,
250
- autoCompleteKinds = _ref$autoCompleteKind === void 0 ? [] : _ref$autoCompleteKind,
251
- _ref$enablePreFilling = _ref.enablePreFilling,
252
- enablePreFilling = _ref$enablePreFilling === void 0 ? false : _ref$enablePreFilling,
253
- _ref$language = _ref.language,
254
- language = _ref$language === void 0 ? i18next.resolvedLanguage : _ref$language,
255
- _ref$remainingSlotsCo = _ref.remainingSlotsCount,
256
- remainingSlotsCount = _ref$remainingSlotsCo === void 0 ? null : _ref$remainingSlotsCo;
257
- var _useState = useState(false),
258
- _useState2 = _slicedToArray(_useState, 2),
259
- isSubmitted = _useState2[0],
260
- setIsSubmitted = _useState2[1];
261
- var _useState3 = useState(false),
262
- _useState4 = _slicedToArray(_useState3, 2),
263
- showSuccess = _useState4[0],
264
- setShowSuccess = _useState4[1];
265
- var _useState5 = useState(getWithExpiry("".concat(formId, "/values"))),
266
- _useState6 = _slicedToArray(_useState5, 2),
267
- localValues = _useState6[0],
268
- setLocalValues = _useState6[1];
269
- var isMounted = useIsMounted();
270
- var _useState7 = useState(null),
271
- _useState8 = _slicedToArray(_useState7, 2),
272
- error = _useState8[0],
273
- setError = _useState8[1];
274
- var formRef = useRef();
275
- var formikInnerRef = useRef();
276
- var editorRef = useRef();
277
- var captchaRef = useRef(null);
278
- var queryClient = useQueryClient();
279
- var _usePublicForm = usePublicForm({
280
- formId: formId,
281
- language: language,
282
- preview: preview,
283
- enabled: !preview
284
- }),
285
- _usePublicForm$data = _usePublicForm.data,
286
- form = _usePublicForm$data === void 0 ? {
287
- title: "",
288
- questions: [],
289
- isQuestionsLoading: true
290
- } : _usePublicForm$data,
291
- isLoading = _usePublicForm.isLoading;
292
- var title = form.title,
293
- _form$questions = form.questions,
294
- questions = _form$questions === void 0 ? [] : _form$questions;
295
- var formUuid = (_path = path([0, "formId"], questions)) !== null && _path !== void 0 ? _path : formId;
296
- useEffect(function () {
297
- if (equals(language, clientI18nInstance.resolvedLanguage)) return;
298
- clientI18nInstance.changeLanguage(language);
299
- }, [language]);
300
- useEffect(function () {
301
- if (!preserveValues) clearEmailVerificationDetails(formUuid);
302
- }, []);
303
- var _useTranslation = useTranslation(),
304
- t = _useTranslation.t;
305
- useEffect(function () {
306
- setLocalValues(getWithExpiry("".concat(formId, "/values")));
307
- }, [formId]);
308
- var _useCreateSubmission = useCreateSubmission({
309
- enabled: !submissionId
310
- }),
311
- createSubmission = _useCreateSubmission.mutateAsync;
312
- var _useUpdateSubmission = useUpdateSubmission({
313
- enabled: !!submissionId
314
- }),
315
- updateSubmission = _useUpdateSubmission.mutateAsync;
316
- var _useSubmission = useSubmission({
317
- formId: formId,
318
- submissionId: submissionId,
319
- placeholderData: submissionId ? {
320
- responses: [],
321
- isLoading: true
322
- } : {},
323
- enabled: !!submissionId
324
- }),
325
- submission = _useSubmission.data;
326
- var clearLocalFormValues = function clearLocalFormValues() {
327
- return clearLocalStorageValues("".concat(formId, "/values"));
328
- };
329
- var onSubmit = /*#__PURE__*/function () {
330
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(values, _ref2) {
331
- var setSubmitting, responses, newResponses, data;
332
- return _regeneratorRuntime.wrap(function _callee$(_context) {
333
- while (1) switch (_context.prev = _context.next) {
334
- case 0:
335
- setSubmitting = _ref2.setSubmitting;
336
- setError(null);
337
- responses = generateFormResponse(values, questions);
338
- _context.prev = 3;
339
- if (!preview) {
340
- _context.next = 9;
341
- break;
342
- }
343
- _context.next = 7;
344
- return new Promise(function (resolve) {
345
- return setTimeout(function () {
346
- resolve();
347
- setIsSubmitted(true);
348
- setTimeout(function () {
349
- return setShowSuccess(true);
350
- }, 1000);
351
- }, 1500);
352
- });
353
- case 7:
354
- _context.next = 34;
355
- break;
356
- case 9:
357
- if (!onBeforeSubmit) {
358
- _context.next = 14;
359
- break;
360
- }
361
- _context.next = 12;
362
- return onBeforeSubmit(responses, values);
363
- case 12:
364
- newResponses = _context.sent;
365
- if (newResponses) {
366
- responses = newResponses;
367
- }
368
- case 14:
369
- if (!customSubmitHandler) {
370
- _context.next = 21;
371
- break;
372
- }
373
- _context.next = 17;
374
- return customSubmitHandler({
375
- responses: responses,
376
- values: values
377
- }, clearLocalFormValues);
378
- case 17:
379
- data = _context.sent;
380
- queryClient.invalidateQueries({
381
- queryKey: [QUERY_KEYS.SUBMISSION, formId, submissionId]
382
- });
383
- _context.next = 30;
384
- break;
385
- case 21:
386
- if (!submissionId) {
387
- _context.next = 27;
388
- break;
389
- }
390
- _context.next = 24;
391
- return updateSubmission({
392
- formId: formId,
393
- values: {
394
- neetoFormResponse: {
395
- submissionId: submissionId,
396
- responses: responses
397
- }
398
- }
399
- });
400
- case 24:
401
- data = _context.sent;
402
- _context.next = 30;
403
- break;
404
- case 27:
405
- _context.next = 29;
406
- return createSubmission({
407
- formId: formId,
408
- values: {
409
- neetoFormResponse: {
410
- responses: responses
411
- }
412
- }
413
- });
414
- case 29:
415
- data = _context.sent;
416
- case 30:
417
- clearValuesOnSubmit && clearLocalFormValues();
418
- setTimeout(function () {
419
- return clearEmailVerificationDetails(formUuid);
420
- }, 1000);
421
- onSubmitSuccess === null || onSubmitSuccess === void 0 || onSubmitSuccess({
422
- values: values,
423
- responses: responses,
424
- data: data
425
- }, clearLocalFormValues);
426
- if (isMounted()) {
427
- setIsSubmitted(true);
428
- setTimeout(function () {
429
- return setShowSuccess(true);
430
- }, 1000);
431
- }
432
- case 34:
433
- _context.next = 39;
434
- break;
435
- case 36:
436
- _context.prev = 36;
437
- _context.t0 = _context["catch"](3);
438
- setError(parseServerError(_context.t0));
439
- case 39:
440
- _context.prev = 39;
441
- if (isMounted()) {
442
- setSubmitting(false);
443
- }
444
- return _context.finish(39);
445
- case 42:
446
- case "end":
447
- return _context.stop();
448
- }
449
- }, _callee, null, [[3, 36, 39, 42]]);
450
- }));
451
- return function onSubmit(_x, _x2) {
452
- return _ref3.apply(this, arguments);
453
- };
454
- }();
455
- var _onReset = function onReset(e, handleReset) {
456
- var _editorRef$current, _captchaRef$current, _formDomProps$onReset;
457
- if (clearValuesOnReset) {
458
- clearLocalStorageValues("".concat(formId, "/values"));
459
- setLocalValues(generateInitValues({
460
- questions: questions
461
- }));
462
- submissionId && queryClient.setQueryData([QUERY_KEYS.SUBMISSION, formId, submissionId], {
463
- responses: []
464
- });
465
- }
466
- editorRef === null || editorRef === void 0 || (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || (_editorRef$current = _editorRef$current.editor) === null || _editorRef$current === void 0 || (_editorRef$current = _editorRef$current.commands) === null || _editorRef$current === void 0 || _editorRef$current.setContent("");
467
- (_captchaRef$current = captchaRef.current) === null || _captchaRef$current === void 0 || _captchaRef$current.reset();
468
- handleReset(e);
469
- formDomProps === null || formDomProps === void 0 || (_formDomProps$onReset = formDomProps.onReset) === null || _formDomProps$onReset === void 0 || _formDomProps$onReset.call(formDomProps, e);
470
- clearEmailVerificationDetails(formUuid);
471
- };
472
- var handleScrollToError = function handleScrollToError(errors) {
473
- if (!formRef.current) return;
474
- var errorKeys = Object.keys(errors);
475
- if (isEmpty(errorKeys)) return;
476
- var _iterator = _createForOfIteratorHelper(formRef.current),
477
- _step;
478
- try {
479
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
480
- var formElement = _step.value;
481
- if (errorKeys.includes(formElement.name)) {
482
- formElement.scrollIntoView({
483
- behavior: "smooth",
484
- block: "center"
485
- });
486
- break;
487
- }
488
- }
489
- } catch (err) {
490
- _iterator.e(err);
491
- } finally {
492
- _iterator.f();
493
- }
494
- };
495
- var _queryClient$getQuery = queryClient.getQueryState([QUERY_KEYS.QUESTIONS, formId, language]),
496
- dataUpdateCount = _queryClient$getQuery.dataUpdateCount;
497
- var keyPressRef = useHotkeys("command+enter", ((_formikInnerRef$curre = formikInnerRef.current) === null || _formikInnerRef$curre === void 0 ? void 0 : _formikInnerRef$curre.handleSubmit) || noop, {
498
- mode: "scoped"
499
- });
500
- if (isLoading || form.isQuestionsLoading || !!submissionId && submission !== null && submission !== void 0 && submission.isLoading) {
501
- return /*#__PURE__*/jsx("div", {
502
- className: "loader flex h-full w-full items-center justify-center",
503
- children: /*#__PURE__*/jsx(PageLoader, {})
504
- });
505
- }
506
- var displayTitle = formTitle || title;
507
- var renderedQuestions = preview ? questions : removeBy({
508
- isHidden: true
509
- }, questions);
510
- if (displayThankYou && showSuccess) {
511
- return /*#__PURE__*/jsx(Success, {});
512
- }
513
- return /*#__PURE__*/jsxs("div", {
514
- className: classnames("neeto-form-nano-external-form", {
515
- "neeto-form-nano-external-form--size-large": size === "large",
516
- "neeto-form-nano-external-form--size-medium": size === "medium"
517
- }),
518
- children: [showTitle && displayTitle && /*#__PURE__*/jsx("div", {
519
- className: "neeto-form-nano-external-form-header py-6",
520
- children: /*#__PURE__*/jsx(Typography, {
521
- className: "neeto-ui-text-gray-800 neeto-form-nano-external-form-title",
522
- style: "h4",
523
- weight: "semibold",
524
- children: displayTitle
525
- })
526
- }), /*#__PURE__*/jsx(Formik, {
527
- onSubmit: onSubmit,
528
- enableReinitialize: true,
529
- innerRef: formikInnerRef,
530
- initialValues: generateInitValues({
531
- questions: questions,
532
- initialValues: submission === null || submission === void 0 ? void 0 : submission.responses,
533
- localValues: preserveValues ? localValues : initialValues,
534
- fieldCodes: enablePreFilling ? getQueryParams({
535
- toCamelCase: false
536
- }) : {},
537
- remainingSlotsCount: remainingSlotsCount
538
- }),
539
- children: function children(_ref4) {
540
- var isSubmitting = _ref4.isSubmitting,
541
- errors = _ref4.errors,
542
- setFieldError = _ref4.setFieldError,
543
- handleReset = _ref4.handleReset;
544
- return /*#__PURE__*/jsxs(FormikWrap, {
545
- dataUpdateCount: dataUpdateCount,
546
- formId: formId,
547
- preserveValues: preserveValues,
548
- onError: handleScrollToError,
549
- onValuesChange: onChange,
550
- children: [/*#__PURE__*/jsxs(Form, _objectSpread(_objectSpread({
551
- noValidate: true,
552
- ref: mergeRefs(formRef, keyPressRef),
553
- className: classnames("neeto-form-engine-form relative", _defineProperty({
554
- "space-y-6": size === "large",
555
- "space-y-4": size === "medium"
556
- }, className, className)),
557
- onChange: function onChange(event) {
558
- if (isEmpty(errors)) return;
559
- setFieldError(event.target.name, "");
560
- }
561
- }, formDomProps), {}, {
562
- onReset: function onReset(e) {
563
- return _onReset(e, handleReset);
564
- },
565
- children: [(submission === null || submission === void 0 ? void 0 : submission.isLoading) && /*#__PURE__*/jsx("div", {
566
- className: "neeto-ui-bg-gray-100 absolute bottom-0 start-0 end-0 top-0 flex items-center justify-center opacity-75",
567
- children: /*#__PURE__*/jsx(Spinner$2, {})
568
- }), renderedQuestions.map(function (question, index) {
569
- var _question$id;
570
- var FieldComponent = getFieldComponent(question);
571
- var isLastFewElements = index >= renderedQuestions.length - LAST_ELEMENTS_THRESHOLD;
572
- return /*#__PURE__*/jsxs("div", {
573
- className: "w-full flex flex-col gap-2",
574
- children: [/*#__PURE__*/jsx(FieldComponent, _objectSpread(_objectSpread({}, _objectSpread({
575
- captchaRef: captchaRef,
576
- editorProps: editorProps,
577
- editorRef: editorRef,
578
- isLastFewElements: isLastFewElements,
579
- preview: preview,
580
- question: question
581
- }, question.kind === QUESTION_KIND.SPOT.value && typeof remainingSlotsCount === "number" && {
582
- remainingSlotsCount: remainingSlotsCount
583
- })), {}, {
584
- customValidator: customValidator === null || customValidator === void 0 ? void 0 : customValidator(question),
585
- autoComplete: buildAutoCompleteAttribute(question.kind, autoCompleteKinds, formDomProps)
586
- })), question.isHidden && /*#__PURE__*/jsx(NeetoUICallout, {
587
- "data-testid": "hidden-question-callout",
588
- icon: Warning,
589
- style: "warning",
590
- children: /*#__PURE__*/jsx(Typography, {
591
- style: "body2",
592
- children: t("neetoForm.callouts.hiddenQuestion")
593
- })
594
- }), preview && question.isResponseVisibleOnlyToHost && /*#__PURE__*/jsx(NeetoUICallout, {
595
- "data-testid": "response-visible-only-to-host-callout",
596
- icon: Warning,
597
- style: "warning",
598
- children: /*#__PURE__*/jsx(Typography, {
599
- style: "body2",
600
- children: t("neetoForm.callouts.responseVisibleOnlyToHost")
601
- })
602
- })]
603
- }, (_question$id = question.id) !== null && _question$id !== void 0 ? _question$id : question.nodeId);
604
- }), showEmptyState && isEmpty(renderedQuestions) && /*#__PURE__*/jsx("div", {
605
- className: "flex w-full grow items-center justify-center py-8",
606
- children: /*#__PURE__*/jsx(NoData, {
607
- className: "min-h-80",
608
- title: t("neetoForm.questions.common.noData")
609
- })
610
- }), !isEmpty(renderedQuestions) && /*#__PURE__*/jsxs("div", {
611
- className: "neeto-form-nano-form-footer mt-8 flex items-center justify-between",
612
- children: [cancelButtonProps && /*#__PURE__*/jsx(Button$1, _objectSpread({
613
- label: t("neetoForm.common.cancel"),
614
- style: "secondary"
615
- }, cancelButtonProps)), /*#__PURE__*/jsx("div", {
616
- className: "flex gap-x-2",
617
- children: renderButtonsInOrder([/*#__PURE__*/jsx(Button$1, _objectSpread({
618
- disabled: isSubmitting || isSubmitted,
619
- label: t("neetoForm.common.submit"),
620
- loading: isSubmitting,
621
- type: "submit"
622
- }, submitButtonProps), "submit"), /*#__PURE__*/jsx(Button$1, _objectSpread({
623
- label: t("neetoForm.common.reset"),
624
- style: "secondary",
625
- type: "reset"
626
- }, resetButtonProps), "reset")], isPresent(cancelButtonProps))
627
- })]
628
- })]
629
- })), !customSubmitHandler && /*#__PURE__*/jsx(Callout, {
630
- callout: {
631
- isVisible: isPresent(error),
632
- title: t("neetoForm.callouts.submitError"),
633
- message: error
634
- },
635
- onClose: function onClose() {
636
- return setError(null);
637
- }
638
- })]
639
- });
640
- }
641
- })]
642
- });
643
- };
644
- var index = withI18nInstance(ExternalForm, clientI18nInstance);
645
-
646
- export { index as default };
647
- //# sourceMappingURL=ExternalForm.js.map