@bigbinary/neeto-form-frontend 4.4.26 → 4.4.28

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