@bigbinary/neeto-form-frontend 3.3.2 → 3.4.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.
Files changed (62) hide show
  1. package/app/javascript/src/translations/en.json +3 -3
  2. package/dist/BuildForm.js +2358 -0
  3. package/dist/BuildForm.js.map +1 -0
  4. package/dist/ExternalForm.js +657 -0
  5. package/dist/ExternalForm.js.map +1 -0
  6. package/dist/NeetoFormProvider.js +11 -0
  7. package/dist/NeetoFormProvider.js.map +1 -0
  8. package/dist/Submission.js +2700 -0
  9. package/dist/Submission.js.map +1 -0
  10. package/dist/UrlBuilder.js +297 -0
  11. package/dist/UrlBuilder.js.map +1 -0
  12. package/dist/buildForm-4a5a5251.js +35 -0
  13. package/dist/buildForm-4a5a5251.js.map +1 -0
  14. package/dist/buildForm-77b32f08.js +42 -0
  15. package/dist/buildForm-77b32f08.js.map +1 -0
  16. package/dist/cjs/BuildForm.js +2416 -0
  17. package/dist/cjs/BuildForm.js.map +1 -0
  18. package/dist/cjs/ExternalForm.js +697 -0
  19. package/dist/cjs/ExternalForm.js.map +1 -0
  20. package/dist/cjs/NeetoFormProvider.js +13 -0
  21. package/dist/cjs/NeetoFormProvider.js.map +1 -0
  22. package/dist/cjs/Submission.js +2711 -0
  23. package/dist/cjs/Submission.js.map +1 -0
  24. package/dist/cjs/UrlBuilder.js +308 -0
  25. package/dist/cjs/UrlBuilder.js.map +1 -0
  26. package/dist/cjs/hooks.js +34 -0
  27. package/dist/cjs/hooks.js.map +1 -0
  28. package/dist/cjs/index.js +115 -0
  29. package/dist/cjs/index.js.map +1 -0
  30. package/dist/constants-9310a7c2.js +342 -0
  31. package/dist/constants-9310a7c2.js.map +1 -0
  32. package/dist/constants-f0f38e6f.js +378 -0
  33. package/dist/constants-f0f38e6f.js.map +1 -0
  34. package/dist/hooks.js +20 -0
  35. package/dist/hooks.js.map +1 -0
  36. package/dist/index-2664c3e7.js +39 -0
  37. package/dist/index-2664c3e7.js.map +1 -0
  38. package/dist/index-b6bb805c.js +46 -0
  39. package/dist/index-b6bb805c.js.map +1 -0
  40. package/dist/index.js +94 -9325
  41. package/dist/index.js.map +1 -1
  42. package/dist/main.css +12 -1
  43. package/dist/main.css.map +1 -1
  44. package/dist/no-questions-832318c3.js +487 -0
  45. package/dist/no-questions-832318c3.js.map +1 -0
  46. package/dist/no-questions-995fd77e.js +538 -0
  47. package/dist/no-questions-995fd77e.js.map +1 -0
  48. package/dist/useFormApi-ca36173e.js +492 -0
  49. package/dist/useFormApi-ca36173e.js.map +1 -0
  50. package/dist/useFormApi-d733cb8d.js +467 -0
  51. package/dist/useFormApi-d733cb8d.js.map +1 -0
  52. package/dist/useFormSubmission-866195bb.js +24 -0
  53. package/dist/useFormSubmission-866195bb.js.map +1 -0
  54. package/dist/useFormSubmission-f8866b84.js +22 -0
  55. package/dist/useFormSubmission-f8866b84.js.map +1 -0
  56. package/dist/utils-7000103c.js +2157 -0
  57. package/dist/utils-7000103c.js.map +1 -0
  58. package/dist/utils-a487b8ff.js +2221 -0
  59. package/dist/utils-a487b8ff.js.map +1 -0
  60. package/package.json +19 -7
  61. package/dist/index.cjs.js +0 -9424
  62. package/dist/index.cjs.js.map +0 -1
@@ -0,0 +1,2358 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import { useState, createElement, useRef, useEffect } from 'react';
3
+ import { useQueryClient } from '@tanstack/react-query';
4
+ import classnames from 'classnames';
5
+ import { useFormikContext, useField, FieldArray, Form as Form$3, Formik } from 'formik';
6
+ import { isPresent, truncate, findBy, slugify, filterBy, hyphenate, noop, nullSafe, removeBy } from '@bigbinary/neeto-cist';
7
+ import { showThumbsUpToastr, hyphenize } from '@bigbinary/neeto-commons-frontend/utils';
8
+ import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
9
+ import { equals, includes, __, reduce, assoc, when, isEmpty, reject, keys, pick, omit, pluck, modify, without, path, mergeLeft, isNil, pipe, filter, isNotNil, uniq, join, map, test, difference, prop, split, last, concat } from 'ramda';
10
+ import { e as useDeleteQuestion, f as useFetchQuestions, g as useCreateQuestion, h as useUpdateQuestion, i as useReorderQuestions, Q as QUERY_KEYS } from './useFormApi-d733cb8d.js';
11
+ import { Q as QUESTION_KIND } from './constants-9310a7c2.js';
12
+ import { I as INDEPENDENT_LABELS_MAP, R as RICH_TEXT_QUESTIONS, h as htmlToPlainText, D as Drag, S as SELECTABLE_KINDS, a as RESERVED_FIELD_CODES, b as SvgNoQuestions, Q as QUESTION_TYPES, c as QUESTIONS_WITHOUT_FIELD_CODE, C as CAPTCHA_TYPES, F as FILE_TYPES_MAP, d as FILE_GROUPS, M as MINIMUM_OPTIONS, e as RATING_OPTIONS, f as STAR_RATING_MIN_VALUE_OPTIONS, g as STAR_RATING_MAX_VALUE_OPTIONS, i as STAR_RATING_ICONS_MAP, j as QUESTION_ACTIONS, k as QUESTION_KINDS, l as getActiveQuestionKindDetails, m as DEFAULT_AVAILABLE_LANGUAGES, n as QUESTIONS_INITIAL_VALUE, o as MANDATORY_KINDS } from './no-questions-832318c3.js';
13
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
14
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
15
+ import { Droppable, Draggable, DragDropContext } from '@hello-pangea/dnd';
16
+ import { isMetaKeyPressed, withT, useStateWithDependency, useOnClickOutside } from '@bigbinary/neeto-commons-frontend/react-utils';
17
+ import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
18
+ import { useTranslation, Trans } from 'react-i18next';
19
+ import { a as useBuildFormStore } from './buildForm-4a5a5251.js';
20
+ import { shallow } from 'zustand/shallow';
21
+ import Alert from '@bigbinary/neetoui/Alert';
22
+ import { f as fieldWithFallback, i as isFunction } from './index-2664c3e7.js';
23
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
24
+ import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
25
+ import Typography from '@bigbinary/neetoui/Typography';
26
+ import Dropdown from '@bigbinary/neetoui/Dropdown';
27
+ import Tooltip from '@bigbinary/neetoui/Tooltip';
28
+ import { t } from 'i18next';
29
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
30
+ import Pane from '@bigbinary/neetoui/Pane';
31
+ import Form$2 from '@bigbinary/neetoui/formik/Form';
32
+ import Select from '@bigbinary/neetoui/formik/Select';
33
+ import Switch from '@bigbinary/neetoui/formik/Switch';
34
+ import Textarea from '@bigbinary/neetoui/formik/Textarea';
35
+ import NeetoEditor from '@bigbinary/neeto-editor/Editor';
36
+ import Button from '@bigbinary/neetoui/Button';
37
+ import Accordion from '@bigbinary/neetoui/Accordion';
38
+ import Input from '@bigbinary/neetoui/formik/Input';
39
+ import { isEditorEmpty } from '@bigbinary/neeto-editor/utils';
40
+ import * as yup from 'yup';
41
+ import Radio from '@bigbinary/neetoui/formik/Radio';
42
+ import HelpPopover from '@bigbinary/neeto-molecules/HelpPopover';
43
+ import Label from '@bigbinary/neetoui/Label';
44
+ import CreatableSelect from 'react-select/creatable';
45
+ import _toArray from '@babel/runtime/helpers/toArray';
46
+ import Close from '@bigbinary/neeto-icons/Close';
47
+ import Tag from '@bigbinary/neetoui/Tag';
48
+ import { components } from 'react-select';
49
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
50
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
51
+ import Checkbox$1 from '@bigbinary/neetoui/formik/Checkbox';
52
+ import Checkbox from '@bigbinary/neetoui/Checkbox';
53
+ import Delete from '@bigbinary/neeto-icons/Delete';
54
+ import Plus from '@bigbinary/neeto-icons/Plus';
55
+ import '@bigbinary/neeto-commons-frontend/constants';
56
+ import 'axios';
57
+ import 'dompurify';
58
+ import 'zustand';
59
+ import '@babel/runtime/helpers/typeof';
60
+
61
+ var DeleteAlert = function DeleteAlert(_ref) {
62
+ var selectedQuestion = _ref.selectedQuestion,
63
+ isOpen = _ref.isOpen,
64
+ onClose = _ref.onClose,
65
+ languagesCount = _ref.languagesCount,
66
+ handleSelect = _ref.handleSelect;
67
+ var _useTranslation = useTranslation(),
68
+ t = _useTranslation.t;
69
+ var _useBuildFormStore = useBuildFormStore(function (store) {
70
+ var _store$formState;
71
+ return {
72
+ selectedLanguage: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["selectedLanguage"]
73
+ };
74
+ }, shallow),
75
+ selectedLanguage = _useBuildFormStore.selectedLanguage;
76
+ var renderQuestionLabel = function renderQuestionLabel() {
77
+ var questionKind = selectedQuestion.kind;
78
+ var independentLabel = INDEPENDENT_LABELS_MAP[questionKind];
79
+ if (isPresent(independentLabel)) return independentLabel;
80
+ var questionLabel = fieldWithFallback(selectedQuestion, "label");
81
+ return truncate(questionLabel, 40);
82
+ };
83
+ var _useDeleteQuestion = useDeleteQuestion(selectedQuestion === null || selectedQuestion === void 0 ? void 0 : selectedQuestion.formId, selectedLanguage, {
84
+ onSuccess: function onSuccess() {
85
+ showThumbsUpToastr();
86
+ onClose();
87
+ }
88
+ }),
89
+ deleteQuestion = _useDeleteQuestion.mutate,
90
+ isDeleting = _useDeleteQuestion.isPending;
91
+ var selectNextQuestion = function selectNextQuestion(questions) {
92
+ var selectedQuestionIndex = selectedQuestion.displayOrder;
93
+ var wasLastQuestion = equals(selectedQuestionIndex, questions.length);
94
+ var newDisplayOrder = wasLastQuestion ? selectedQuestionIndex - 1 : selectedQuestionIndex;
95
+ var newQuestion = findBy({
96
+ displayOrder: newDisplayOrder
97
+ }, questions);
98
+ handleSelect(newQuestion);
99
+ };
100
+ var handleSubmit = function handleSubmit() {
101
+ deleteQuestion(selectedQuestion.id, {
102
+ onSuccess: function onSuccess(_ref2) {
103
+ var questions = _ref2.questions;
104
+ return selectNextQuestion(questions);
105
+ }
106
+ });
107
+ };
108
+ return /*#__PURE__*/jsx(Alert, {
109
+ isOpen: isOpen,
110
+ onClose: onClose,
111
+ isSubmitting: isDeleting,
112
+ submitButtonLabel: t("neetoForm.common.delete"),
113
+ title: t("neetoForm.questions.deleteAlert.title"),
114
+ message: isPresent(selectedQuestion) && /*#__PURE__*/jsx(Trans, {
115
+ i18nKey: "neetoForm.questions.deleteAlert.message",
116
+ values: {
117
+ count: languagesCount,
118
+ label: renderQuestionLabel()
119
+ }
120
+ }),
121
+ onSubmit: handleSubmit
122
+ });
123
+ };
124
+
125
+ var ChangeLanguageDropdown = function ChangeLanguageDropdown(_ref) {
126
+ var _findBy;
127
+ var currentLanguage = _ref.currentLanguage,
128
+ languages = _ref.languages,
129
+ onChange = _ref.onChange;
130
+ var _useState = useState(false),
131
+ _useState2 = _slicedToArray(_useState, 2),
132
+ isUnsavedChangesAlertOpen = _useState2[0],
133
+ setIsUnsavedChangesAlertOpen = _useState2[1];
134
+ var _useState3 = useState(currentLanguage),
135
+ _useState4 = _slicedToArray(_useState3, 2),
136
+ selectedLanguage = _useState4[0],
137
+ setSelectedLanguage = _useState4[1];
138
+ var _useTranslation = useTranslation(),
139
+ t = _useTranslation.t;
140
+ var _useFormikContext = useFormikContext(),
141
+ dirty = _useFormikContext.dirty;
142
+ var languageChangeHandler = function languageChangeHandler(code) {
143
+ if (!dirty) {
144
+ onChange(code);
145
+ return;
146
+ }
147
+ setSelectedLanguage(code);
148
+ setIsUnsavedChangesAlertOpen(true);
149
+ };
150
+ var selectedLanguageName = (_findBy = findBy({
151
+ code: currentLanguage
152
+ }, languages)) === null || _findBy === void 0 ? void 0 : _findBy.name;
153
+ return /*#__PURE__*/jsxs(Fragment, {
154
+ children: [/*#__PURE__*/jsx(Tooltip, {
155
+ content: t("neetoForm.questions.changeLanguage"),
156
+ children: /*#__PURE__*/jsx("div", {
157
+ children: /*#__PURE__*/jsx(Dropdown, {
158
+ buttonStyle: "secondary",
159
+ label: selectedLanguageName,
160
+ children: /*#__PURE__*/jsx(Dropdown.Menu, {
161
+ children: languages.map(function (_ref2) {
162
+ var code = _ref2.code,
163
+ name = _ref2.name;
164
+ return /*#__PURE__*/jsx(Dropdown.MenuItem.Button, {
165
+ isActive: currentLanguage === code,
166
+ onClick: function onClick() {
167
+ return languageChangeHandler(code);
168
+ },
169
+ children: name
170
+ }, code);
171
+ })
172
+ })
173
+ })
174
+ })
175
+ }), /*#__PURE__*/jsx(Alert, {
176
+ isOpen: isUnsavedChangesAlertOpen,
177
+ message: t("neetoForm.questions.unsavedChangesAlert.message"),
178
+ submitButtonLabel: t("neetoForm.questions.unsavedChangesAlert.discard"),
179
+ title: t("neetoForm.questions.unsavedChangesAlert.title"),
180
+ onClose: function onClose() {
181
+ return setIsUnsavedChangesAlertOpen(false);
182
+ },
183
+ onSubmit: function onSubmit() {
184
+ onChange(selectedLanguage);
185
+ setIsUnsavedChangesAlertOpen(false);
186
+ }
187
+ })]
188
+ });
189
+ };
190
+
191
+ var Overview = function Overview(_ref) {
192
+ var title = _ref.title,
193
+ description = _ref.description,
194
+ availableLanguages = _ref.availableLanguages,
195
+ selectedLanguage = _ref.selectedLanguage,
196
+ onLanguageChange = _ref.onLanguageChange,
197
+ additionalActionOptions = _ref.additionalActionOptions;
198
+ return /*#__PURE__*/jsxs("div", {
199
+ className: "neeto-form-nano-form-wrapper__overview mb-4 w-full flex-shrink-0 space-y-4 px-6 pt-6",
200
+ children: [/*#__PURE__*/jsxs("div", {
201
+ className: "flex items-center justify-between",
202
+ children: [/*#__PURE__*/jsx(Typography, {
203
+ "data-cy": "neeto-form-engine-overview-title",
204
+ lineHeight: "neeto-ui-leading-normal",
205
+ style: "h2",
206
+ weight: "neeto-ui-font-semibold",
207
+ children: title
208
+ }), /*#__PURE__*/jsxs("div", {
209
+ className: "flex flex-shrink-0 items-center justify-between space-x-1",
210
+ children: [availableLanguages.length > 1 && /*#__PURE__*/jsx(ChangeLanguageDropdown, {
211
+ currentLanguage: selectedLanguage,
212
+ languages: availableLanguages,
213
+ onChange: onLanguageChange
214
+ }), isPresent(additionalActionOptions) && /*#__PURE__*/jsx(MoreDropdown, {
215
+ dropdownButtonProps: {
216
+ isRounded: true,
217
+ style: "tertiary"
218
+ },
219
+ dropdownProps: {
220
+ strategy: "fixed",
221
+ position: "bottom-start"
222
+ },
223
+ menuItems: additionalActionOptions
224
+ })]
225
+ })]
226
+ }), /*#__PURE__*/jsx(Typography, {
227
+ "data-cy": "neeto-form-engine-overview-description",
228
+ style: "body2",
229
+ children: description
230
+ })]
231
+ });
232
+ };
233
+
234
+ var validateEditorContent = function validateEditorContent(editorRef) {
235
+ return function () {
236
+ var _editorRef$current;
237
+ return (_editorRef$current = editorRef.current) !== null && _editorRef$current !== void 0 && (_editorRef$current = _editorRef$current.editor) !== null && _editorRef$current !== void 0 && _editorRef$current.isEmpty ? t("neetoForm.common.thisFieldIsRequired") : "";
238
+ };
239
+ };
240
+ var buildReorderPayload = function buildReorderPayload(questions) {
241
+ return reduce(function (acc, _ref) {
242
+ var id = _ref.id,
243
+ displayOrder = _ref.displayOrder;
244
+ return assoc(id, displayOrder, acc);
245
+ }, {}, questions);
246
+ };
247
+ var isRichTextQuestion = includes(__, RICH_TEXT_QUESTIONS);
248
+
249
+ var Card = function Card(_ref) {
250
+ var _ref$question = _ref.question,
251
+ question = _ref$question === void 0 ? {} : _ref$question,
252
+ allQuestionKinds = _ref.allQuestionKinds,
253
+ getActiveKindDetails = _ref.getActiveKindDetails,
254
+ isActive = _ref.isActive,
255
+ onSelect = _ref.onSelect,
256
+ onEdit = _ref.onEdit,
257
+ onClone = _ref.onClone,
258
+ onDelete = _ref.onDelete;
259
+ var _useTranslation = useTranslation(),
260
+ t = _useTranslation.t;
261
+ var _getActiveKindDetails = getActiveKindDetails({
262
+ allQuestionKinds: allQuestionKinds,
263
+ item: question
264
+ }),
265
+ kind = _getActiveKindDetails.kind,
266
+ isSingular = _getActiveKindDetails.isSingular;
267
+ var label = fieldWithFallback(question, "label");
268
+ var questionLabel = isRichTextQuestion(kind) ? htmlToPlainText(label) : label;
269
+ return /*#__PURE__*/jsxs("div", {
270
+ "data-cy": "neeto-form-engine-".concat(slugify(questionLabel)),
271
+ className: classnames("neeto-ui-rounded neeto-ui-border-gray-300 neeto-ui-bg-white neeto-form-nano-form__card flex h-10 w-full items-center justify-between border p-2", {
272
+ "neeto-ui-border-primary-500 neeto-form-nano-form__card--active": isActive
273
+ }),
274
+ onClick: function onClick() {
275
+ return onSelect(question);
276
+ },
277
+ children: [/*#__PURE__*/jsxs("div", {
278
+ className: "flex min-w-0 flex-grow items-center gap-1",
279
+ children: [/*#__PURE__*/jsx(Drag, {
280
+ className: "neeto-ui-text-gray-600 flex-shrink-0"
281
+ }), /*#__PURE__*/jsx(Typography, {
282
+ className: "line-clamp-2 min-w-0 flex-grow truncate break-words",
283
+ lineHeight: "snug",
284
+ style: "body2",
285
+ weight: "medium",
286
+ children: questionLabel
287
+ })]
288
+ }), /*#__PURE__*/jsx(MoreDropdown, {
289
+ dropdownButtonProps: {
290
+ className: "shrink-0"
291
+ },
292
+ dropdownProps: {
293
+ strategy: "fixed"
294
+ },
295
+ menuItems: [{
296
+ "data-cy": "edit-question",
297
+ key: "edit",
298
+ label: t("neetoForm.common.edit"),
299
+ onClick: onEdit
300
+ }, {
301
+ "data-cy": "clone-question",
302
+ key: "clone",
303
+ label: t("neetoForm.common.clone"),
304
+ isVisible: !isSingular && isFunction(onClone),
305
+ onClick: onClone
306
+ }, {
307
+ "data-cy": "delete-question",
308
+ key: "delete",
309
+ label: t("neetoForm.common.delete"),
310
+ isVisible: isFunction(onDelete),
311
+ onClick: onDelete
312
+ }]
313
+ })]
314
+ });
315
+ };
316
+
317
+ 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; }
318
+ 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; }
319
+ var Questions = function Questions(_ref) {
320
+ var questions = _ref.questions,
321
+ isDeletable = _ref.isDeletable,
322
+ allQuestionKinds = _ref.allQuestionKinds,
323
+ getActiveKindDetails = _ref.getActiveKindDetails,
324
+ selectedQuestion = _ref.selectedQuestion,
325
+ onEdit = _ref.onEdit,
326
+ onClone = _ref.onClone,
327
+ onDelete = _ref.onDelete,
328
+ onSelect = _ref.onSelect;
329
+ return /*#__PURE__*/jsx(Droppable, {
330
+ droppableId: "droppable",
331
+ children: function children(_ref2) {
332
+ var droppableProps = _ref2.droppableProps,
333
+ placeholder = _ref2.placeholder,
334
+ innerRef = _ref2.innerRef;
335
+ return /*#__PURE__*/jsxs("div", _objectSpread$e(_objectSpread$e({}, droppableProps), {}, {
336
+ className: "space-y-2",
337
+ ref: innerRef,
338
+ children: [questions.map(function (question, index) {
339
+ var _question$id, _question$id2;
340
+ return /*#__PURE__*/createElement(Draggable, {
341
+ index: index,
342
+ draggableId: "question-".concat((_question$id = question.id) !== null && _question$id !== void 0 ? _question$id : question.nodeId),
343
+ key: "question-".concat((_question$id2 = question.id) !== null && _question$id2 !== void 0 ? _question$id2 : question.nodeId)
344
+ }, function (_ref3) {
345
+ var draggableProps = _ref3.draggableProps,
346
+ dragHandleProps = _ref3.dragHandleProps,
347
+ innerRef = _ref3.innerRef;
348
+ return /*#__PURE__*/jsx("div", _objectSpread$e(_objectSpread$e(_objectSpread$e({}, draggableProps), dragHandleProps), {}, {
349
+ ref: innerRef,
350
+ children: /*#__PURE__*/jsx(Card, {
351
+ allQuestionKinds: allQuestionKinds,
352
+ getActiveKindDetails: getActiveKindDetails,
353
+ onClone: onClone,
354
+ onEdit: onEdit,
355
+ onSelect: onSelect,
356
+ question: question,
357
+ isActive: equals(selectedQuestion, question),
358
+ onDelete: isDeletable(question) && onDelete
359
+ })
360
+ }));
361
+ });
362
+ }), placeholder]
363
+ }));
364
+ }
365
+ });
366
+ };
367
+
368
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
369
+ // require the crypto API and do not support built-in fallback to lower quality random number
370
+ // generators (like Math.random()).
371
+ let getRandomValues;
372
+ const rnds8 = new Uint8Array(16);
373
+ function rng() {
374
+ // lazy load so that environments that need to polyfill have a chance to do so
375
+ if (!getRandomValues) {
376
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
377
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
378
+
379
+ if (!getRandomValues) {
380
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
381
+ }
382
+ }
383
+
384
+ return getRandomValues(rnds8);
385
+ }
386
+
387
+ /**
388
+ * Convert array of 16 byte values to UUID string format of the form:
389
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
390
+ */
391
+
392
+ const byteToHex = [];
393
+
394
+ for (let i = 0; i < 256; ++i) {
395
+ byteToHex.push((i + 0x100).toString(16).slice(1));
396
+ }
397
+
398
+ function unsafeStringify(arr, offset = 0) {
399
+ // Note: Be careful editing this code! It's been tuned for performance
400
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
401
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
402
+ }
403
+
404
+ const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
405
+ var native = {
406
+ randomUUID
407
+ };
408
+
409
+ function v4(options, buf, offset) {
410
+ if (native.randomUUID && !buf && !options) {
411
+ return native.randomUUID();
412
+ }
413
+
414
+ options = options || {};
415
+ const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
416
+
417
+ rnds[6] = rnds[6] & 0x0f | 0x40;
418
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
419
+
420
+ if (buf) {
421
+ offset = offset || 0;
422
+
423
+ for (let i = 0; i < 16; ++i) {
424
+ buf[offset + i] = rnds[i];
425
+ }
426
+
427
+ return buf;
428
+ }
429
+
430
+ return unsafeStringify(rnds);
431
+ }
432
+
433
+ var moveItem = function moveItem(arr, sourceIndex, destinationIndex) {
434
+ if (sourceIndex === destinationIndex) return arr;
435
+ if (arr instanceof Array && arr[sourceIndex] !== undefined) {
436
+ var removedItem = arr.splice(sourceIndex, 1)[0];
437
+ arr.splice(destinationIndex, 0, removedItem);
438
+ }
439
+ return arr;
440
+ };
441
+ var arrayHelpers = {
442
+ moveItem: moveItem
443
+ };
444
+
445
+ 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; }
446
+ 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; }
447
+ var isChoiceQuestion = function isChoiceQuestion(question) {
448
+ return includes(question === null || question === void 0 ? void 0 : question.kind, SELECTABLE_KINDS);
449
+ };
450
+ var generateUniqueFieldCode = function generateUniqueFieldCode(type, questions) {
451
+ var fieldCodes = pluck("fieldCode", filterBy({
452
+ kind: type
453
+ }, questions));
454
+ var uniqueNumber = fieldCodes.length;
455
+ var candidateFieldCode = "";
456
+ var prefix = RESERVED_FIELD_CODES.includes(type) ? "".concat(type, "_field") : type;
457
+
458
+ //We need to continue this while loop until we can generate a unique fieldCode
459
+ // eslint-disable-next-line no-constant-condition
460
+ while (true) {
461
+ candidateFieldCode = "".concat(prefix).concat(uniqueNumber || "");
462
+ if (!findBy({
463
+ fieldCode: candidateFieldCode
464
+ }, questions)) break;
465
+ uniqueNumber += 1;
466
+ }
467
+ return candidateFieldCode;
468
+ };
469
+ var isQuestionKindAlreadyActive = function isQuestionKindAlreadyActive(_ref) {
470
+ var activeQuestions = _ref.activeQuestions,
471
+ kind = _ref.kind;
472
+ return activeQuestions.some(function (activeQuestion) {
473
+ return activeQuestion.kind === kind.type && activeQuestion._destroy !== true;
474
+ });
475
+ };
476
+ var handleFieldDragEnd = function handleFieldDragEnd(_ref2) {
477
+ var items = _ref2.items,
478
+ setValue = _ref2.setValue,
479
+ source = _ref2.source,
480
+ destination = _ref2.destination;
481
+ if (!(destination && items instanceof Array)) return;
482
+ var nextItems = _toConsumableArray(items);
483
+ arrayHelpers.moveItem(nextItems, source.index, destination.index);
484
+ var orderedItems = nextItems.map(function (item, index) {
485
+ return _objectSpread$d(_objectSpread$d({}, item), {}, {
486
+ displayOrder: index
487
+ });
488
+ });
489
+ setValue("questions", orderedItems);
490
+ };
491
+ var createFieldData = function createFieldData(_ref3) {
492
+ var _ref3$kind = _ref3.kind,
493
+ defaults = _ref3$kind.defaults,
494
+ type = _ref3$kind.type,
495
+ metadata = _ref3$kind.metadata,
496
+ _ref3$isRequired = _ref3.isRequired,
497
+ isRequired = _ref3$isRequired === void 0 ? undefined : _ref3$isRequired,
498
+ questions = _ref3.questions;
499
+ return _objectSpread$d(_objectSpread$d({}, defaults), {}, {
500
+ metadata: metadata,
501
+ isRequired: isRequired,
502
+ kind: type,
503
+ nodeId: v4(),
504
+ fieldCode: generateUniqueFieldCode(type, questions)
505
+ });
506
+ };
507
+ var duplicateFieldData = function duplicateFieldData(_ref4) {
508
+ var item = _ref4.item,
509
+ questionKinds = _ref4.questionKinds,
510
+ questions = _ref4.questions;
511
+ var questionKind = findBy({
512
+ type: item.kind
513
+ }, questionKinds);
514
+ var isRequired = item.isRequired,
515
+ kind = item.kind,
516
+ optionsAttributes = item.optionsAttributes;
517
+ var label = fieldWithFallback(item, "label");
518
+ var defaultAttributeNames = keys(questionKind.defaults || {});
519
+ var defaultAttributes = pick(defaultAttributeNames, item);
520
+ var newQuestionLabel = isRichTextQuestion(kind) ? label : t("neetoForm.common.clonedElementLabel", {
521
+ label: label
522
+ });
523
+ return _objectSpread$d(_objectSpread$d({}, defaultAttributes), {}, {
524
+ isRequired: isRequired,
525
+ kind: kind,
526
+ label: newQuestionLabel,
527
+ optionsAttributes: optionsAttributes && optionsAttributes.map(omit(["id"])),
528
+ nodeId: v4(),
529
+ fieldCode: generateUniqueFieldCode(item.kind, questions),
530
+ displayOrder: item.displayOrder + 1
531
+ });
532
+ };
533
+ var getAvailableQuestionKinds = function getAvailableQuestionKinds(_ref5) {
534
+ var allQuestionKinds = _ref5.allQuestionKinds,
535
+ _ref5$activeQuestions = _ref5.activeQuestions,
536
+ activeQuestions = _ref5$activeQuestions === void 0 ? [] : _ref5$activeQuestions,
537
+ isKindAlreadyActive = _ref5.isKindAlreadyActive;
538
+ if (isEmpty(activeQuestions)) return allQuestionKinds;
539
+ return reject(function (kind) {
540
+ var isSingularKind = kind.isSingular;
541
+ return isSingularKind && isKindAlreadyActive({
542
+ activeQuestions: activeQuestions,
543
+ kind: kind
544
+ });
545
+ }, allQuestionKinds);
546
+ };
547
+ var formatQuestionAttributesForClone = when(isChoiceQuestion, assoc("isCloning", true));
548
+
549
+ var AddFirstQuestion = function AddFirstQuestion(_ref) {
550
+ var children = _ref.children;
551
+ return /*#__PURE__*/jsxs("div", {
552
+ className: "flex h-full flex-col items-center justify-center py-8",
553
+ children: [/*#__PURE__*/jsx("div", {
554
+ className: "mb-6",
555
+ children: /*#__PURE__*/jsx(SvgNoQuestions, {})
556
+ }), children]
557
+ });
558
+ };
559
+
560
+ var NAME = QUESTION_TYPES.NAME,
561
+ PHONE = QUESTION_TYPES.PHONE,
562
+ EMAIL$1 = QUESTION_TYPES.EMAIL,
563
+ ADDITIONAL_GUESTS = QUESTION_TYPES.ADDITIONAL_GUESTS,
564
+ TEXT = QUESTION_TYPES.TEXT,
565
+ TEXTAREA = QUESTION_TYPES.TEXTAREA,
566
+ RICH_TEXT = QUESTION_TYPES.RICH_TEXT,
567
+ INTEGER = QUESTION_TYPES.INTEGER,
568
+ DECIMAL = QUESTION_TYPES.DECIMAL,
569
+ STAR_RATING$1 = QUESTION_TYPES.STAR_RATING,
570
+ RATING$1 = QUESTION_TYPES.RATING,
571
+ DATE = QUESTION_TYPES.DATE,
572
+ FILE_UPLOAD$1 = QUESTION_TYPES.FILE_UPLOAD,
573
+ CAPTCHA$1 = QUESTION_TYPES.CAPTCHA;
574
+ var QUESTIONS_WITH_ADDITIONAL_DATA = [].concat(_toConsumableArray(SELECTABLE_KINDS), [STAR_RATING$1, RATING$1, FILE_UPLOAD$1, CAPTCHA$1, EMAIL$1]);
575
+ var QUESTIONS_WITH_PLACEHOLDERS = [NAME, PHONE, EMAIL$1, ADDITIONAL_GUESTS, TEXT, TEXTAREA, RICH_TEXT, INTEGER, DECIMAL, DATE];
576
+ var DEFAULT_PLACEHOLDERS = {
577
+ CHECKBOX: t("neetoForm.questions.common.questionFields.field.labelExample", {
578
+ what: t("neetoForm.common.hobbies")
579
+ }),
580
+ RADIO: t("neetoForm.questions.common.questionFields.field.labelExample", {
581
+ what: t("neetoForm.common.country")
582
+ }),
583
+ DROPDOWN: t("neetoForm.questions.common.questionFields.field.labelExample", {
584
+ what: t("neetoForm.common.company")
585
+ })
586
+ };
587
+ var INITIAL_VALUES = {
588
+ kind: "",
589
+ label: "",
590
+ fieldCode: ""
591
+ };
592
+
593
+ var _excluded$8 = ["label", "name"];
594
+ 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; }
595
+ 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; }
596
+ var FormikAdaptiveInput = function FormikAdaptiveInput(_ref) {
597
+ var label = _ref.label,
598
+ name = _ref.name,
599
+ otherProps = _objectWithoutProperties(_ref, _excluded$8);
600
+ var _useFormikContext = useFormikContext(),
601
+ dirty = _useFormikContext.dirty,
602
+ isValid = _useFormikContext.isValid,
603
+ submitForm = _useFormikContext.submitForm;
604
+ var handleKeyDown = function handleKeyDown(event) {
605
+ if (event.key !== "Enter" || event.shiftKey) return;
606
+ event.preventDefault();
607
+ if (isMetaKeyPressed(event)) return;
608
+ dirty && isValid && submitForm();
609
+ };
610
+ var handleFocus = function handleFocus(element) {
611
+ var end = element.value.length;
612
+ element.setSelectionRange(end, end);
613
+ };
614
+ return /*#__PURE__*/jsx(Textarea, _objectSpread$c({
615
+ label: label,
616
+ name: name,
617
+ className: "neeto-form-nano-adaptive-input",
618
+ resize: "none",
619
+ size: "small",
620
+ onFocus: function onFocus(_ref2) {
621
+ var target = _ref2.target;
622
+ return handleFocus(target);
623
+ },
624
+ onKeyDown: handleKeyDown
625
+ }, otherProps));
626
+ };
627
+
628
+ var Block = function Block(_ref) {
629
+ var title = _ref.title,
630
+ children = _ref.children,
631
+ dataCy = _ref.dataCy;
632
+ return /*#__PURE__*/jsxs("div", {
633
+ className: "mt-4 space-y-4",
634
+ "data-cy": dataCy,
635
+ children: [/*#__PURE__*/jsx("div", {
636
+ className: "flex items-center justify-between",
637
+ "data-cy": "properties-header",
638
+ children: /*#__PURE__*/jsx(Typography, {
639
+ lineHeight: "normal",
640
+ style: "body1",
641
+ weight: "semibold",
642
+ children: title
643
+ })
644
+ }), /*#__PURE__*/jsx("div", {
645
+ className: "space-y-4",
646
+ children: children
647
+ })]
648
+ });
649
+ };
650
+
651
+ var useUpdateEditorContent = function useUpdateEditorContent(_ref) {
652
+ var editorRef = _ref.editorRef,
653
+ fieldName = _ref.fieldName,
654
+ value = _ref.value,
655
+ initialValue = _ref.initialValue,
656
+ fieldCode = _ref.fieldCode;
657
+ var initialStateRef = useRef({
658
+ language: "",
659
+ value: null
660
+ });
661
+ var _useBuildFormStore = useBuildFormStore(function (store) {
662
+ return {
663
+ setFormData: store["setFormData"]
664
+ };
665
+ }, shallow),
666
+ setFormData = _useBuildFormStore.setFormData;
667
+ var _useBuildFormStore2 = useBuildFormStore(function (store) {
668
+ var _store$formState, _store$formState2;
669
+ return {
670
+ formId: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["formId"],
671
+ selectedLanguage: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["selectedLanguage"]
672
+ };
673
+ }, shallow),
674
+ formId = _useBuildFormStore2.formId,
675
+ language = _useBuildFormStore2.selectedLanguage;
676
+ var shouldReset = useBuildFormStore(function (store) {
677
+ return store.formState.richTextFieldsToReset.includes(fieldCode);
678
+ });
679
+ var setEditorContent = function setEditorContent(content) {
680
+ var _editorRef$current$ed;
681
+ return (_editorRef$current$ed = editorRef.current.editor) === null || _editorRef$current$ed === void 0 || (_editorRef$current$ed = _editorRef$current$ed.commands) === null || _editorRef$current$ed === void 0 ? void 0 : _editorRef$current$ed.setContent(content);
682
+ };
683
+ if (shouldReset) {
684
+ setEditorContent(initialValue);
685
+ setFormData(modify("richTextFieldsToReset", without([fieldCode])));
686
+ }
687
+ var _useFetchQuestions = useFetchQuestions({
688
+ formId: formId,
689
+ language: language
690
+ }),
691
+ data = _useFetchQuestions.data;
692
+ useEffect(function () {
693
+ if (!data) return;
694
+ var pathArray = fieldName.split(".").map(function (part) {
695
+ var parsedPart = parseInt(part);
696
+ return isNaN(parsedPart) ? part : parsedPart;
697
+ });
698
+ setEditorContent(path(pathArray, data));
699
+ }, [data]);
700
+ useEffect(function () {
701
+ if (initialStateRef.current["language"] !== language) {
702
+ initialStateRef.current["language"] = language;
703
+ initialStateRef.current["value"] = null;
704
+ return;
705
+ }
706
+ if (initialStateRef.current["value"] === null && value !== null) {
707
+ setEditorContent(value);
708
+ initialStateRef.current["value"] = value;
709
+ }
710
+ }, [language, value]);
711
+ };
712
+
713
+ var Editor = function Editor() {
714
+ var editorRef = useRef({
715
+ editor: {}
716
+ });
717
+ var _useFormikContext = useFormikContext(),
718
+ fieldCode = _useFormikContext.values.fieldCode;
719
+ var fieldName = "label";
720
+ var _useField = useField({
721
+ name: fieldName,
722
+ validate: validateEditorContent(editorRef)
723
+ }),
724
+ _useField2 = _slicedToArray(_useField, 3),
725
+ value = _useField2[0].value,
726
+ _useField2$ = _useField2[1],
727
+ touched = _useField2$.touched,
728
+ error = _useField2$.error,
729
+ initialValue = _useField2$.initialValue,
730
+ _useField2$2 = _useField2[2],
731
+ setTouched = _useField2$2.setTouched,
732
+ setValue = _useField2$2.setValue;
733
+ useUpdateEditorContent({
734
+ editorRef: editorRef,
735
+ fieldName: fieldName,
736
+ value: value,
737
+ initialValue: initialValue,
738
+ fieldCode: fieldCode
739
+ });
740
+ return /*#__PURE__*/jsx("div", {
741
+ className: "w-full cursor-auto",
742
+ children: /*#__PURE__*/jsx(NeetoEditor, {
743
+ required: true,
744
+ error: touched ? error : "",
745
+ id: "editor",
746
+ initialValue: value,
747
+ name: fieldName,
748
+ ref: editorRef,
749
+ onBlur: function onBlur() {
750
+ return setTouched(true);
751
+ },
752
+ onChange: setValue
753
+ })
754
+ });
755
+ };
756
+
757
+ var RequiredSwitch = withT(function (_ref) {
758
+ var t = _ref.t;
759
+ return /*#__PURE__*/jsx("div", {
760
+ className: "w-full",
761
+ children: /*#__PURE__*/jsx(Switch, {
762
+ label: t("neetoForm.common.required"),
763
+ name: "isRequired"
764
+ })
765
+ });
766
+ });
767
+
768
+ var _excluded$7 = ["maxLength"];
769
+ 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; }
770
+ 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; }
771
+ var InputWithMaxLength = function InputWithMaxLength(_ref) {
772
+ var maxLength = _ref.maxLength,
773
+ props = _objectWithoutProperties(_ref, _excluded$7);
774
+ var _useField = useField(props),
775
+ _useField2 = _slicedToArray(_useField, 3),
776
+ value = _useField2[0].value,
777
+ setValue = _useField2[2].setValue;
778
+ useEffect(function () {
779
+ if (value && value.length > maxLength) {
780
+ setValue(value.substring(0, maxLength));
781
+ }
782
+ }, [value, maxLength, setValue]);
783
+ var shouldShowMaxLength = value && value.length > maxLength - 10;
784
+ return /*#__PURE__*/jsx(Input, _objectSpread$b(_objectSpread$b({}, props), shouldShowMaxLength && {
785
+ maxLength: maxLength
786
+ }));
787
+ };
788
+
789
+ var FieldCode = withT(function (_ref) {
790
+ var helpDocUrl = _ref.helpDocUrl,
791
+ t = _ref.t;
792
+ return /*#__PURE__*/jsx(Accordion, {
793
+ className: "neeto-form-nano-advanced-properties-accordion",
794
+ "data-cy": "advanced-properties-card",
795
+ children: /*#__PURE__*/jsx(Accordion.Item, {
796
+ title: t("neetoForm.common.advancedProperties"),
797
+ children: /*#__PURE__*/jsx(InputWithMaxLength, {
798
+ required: true,
799
+ label: t("neetoForm.questions.common.questionFields.field.fieldCode"),
800
+ name: "fieldCode",
801
+ helpText: helpDocUrl && /*#__PURE__*/jsx(Trans, {
802
+ i18nKey: "neetoForm.questions.common.questionFields.field.fieldCodeHelpDescription",
803
+ components: {
804
+ Link: /*#__PURE__*/jsx(Button, {
805
+ className: "text-xs",
806
+ href: helpDocUrl,
807
+ style: "link",
808
+ target: "_blank"
809
+ })
810
+ }
811
+ })
812
+ })
813
+ })
814
+ });
815
+ });
816
+
817
+ var Form$1 = function Form(_ref) {
818
+ var questions = _ref.questions,
819
+ initialFocusRef = _ref.initialFocusRef,
820
+ isRequiredField = _ref.isRequiredField,
821
+ isDisabledFieldLabel = _ref.isDisabledFieldLabel,
822
+ enableFieldCode = _ref.enableFieldCode,
823
+ allQuestionKinds = _ref.allQuestionKinds,
824
+ availableQuestionKinds = _ref.availableQuestionKinds,
825
+ getActiveKindDetails = _ref.getActiveKindDetails,
826
+ additionalQuestionKindPattern = _ref.additionalQuestionKindPattern,
827
+ fieldCodeHelpDocUrl = _ref.fieldCodeHelpDocUrl,
828
+ enableDomainRestriction = _ref.enableDomainRestriction,
829
+ domainRestrictionHelpDocUrl = _ref.domainRestrictionHelpDocUrl,
830
+ _ref$isEdit = _ref.isEdit,
831
+ isEdit = _ref$isEdit === void 0 ? false : _ref$isEdit;
832
+ var _useTranslation = useTranslation(),
833
+ t = _useTranslation.t;
834
+ var _useFormikContext = useFormikContext(),
835
+ values = _useFormikContext.values,
836
+ setValues = _useFormikContext.setValues,
837
+ setErrors = _useFormikContext.setErrors,
838
+ setTouched = _useFormikContext.setTouched;
839
+ var kind = values.kind;
840
+ var questionKinds = isEdit ? allQuestionKinds : availableQuestionKinds;
841
+ var questionKindUniquenessPattern = mergeLeft(isEdit && additionalQuestionKindPattern ? additionalQuestionKindPattern(values) : {}, {
842
+ type: kind
843
+ });
844
+ var _useStateWithDependen = useStateWithDependency(getQuestionKind(questionKinds, questionKindUniquenessPattern), [kind]),
845
+ _useStateWithDependen2 = _slicedToArray(_useStateWithDependen, 1),
846
+ questionKind = _useStateWithDependen2[0];
847
+ var _ref2 = questionKind ? getActiveKindDetails({
848
+ allQuestionKinds: allQuestionKinds,
849
+ item: questionKind
850
+ }) : {},
851
+ _ref2$questionProps = _ref2.questionProps,
852
+ questionProps = _ref2$questionProps === void 0 ? {} : _ref2$questionProps;
853
+ var isRequired = questionKind && isRequiredField(questionKind);
854
+ var isLabelDisabled = questionKind && isDisabledFieldLabel(questionKind);
855
+ var shouldShowPlaceholder = includes(kind, QUESTIONS_WITH_PLACEHOLDERS);
856
+ var hasAdditionalData = includes(kind, QUESTIONS_WITH_ADDITIONAL_DATA);
857
+ var shouldShowFieldCode = enableFieldCode && !includes(kind, QUESTIONS_WITHOUT_FIELD_CODE);
858
+ var shouldShowHideSwitch = !includes(kind, QUESTIONS_WITHOUT_FIELD_CODE);
859
+ var handleKindChange = function handleKindChange(option) {
860
+ var data = buildQuestionData(option);
861
+ updateFormState(data);
862
+ };
863
+ var buildQuestionData = function buildQuestionData(option) {
864
+ if (isNil(option)) {
865
+ return INITIAL_VALUES;
866
+ }
867
+ var label = option.label,
868
+ value = option.value;
869
+ var kind = extractKindFromOption(value);
870
+ var questionKind = getQuestionKind(availableQuestionKinds, {
871
+ type: kind,
872
+ label: label
873
+ });
874
+ return createFieldData({
875
+ kind: questionKind,
876
+ isRequired: isRequired,
877
+ questions: questions
878
+ });
879
+ };
880
+ var updateFormState = function updateFormState(data) {
881
+ setValues(data);
882
+ setErrors({});
883
+ setTouched({});
884
+ };
885
+ return /*#__PURE__*/jsx(Pane.Body, {
886
+ children: /*#__PURE__*/jsxs("div", {
887
+ className: "w-full space-y-4",
888
+ children: [/*#__PURE__*/jsx(Select, {
889
+ isClearable: true,
890
+ isSearchable: true,
891
+ defaultValue: buildDefaultValueForKind(questionKind),
892
+ innerRef: initialFocusRef,
893
+ isDisabled: isEdit,
894
+ name: "kind",
895
+ options: buildKindOptions(questionKinds),
896
+ label: t("neetoForm.questions.common.questionFields.field.questionType"),
897
+ onChange: handleKindChange
898
+ }), isRichTextQuestion(kind) ? /*#__PURE__*/jsx(Editor, {
899
+ isLabelDisabled: isLabelDisabled
900
+ }) : /*#__PURE__*/jsxs("div", {
901
+ className: "space-y-6",
902
+ children: [/*#__PURE__*/jsxs("div", {
903
+ className: "space-y-4",
904
+ children: [/*#__PURE__*/jsx(FormikAdaptiveInput, {
905
+ required: true,
906
+ disabled: isLabelDisabled,
907
+ name: "label",
908
+ placeholder: DEFAULT_PLACEHOLDERS[kind],
909
+ label: t("neetoForm.questions.common.questionFields.field.question")
910
+ }), shouldShowPlaceholder && /*#__PURE__*/jsx(FormikAdaptiveInput, {
911
+ name: "placeholder",
912
+ label: t("neetoForm.questions.common.questionFields.field.placeholder")
913
+ }), hasAdditionalData && renderAdditionalData({
914
+ kind: kind,
915
+ questionProps: questionProps,
916
+ domainRestrictionHelpDocUrl: domainRestrictionHelpDocUrl,
917
+ enableDomainRestriction: enableDomainRestriction
918
+ })]
919
+ }), !isRequired && /*#__PURE__*/jsxs(Block, {
920
+ dataCy: "settings-card",
921
+ title: t("neetoForm.common.settings"),
922
+ children: [/*#__PURE__*/jsx(RequiredSwitch, {}), shouldShowHideSwitch && /*#__PURE__*/jsx(Switch, {
923
+ label: t("neetoForm.common.hideQuestion"),
924
+ name: "isHidden"
925
+ })]
926
+ }), shouldShowFieldCode && /*#__PURE__*/jsx(FieldCode, {
927
+ helpDocUrl: fieldCodeHelpDocUrl
928
+ })]
929
+ })]
930
+ })
931
+ });
932
+ };
933
+
934
+ /* eslint-disable @bigbinary/neeto/file-name-and-export-name-standards */
935
+ var requiredLabelValidation = function requiredLabelValidation(schema, field) {
936
+ return schema.trim().required(t("neetoForm.common.fieldReq", {
937
+ field: field
938
+ }));
939
+ };
940
+ var richTextFieldMissingErrorMessage = function richTextFieldMissingErrorMessage(kind) {
941
+ var field = equals(kind, QUESTION_TYPES.PARAGRAPH) ? t("neetoForm.fields.def") : t("neetoForm.fields.tcf");
942
+ return t("neetoForm.error.fieldCantBeEmpty", {
943
+ field: field
944
+ });
945
+ };
946
+ var formValidationSchema = yup.object().shape({
947
+ kind: yup.string().trim().required(t("neetoForm.common.fieldReq", {
948
+ field: t("neetoForm.questions.common.questionFields.field.questionType")
949
+ })),
950
+ label: yup.string().when("kind", function (kind, schema) {
951
+ return includes(kind, RICH_TEXT_QUESTIONS) ? schema.test("required", richTextFieldMissingErrorMessage(kind), function (value) {
952
+ return !isEditorEmpty(value);
953
+ }) : requiredLabelValidation(schema, t("neetoForm.questions.common.questionFields.field.question"));
954
+ }),
955
+ fieldCode: yup.string().trim().notOneOf(RESERVED_FIELD_CODES, t("neetoForm.error.invalidFieldCode")).when("kind", function (kind, schema) {
956
+ return includes(kind, QUESTIONS_WITHOUT_FIELD_CODE) ? schema.notRequired() : requiredLabelValidation(schema, t("neetoForm.questions.common.questionFields.field.fieldCode"));
957
+ }),
958
+ optionsAttributes: yup.array().when("_destroy", {
959
+ is: true,
960
+ otherwise: function otherwise(schema) {
961
+ return schema.when("kind", function (kind, schema) {
962
+ return includes(kind, SELECTABLE_KINDS) ? schema.of(yup.object().shape({
963
+ label: requiredLabelValidation(yup.string(), t("neetoForm.questions.common.questionFields.field.option"))
964
+ })) : schema.notRequired();
965
+ });
966
+ }
967
+ }),
968
+ highestRatingLabel: yup.string().nullable(),
969
+ averageRatingLabel: yup.string().nullable(),
970
+ lowestRatingLabel: yup.string().nullable()
971
+ });
972
+
973
+ var _excluded$6 = ["question", "onClose", "questions", "handleSelect", "buildRequestArgs", "isOpen", "fieldCodeHelpDocUrl", "domainRestrictionHelpDocUrl"];
974
+ function ownKeys$a(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
975
+ function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
976
+ var Add = function Add(_ref) {
977
+ var question = _ref.question,
978
+ onClose = _ref.onClose,
979
+ questions = _ref.questions,
980
+ handleSelect = _ref.handleSelect,
981
+ buildRequestArgs = _ref.buildRequestArgs,
982
+ isOpen = _ref.isOpen,
983
+ fieldCodeHelpDocUrl = _ref.fieldCodeHelpDocUrl,
984
+ domainRestrictionHelpDocUrl = _ref.domainRestrictionHelpDocUrl,
985
+ props = _objectWithoutProperties(_ref, _excluded$6);
986
+ var _useBuildFormStore = useBuildFormStore(function (store) {
987
+ var _store$formState, _store$formState2;
988
+ return {
989
+ formId: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["formId"],
990
+ selectedLanguage: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["selectedLanguage"]
991
+ };
992
+ }, shallow),
993
+ formId = _useBuildFormStore.formId,
994
+ language = _useBuildFormStore.selectedLanguage;
995
+ var _useTranslation = useTranslation(),
996
+ t = _useTranslation.t;
997
+ var _useCreateQuestion = useCreateQuestion(formId, language, {
998
+ onSuccess: function onSuccess() {
999
+ showThumbsUpToastr();
1000
+ onClose();
1001
+ }
1002
+ }),
1003
+ createQuestion = _useCreateQuestion.mutate,
1004
+ isCreating = _useCreateQuestion.isPending;
1005
+ var handleSubmit = function handleSubmit(values) {
1006
+ if (isCreating || !isOpen) return;
1007
+ var displayOrder = question ? question.displayOrder + 1 : questions.length;
1008
+ createQuestion(_objectSpread$a({
1009
+ language: language,
1010
+ neetoFormQuestion: mergeLeft({
1011
+ displayOrder: displayOrder
1012
+ }, values)
1013
+ }, buildRequestArgs), {
1014
+ onSuccess: function onSuccess(_ref2) {
1015
+ var questions = _ref2.questions;
1016
+ var newQuestion = findBy({
1017
+ displayOrder: displayOrder
1018
+ }, questions);
1019
+ handleSelect(newQuestion);
1020
+ }
1021
+ });
1022
+ };
1023
+ return /*#__PURE__*/jsxs(Fragment, {
1024
+ children: [/*#__PURE__*/jsx(Pane.Header, {
1025
+ children: /*#__PURE__*/jsx(Typography, {
1026
+ "data-cy": "add-question-pane-header",
1027
+ style: "h2",
1028
+ children: t("neetoForm.questions.common.primaryPanel.addQuestion")
1029
+ })
1030
+ }), /*#__PURE__*/jsx(Form$2, {
1031
+ formikProps: {
1032
+ initialValues: INITIAL_VALUES,
1033
+ validationSchema: formValidationSchema,
1034
+ onSubmit: handleSubmit
1035
+ },
1036
+ children: /*#__PURE__*/jsxs(Fragment, {
1037
+ children: [/*#__PURE__*/jsx(Form$1, _objectSpread$a({}, _objectSpread$a(_objectSpread$a({}, props), {}, {
1038
+ domainRestrictionHelpDocUrl: domainRestrictionHelpDocUrl,
1039
+ fieldCodeHelpDocUrl: fieldCodeHelpDocUrl,
1040
+ question: question,
1041
+ questions: questions
1042
+ }))), /*#__PURE__*/jsx(Pane.Footer, {
1043
+ children: /*#__PURE__*/jsx(ActionBlock, {
1044
+ cancelButtonProps: {
1045
+ onClick: onClose
1046
+ },
1047
+ isSubmitting: isCreating
1048
+ })
1049
+ })]
1050
+ })
1051
+ })]
1052
+ });
1053
+ };
1054
+
1055
+ var _excluded$5 = ["question", "isOpen", "onClose", "fieldCodeHelpDocUrl", "domainRestrictionHelpDocUrl"];
1056
+ function ownKeys$9(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1057
+ function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1058
+ var Edit = function Edit(_ref) {
1059
+ var question = _ref.question,
1060
+ isOpen = _ref.isOpen,
1061
+ onClose = _ref.onClose,
1062
+ fieldCodeHelpDocUrl = _ref.fieldCodeHelpDocUrl,
1063
+ domainRestrictionHelpDocUrl = _ref.domainRestrictionHelpDocUrl,
1064
+ props = _objectWithoutProperties(_ref, _excluded$5);
1065
+ var _useTranslation = useTranslation(),
1066
+ t = _useTranslation.t;
1067
+ var _useBuildFormStore = useBuildFormStore(function (store) {
1068
+ var _store$formState;
1069
+ return {
1070
+ selectedLanguage: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["selectedLanguage"]
1071
+ };
1072
+ }, shallow),
1073
+ language = _useBuildFormStore.selectedLanguage;
1074
+ var _useUpdateQuestion = useUpdateQuestion(question === null || question === void 0 ? void 0 : question.formId, language),
1075
+ updateQuestion = _useUpdateQuestion.mutate,
1076
+ isUpdating = _useUpdateQuestion.isPending;
1077
+ var handleSubmit = function handleSubmit(values, _ref2) {
1078
+ var setSubmitting = _ref2.setSubmitting;
1079
+ if (isUpdating || !isOpen) return;
1080
+ var payload = {
1081
+ language: language,
1082
+ neetoFormQuestion: values
1083
+ };
1084
+ updateQuestion({
1085
+ questionId: question.id,
1086
+ payload: payload
1087
+ }, {
1088
+ onSuccess: function onSuccess() {
1089
+ showThumbsUpToastr();
1090
+ onClose();
1091
+ },
1092
+ onSettled: function onSettled() {
1093
+ return setSubmitting(false);
1094
+ }
1095
+ });
1096
+ };
1097
+ return /*#__PURE__*/jsxs(Fragment, {
1098
+ children: [/*#__PURE__*/jsx(Pane.Header, {
1099
+ children: /*#__PURE__*/jsx(Typography, {
1100
+ "data-cy": "edit-question-pane-header",
1101
+ style: "h2",
1102
+ children: t("neetoForm.questions.common.editQuestion")
1103
+ })
1104
+ }), /*#__PURE__*/jsx(Form$2, {
1105
+ formikProps: {
1106
+ initialValues: question,
1107
+ validationSchema: formValidationSchema,
1108
+ onSubmit: handleSubmit
1109
+ },
1110
+ children: /*#__PURE__*/jsxs(Fragment, {
1111
+ children: [/*#__PURE__*/jsx(Form$1, _objectSpread$9(_objectSpread$9({}, _objectSpread$9({
1112
+ domainRestrictionHelpDocUrl: domainRestrictionHelpDocUrl,
1113
+ fieldCodeHelpDocUrl: fieldCodeHelpDocUrl,
1114
+ question: question
1115
+ }, props)), {}, {
1116
+ isEdit: true
1117
+ })), /*#__PURE__*/jsx(Pane.Footer, {
1118
+ children: /*#__PURE__*/jsx(ActionBlock, {
1119
+ cancelButtonProps: {
1120
+ onClick: onClose
1121
+ },
1122
+ isSubmitting: isUpdating
1123
+ })
1124
+ })]
1125
+ })
1126
+ })]
1127
+ });
1128
+ };
1129
+
1130
+ var Captcha = withT(function (_ref) {
1131
+ var t = _ref.t;
1132
+ return /*#__PURE__*/jsxs(Radio, {
1133
+ label: t("neetoForm.common.captchaType"),
1134
+ labelProps: {
1135
+ required: true
1136
+ },
1137
+ name: "variant",
1138
+ children: [/*#__PURE__*/jsx(Radio.Item, {
1139
+ label: t("neetoForm.common.reCaptchaV2"),
1140
+ value: CAPTCHA_TYPES.RECAPTCHA_V2
1141
+ }), /*#__PURE__*/jsx(Radio.Item, {
1142
+ label: t("neetoForm.common.mathCaptcha"),
1143
+ value: CAPTCHA_TYPES.MATH_CAPTCHA
1144
+ })]
1145
+ });
1146
+ });
1147
+
1148
+ var _excluded$4 = ["name", "title", "className"];
1149
+ function ownKeys$8(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1150
+ function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$8(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$8(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1151
+ var SwitchBlock = function SwitchBlock(_ref) {
1152
+ var name = _ref.name,
1153
+ title = _ref.title,
1154
+ _ref$className = _ref.className,
1155
+ className = _ref$className === void 0 ? "" : _ref$className,
1156
+ otherProps = _objectWithoutProperties(_ref, _excluded$4);
1157
+ return /*#__PURE__*/jsxs(Label, {
1158
+ className: classnames("flex items-center justify-start gap-2 ", className),
1159
+ "data-cy": "neeto-form-engine-".concat(hyphenate(title), "-toggle-label"),
1160
+ children: [/*#__PURE__*/jsx(Switch, _objectSpread$8(_objectSpread$8({}, _objectSpread$8(_objectSpread$8({}, otherProps), {}, {
1161
+ name: name
1162
+ })), {}, {
1163
+ "data-cy": "neeto-form-engine-".concat(hyphenate(title), "-switch")
1164
+ })), /*#__PURE__*/jsx(Typography, {
1165
+ component: "span",
1166
+ style: "body1",
1167
+ children: title
1168
+ })]
1169
+ });
1170
+ };
1171
+
1172
+ var _excluded$3 = ["children"];
1173
+ function ownKeys$7(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1174
+ function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1175
+ var STYLES = {
1176
+ border: {
1177
+ "default": "1px solid rgb(var(--neeto-ui-gray-400))",
1178
+ error: "1px solid rgb(var(--neeto-ui-error-800)) !important"
1179
+ },
1180
+ color: {
1181
+ "default": "rgb(var(--neeto-ui-gray-800))",
1182
+ error: "rgb(var(--neeto-ui-error-800)) !important"
1183
+ }
1184
+ };
1185
+ var MultiValueRemove = function MultiValueRemove(props) {
1186
+ return /*#__PURE__*/jsx(components.MultiValueRemove, _objectSpread$7(_objectSpread$7({}, props), {}, {
1187
+ innerProps: _objectSpread$7(_objectSpread$7({}, props.innerProps), {}, _defineProperty({}, "data-cy", "".concat(hyphenize(props.data.label), "-remove-icon"))),
1188
+ children: /*#__PURE__*/jsx(Close, {
1189
+ size: 16
1190
+ })
1191
+ }));
1192
+ };
1193
+ var ValueContainer = function ValueContainer(_ref) {
1194
+ var children = _ref.children,
1195
+ props = _objectWithoutProperties(_ref, _excluded$3);
1196
+ var _useTranslation = useTranslation(),
1197
+ t = _useTranslation.t;
1198
+ var getValue = props.getValue,
1199
+ _props$selectProps = props.selectProps,
1200
+ isFocused = _props$selectProps.isFocused,
1201
+ visibleDomainsCount = _props$selectProps.visibleDomainsCount;
1202
+ var value = getValue();
1203
+ var _children = _toArray(children),
1204
+ firstChild = _children[0],
1205
+ rest = _children.slice(1);
1206
+ var shouldCollapse = !isFocused && value.length > visibleDomainsCount;
1207
+ return /*#__PURE__*/jsxs(components.ValueContainer, _objectSpread$7(_objectSpread$7({}, props), {}, {
1208
+ innerProps: _objectSpread$7(_objectSpread$7({}, props.innerProps), {}, _defineProperty({}, "data-cy", "multi-domain-input-container")),
1209
+ children: [shouldCollapse ? firstChild.slice(0, visibleDomainsCount) : firstChild, shouldCollapse && /*#__PURE__*/jsx(Tag, {
1210
+ style: "secondary",
1211
+ label: t("neetoForm.common.remainingItemsCount", {
1212
+ count: value.length - visibleDomainsCount
1213
+ })
1214
+ }), rest]
1215
+ }));
1216
+ };
1217
+ var ClearIndicator = function ClearIndicator(props) {
1218
+ return /*#__PURE__*/jsx(components.ClearIndicator, _objectSpread$7(_objectSpread$7({}, props), {}, {
1219
+ innerProps: _objectSpread$7(_objectSpread$7({}, props.innerProps), {}, _defineProperty({}, "data-cy", "clear-all-button")),
1220
+ children: /*#__PURE__*/jsx(Close, {
1221
+ className: "cursor-pointer",
1222
+ size: 16
1223
+ })
1224
+ }));
1225
+ };
1226
+ var ERROR_MESSAGE_DELIMITER = ". ";
1227
+ var DELIMITER_KEYS = ["Enter", "Tab", ",", " "];
1228
+ var DOMAIN_SEPARATION_REGEX = /[^\s,]+/g;
1229
+ var FLEXIBLE_DOMAIN_REGEX = /^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/;
1230
+ var VALID_DOMAIN_REGEX = /^(?:[a-zA-Z0-9-]{1,63}\.)+[a-zA-Z0-9-]{2,63}$/;
1231
+ var DOMAIN_VALIDATION_SCHEMA = yup.string().required(t("neetoForm.error.requiredField", {
1232
+ label: t("neetoForm.common.domain")
1233
+ })).test("verify domains", t("neetoForm.error.invalidDomain"), function (domain) {
1234
+ return VALID_DOMAIN_REGEX.test(domain);
1235
+ });
1236
+ var CUSTOM_STYLES = {
1237
+ input: assoc("overflow", "hidden"),
1238
+ multiValue: function multiValue(styles, _ref2) {
1239
+ var valid = _ref2.data.valid;
1240
+ return _objectSpread$7(_objectSpread$7({}, styles), {}, {
1241
+ border: valid ? STYLES.border["default"] : STYLES.border.error,
1242
+ color: valid ? STYLES.color["default"] : STYLES.color.error
1243
+ });
1244
+ }
1245
+ };
1246
+ var CUSTOM_COMPONENTS = {
1247
+ DropdownIndicator: null,
1248
+ MultiValueRemove: MultiValueRemove,
1249
+ ValueContainer: ValueContainer,
1250
+ ClearIndicator: ClearIndicator
1251
+ };
1252
+
1253
+ var removeDuplicateErrorMessages = pipe(filter(isNotNil), uniq, join(ERROR_MESSAGE_DELIMITER));
1254
+ var formatDomainInputOptions = function formatDomainInputOptions(domain) {
1255
+ var isValid;
1256
+ try {
1257
+ DOMAIN_VALIDATION_SCHEMA.validateSync(domain);
1258
+ isValid = true;
1259
+ } catch (_unused) {
1260
+ isValid = false;
1261
+ }
1262
+ return {
1263
+ label: domain,
1264
+ value: domain,
1265
+ valid: isValid
1266
+ };
1267
+ };
1268
+ var pruneDuplicates = pipe(pluck("value"), uniq, map(formatDomainInputOptions));
1269
+ var getValidDomains = function getValidDomains(domains) {
1270
+ return domains.filter(function (domain) {
1271
+ return domain === null || domain === void 0 ? void 0 : domain.valid;
1272
+ });
1273
+ };
1274
+ var getValidDomainsCount = function getValidDomainsCount(domains) {
1275
+ return getValidDomains(domains).length;
1276
+ };
1277
+ var formatErrorMessage = function formatErrorMessage(error) {
1278
+ if (typeof error === "string") return error;
1279
+ return removeDuplicateErrorMessages(error);
1280
+ };
1281
+
1282
+ var _excluded$2 = ["label", "value", "onChange", "error", "onBlur"];
1283
+ function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1284
+ function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1285
+ var MultiDomainInput = function MultiDomainInput(_ref) {
1286
+ var _ref$label = _ref.label,
1287
+ label = _ref$label === void 0 ? "" : _ref$label,
1288
+ _ref$value = _ref.value,
1289
+ value = _ref$value === void 0 ? [] : _ref$value,
1290
+ _ref$onChange = _ref.onChange,
1291
+ onChange = _ref$onChange === void 0 ? noop : _ref$onChange,
1292
+ _ref$error = _ref.error,
1293
+ error = _ref$error === void 0 ? "" : _ref$error,
1294
+ _ref$onBlur = _ref.onBlur,
1295
+ onBlur = _ref$onBlur === void 0 ? noop : _ref$onBlur,
1296
+ otherProps = _objectWithoutProperties(_ref, _excluded$2);
1297
+ var _useState = useState(""),
1298
+ _useState2 = _slicedToArray(_useState, 2),
1299
+ inputValue = _useState2[0],
1300
+ setInputValue = _useState2[1];
1301
+ var _useState3 = useState(false),
1302
+ _useState4 = _slicedToArray(_useState3, 2),
1303
+ isFocused = _useState4[0],
1304
+ setIsFocused = _useState4[1];
1305
+ var _useTranslation = useTranslation(),
1306
+ t = _useTranslation.t;
1307
+ var handleFilterDomains = function handleFilterDomains() {
1308
+ return onChange(getValidDomains(value));
1309
+ };
1310
+ var handleDomainChange = function handleDomainChange() {
1311
+ var inputValues = inputValue.match(DOMAIN_SEPARATION_REGEX) || [];
1312
+ var domainMatches = filter(test(FLEXIBLE_DOMAIN_REGEX), inputValues);
1313
+ var domains = domainMatches.map(formatDomainInputOptions);
1314
+ onChange(pruneDuplicates([].concat(_toConsumableArray(value), _toConsumableArray(domains))));
1315
+ setInputValue("");
1316
+ };
1317
+ var handleKeyDown = function handleKeyDown(event) {
1318
+ if (!inputValue) return;
1319
+ if (includes(event.key, DELIMITER_KEYS)) {
1320
+ handleDomainChange();
1321
+ event.preventDefault();
1322
+ event.stopPropagation();
1323
+ }
1324
+ };
1325
+ var onCreateOption = function onCreateOption(input) {
1326
+ var domain = formatDomainInputOptions(input);
1327
+ onChange(pruneDuplicates([].concat(_toConsumableArray(value), [domain])));
1328
+ };
1329
+ var handleBlur = function handleBlur(event) {
1330
+ inputValue ? handleDomainChange() : onBlur(event);
1331
+ setIsFocused(false);
1332
+ };
1333
+ var isFilterDomainsLinkVisible = value.length > getValidDomainsCount(value);
1334
+ return /*#__PURE__*/jsxs("div", {
1335
+ className: "neeto-ui-input__wrapper neeto-ui-email-input__wrapper",
1336
+ children: [/*#__PURE__*/jsx("div", {
1337
+ className: "neeto-ui-email-input__label-wrapper",
1338
+ children: /*#__PURE__*/jsx(Label, {
1339
+ className: "neeto-ui-email-input__label",
1340
+ "data-cy": "".concat(hyphenize(label), "-input-label"),
1341
+ children: label
1342
+ })
1343
+ }), /*#__PURE__*/jsx(CreatableSelect, _objectSpread$6({
1344
+ isMulti: true,
1345
+ required: true,
1346
+ classNamePrefix: "neeto-ui-react-select",
1347
+ components: CUSTOM_COMPONENTS,
1348
+ menuIsOpen: false,
1349
+ visibleDomainsCount: 3,
1350
+ className: classnames("neeto-ui-react-select__container neeto-ui-react-select__container--medium neeto-ui-email-input__select", {
1351
+ "neeto-ui-react-select__container--error": !!error
1352
+ }),
1353
+ styles: _objectSpread$6(_objectSpread$6({}, CUSTOM_STYLES), {}, {
1354
+ control: mergeLeft({
1355
+ maxHeight: "200px",
1356
+ overflowY: "auto"
1357
+ })
1358
+ }),
1359
+ onBlur: handleBlur,
1360
+ onFocus: function onFocus() {
1361
+ return setIsFocused(true);
1362
+ },
1363
+ onInputChange: setInputValue,
1364
+ onKeyDown: handleKeyDown
1365
+ }, _objectSpread$6({
1366
+ inputValue: inputValue,
1367
+ isFocused: isFocused,
1368
+ onChange: onChange,
1369
+ onCreateOption: onCreateOption,
1370
+ value: value
1371
+ }, otherProps))), !!error && /*#__PURE__*/jsxs("p", {
1372
+ className: "neeto-ui-input__error",
1373
+ "data-cy": "".concat(hyphenize(label), "-input-error"),
1374
+ children: [formatErrorMessage(error), isFilterDomainsLinkVisible && /*#__PURE__*/jsxs("span", {
1375
+ className: "neeto-ui-font-semibold cursor-pointer",
1376
+ onClick: handleFilterDomains,
1377
+ children: [ERROR_MESSAGE_DELIMITER, t("neetoForm.domainRestriction.removeInvalidDomains")]
1378
+ })]
1379
+ }), /*#__PURE__*/jsx("p", {
1380
+ className: "neeto-ui-input__help-text",
1381
+ "data-cy": "".concat(hyphenize(label), "-input-help"),
1382
+ children: t("neetoForm.domainRestriction.helpText")
1383
+ })]
1384
+ });
1385
+ };
1386
+
1387
+ var validateDomains = function validateDomains(value) {
1388
+ var schema = yup.array().of(yup.string().test("verify domains", t("neetoForm.error.invalidDomain"), function (domain) {
1389
+ return VALID_DOMAIN_REGEX.test(domain);
1390
+ })).ensure().compact().min(1, t("neetoForm.error.minOneEntity", {
1391
+ entity: t("neetoForm.common.domain")
1392
+ }));
1393
+
1394
+ // eslint-disable-next-line no-async-promise-executor
1395
+ return new Promise( /*#__PURE__*/function () {
1396
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve) {
1397
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1398
+ while (1) switch (_context.prev = _context.next) {
1399
+ case 0:
1400
+ _context.prev = 0;
1401
+ _context.next = 3;
1402
+ return schema.validate(value);
1403
+ case 3:
1404
+ resolve(undefined);
1405
+ _context.next = 9;
1406
+ break;
1407
+ case 6:
1408
+ _context.prev = 6;
1409
+ _context.t0 = _context["catch"](0);
1410
+ resolve(_context.t0.message);
1411
+ case 9:
1412
+ case "end":
1413
+ return _context.stop();
1414
+ }
1415
+ }, _callee, null, [[0, 6]]);
1416
+ }));
1417
+ return function (_x) {
1418
+ return _ref.apply(this, arguments);
1419
+ };
1420
+ }());
1421
+ };
1422
+
1423
+ var RestrictedDomains = function RestrictedDomains() {
1424
+ var _useField = useField({
1425
+ name: "restrictedDomains",
1426
+ validate: validateDomains
1427
+ }),
1428
+ _useField2 = _slicedToArray(_useField, 3),
1429
+ _useField2$0$value = _useField2[0].value,
1430
+ domains = _useField2$0$value === void 0 ? [] : _useField2$0$value,
1431
+ meta = _useField2[1],
1432
+ _useField2$ = _useField2[2],
1433
+ setValue = _useField2$.setValue,
1434
+ setTouched = _useField2$.setTouched;
1435
+ var _useTranslation = useTranslation(),
1436
+ t = _useTranslation.t;
1437
+ var formattedDomains = map(formatDomainInputOptions, domains);
1438
+ return /*#__PURE__*/jsx("div", {
1439
+ className: "mb-4",
1440
+ children: /*#__PURE__*/jsx(MultiDomainInput, {
1441
+ error: meta.touched ? meta.error : "",
1442
+ label: t("neetoForm.domainRestriction.description"),
1443
+ name: "restrictedDomains",
1444
+ value: formattedDomains,
1445
+ onBlur: function onBlur() {
1446
+ return setTouched(true);
1447
+ },
1448
+ onChange: function onChange(value) {
1449
+ return setValue(nullSafe(pluck)("value", value));
1450
+ }
1451
+ })
1452
+ });
1453
+ };
1454
+
1455
+ function ownKeys$5(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1456
+ function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1457
+ var Email = function Email(_ref) {
1458
+ var _ref$domainRestrictio = _ref.domainRestrictionHelpDocUrl,
1459
+ domainRestrictionHelpDocUrl = _ref$domainRestrictio === void 0 ? "" : _ref$domainRestrictio;
1460
+ var _useFormikContext = useFormikContext(),
1461
+ _useFormikContext$val = _useFormikContext.values.isDomainRestrictionEnabled,
1462
+ isDomainRestrictionEnabled = _useFormikContext$val === void 0 ? false : _useFormikContext$val;
1463
+ var _useTranslation = useTranslation(),
1464
+ t = _useTranslation.t;
1465
+ return /*#__PURE__*/jsxs("div", {
1466
+ className: "flex flex-col space-y-4",
1467
+ children: [/*#__PURE__*/jsx(SwitchBlock, {
1468
+ className: "mt-4",
1469
+ name: "isDomainRestrictionEnabled",
1470
+ title: /*#__PURE__*/jsxs("div", {
1471
+ className: "flex gap-2",
1472
+ children: [t("neetoForm.domainRestriction.label"), /*#__PURE__*/jsx(HelpPopover, _objectSpread$5({
1473
+ description: t("neetoForm.domainRestriction.popoverDescription"),
1474
+ popoverProps: {
1475
+ position: "top"
1476
+ }
1477
+ }, domainRestrictionHelpDocUrl && {
1478
+ helpLinkProps: {
1479
+ href: domainRestrictionHelpDocUrl
1480
+ }
1481
+ }))]
1482
+ })
1483
+ }), isDomainRestrictionEnabled && /*#__PURE__*/jsx(RestrictedDomains, {})]
1484
+ });
1485
+ };
1486
+
1487
+ var FileGroup = function FileGroup(_ref) {
1488
+ var name = _ref.name,
1489
+ label = _ref.label,
1490
+ checked = _ref.checked,
1491
+ handleAllowedFileTypesChange = _ref.handleAllowedFileTypesChange;
1492
+ return /*#__PURE__*/jsx(Checkbox, {
1493
+ checked: checked,
1494
+ label: label,
1495
+ name: name,
1496
+ "data-cy": "neeto-form-engine-file-type-".concat(name),
1497
+ id: name,
1498
+ onChange: handleAllowedFileTypesChange
1499
+ });
1500
+ };
1501
+
1502
+ var buildFileTypesList = function buildFileTypesList(fileTypes) {
1503
+ return (fileTypes !== null && fileTypes !== void 0 ? fileTypes : "").split(", ");
1504
+ };
1505
+ var getAllowedFileTypes = function getAllowedFileTypes(_ref) {
1506
+ var type = _ref.type,
1507
+ isChecked = _ref.isChecked,
1508
+ allowedFileTypes = _ref.allowedFileTypes;
1509
+ var fileTypes = buildFileTypesList(allowedFileTypes);
1510
+ if (isChecked) {
1511
+ var fileTypesSet = new Set([].concat(_toConsumableArray(FILE_TYPES_MAP[type]), _toConsumableArray(fileTypes)));
1512
+ return Array.from(fileTypesSet).join(", ");
1513
+ }
1514
+ var newFileTypes = difference(fileTypes, FILE_TYPES_MAP[type]);
1515
+ return newFileTypes.join(", ");
1516
+ };
1517
+ var isFileTypeEnabled = function isFileTypeEnabled(type, allowedFileTypes) {
1518
+ var fileTypes = buildFileTypesList(allowedFileTypes);
1519
+ return isEmpty(difference(FILE_TYPES_MAP[type], fileTypes));
1520
+ };
1521
+
1522
+ var FileUpload = function FileUpload() {
1523
+ var _useTranslation = useTranslation(),
1524
+ t = _useTranslation.t;
1525
+ var _useFormikContext = useFormikContext(),
1526
+ values = _useFormikContext.values,
1527
+ setFieldValue = _useFormikContext.setFieldValue;
1528
+ var allowedFileTypes = prop("allowedFileTypes", values);
1529
+ var handleAllowedFileTypesChange = function handleAllowedFileTypesChange(_ref) {
1530
+ var _ref$target = _ref.target,
1531
+ fileType = _ref$target.name,
1532
+ checked = _ref$target.checked;
1533
+ return setFieldValue("allowedFileTypes", getAllowedFileTypes({
1534
+ type: fileType,
1535
+ isChecked: checked,
1536
+ allowedFileTypes: allowedFileTypes
1537
+ }));
1538
+ };
1539
+ return /*#__PURE__*/jsxs(Fragment, {
1540
+ children: [/*#__PURE__*/jsx("div", {
1541
+ className: "w-full",
1542
+ children: /*#__PURE__*/jsx(Checkbox$1, {
1543
+ id: "multipleFilesAllowed",
1544
+ label: t("neetoForm.fileUpload.enableMultipleFilesUpload"),
1545
+ name: "multipleFilesAllowed"
1546
+ })
1547
+ }), /*#__PURE__*/jsxs("div", {
1548
+ className: "flex flex-col space-y-3",
1549
+ children: [/*#__PURE__*/jsx(Typography, {
1550
+ style: "body1",
1551
+ weight: "semibold",
1552
+ children: t("neetoForm.fileUpload.fileTypes")
1553
+ }), /*#__PURE__*/jsx("div", {
1554
+ className: "flex space-x-4",
1555
+ children: FILE_GROUPS.map(function (_ref2) {
1556
+ var name = _ref2.name,
1557
+ label = _ref2.label;
1558
+ return /*#__PURE__*/createElement(FileGroup, {
1559
+ handleAllowedFileTypesChange: handleAllowedFileTypesChange,
1560
+ label: label,
1561
+ name: name,
1562
+ checked: isFileTypeEnabled(name, allowedFileTypes),
1563
+ key: name
1564
+ });
1565
+ })
1566
+ })]
1567
+ })]
1568
+ });
1569
+ };
1570
+
1571
+ function ownKeys$4(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1572
+ function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1573
+ var defaultConfig = {
1574
+ strict: true,
1575
+ matchKey: "value"
1576
+ };
1577
+ var findOptionByValue = function findOptionByValue(value) {
1578
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1579
+ var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1580
+ var configObject = _objectSpread$4(_objectSpread$4({}, defaultConfig), config);
1581
+ var matchKey = configObject.matchKey,
1582
+ strict = configObject.strict;
1583
+ return options.find(function (option) {
1584
+ return (
1585
+ // eslint-disable-next-line eqeqeq
1586
+ strict ? option[matchKey] === value : option[matchKey] == value
1587
+ );
1588
+ });
1589
+ };
1590
+ var filterOptionsByValues = function filterOptionsByValues() {
1591
+ var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1592
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1593
+ var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1594
+ var configObject = _objectSpread$4(_objectSpread$4({}, defaultConfig), config);
1595
+ var matchKey = configObject.matchKey,
1596
+ strict = configObject.strict;
1597
+ return options.filter(function (option) {
1598
+ return values.some(function (value) {
1599
+ return (
1600
+ // eslint-disable-next-line eqeqeq
1601
+ strict ? option[matchKey] === value : option[matchKey] == value
1602
+ );
1603
+ });
1604
+ });
1605
+ };
1606
+ var destroyFromList = function destroyFromList(items, index) {
1607
+ var itemToRemove = items[index];
1608
+ if (itemToRemove) {
1609
+ var nextItems = _toConsumableArray(items);
1610
+ nextItems.splice(index, 1);
1611
+ if (itemToRemove.id) {
1612
+ nextItems.push(_objectSpread$4(_objectSpread$4({}, itemToRemove), {}, {
1613
+ _destroy: true
1614
+ }));
1615
+ }
1616
+ return nextItems;
1617
+ }
1618
+ return items;
1619
+ };
1620
+ var insertToList = function insertToList(items, item, index) {
1621
+ var nextItems = _toConsumableArray(items !== null && items !== void 0 ? items : []);
1622
+ nextItems.splice(index, 0, item);
1623
+ return nextItems;
1624
+ };
1625
+ var pushToList = function pushToList(items, item) {
1626
+ var nextItems = _toConsumableArray(items !== null && items !== void 0 ? items : []);
1627
+ nextItems.push(item);
1628
+ return nextItems;
1629
+ };
1630
+ var formHelpers = {
1631
+ findOptionByValue: findOptionByValue,
1632
+ filterOptionsByValues: filterOptionsByValues,
1633
+ destroyFromList: destroyFromList,
1634
+ insertToList: insertToList,
1635
+ pushToList: pushToList
1636
+ };
1637
+
1638
+ function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1639
+ function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1640
+ var Options = function Options(_ref) {
1641
+ var questionProps = _ref.questionProps;
1642
+ var _useTranslation = useTranslation(),
1643
+ t = _useTranslation.t;
1644
+ var _useBuildFormStore = useBuildFormStore(function (store) {
1645
+ var _store$formState;
1646
+ return {
1647
+ selectedLanguage: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["selectedLanguage"]
1648
+ };
1649
+ }, shallow),
1650
+ selectedLanguage = _useBuildFormStore.selectedLanguage;
1651
+ var _useField = useField("optionsAttributes"),
1652
+ _useField2 = _slicedToArray(_useField, 3),
1653
+ optionsAttributes = _useField2[0].value;
1654
+ _useField2[1];
1655
+ var setOptionsAttributes = _useField2[2].setValue;
1656
+ var _ref2 = questionProps || {},
1657
+ _ref2$optionLabelProp = _ref2.optionLabelProps,
1658
+ optionLabelProps = _ref2$optionLabelProp === void 0 ? {} : _ref2$optionLabelProp,
1659
+ _ref2$freezeOptions = _ref2.freezeOptions,
1660
+ freezeOptions = _ref2$freezeOptions === void 0 ? false : _ref2$freezeOptions,
1661
+ _ref2$disableAddOptio = _ref2.disableAddOption,
1662
+ disableAddOption = _ref2$disableAddOptio === void 0 ? false : _ref2$disableAddOptio,
1663
+ _ref2$disableRemoveOp = _ref2.disableRemoveOption,
1664
+ disableRemoveOption = _ref2$disableRemoveOp === void 0 ? false : _ref2$disableRemoveOp;
1665
+ var handleRemoveOption = function handleRemoveOption(index) {
1666
+ var nextOptions = formHelpers.destroyFromList(optionsAttributes, index);
1667
+ setOptionsAttributes(nextOptions);
1668
+ };
1669
+ var isManageOptionDisabled = isFunction(freezeOptions) ? freezeOptions(selectedLanguage) : freezeOptions;
1670
+ var isAddOptionDisabled = disableAddOption || isManageOptionDisabled;
1671
+ var isRemoveOptionDisabled = disableRemoveOption || isManageOptionDisabled;
1672
+ return /*#__PURE__*/jsx("div", {
1673
+ className: "w-full",
1674
+ children: /*#__PURE__*/jsx(FieldArray, {
1675
+ name: "optionsAttributes",
1676
+ children: function children(_ref3) {
1677
+ var handlePush = _ref3.handlePush;
1678
+ return /*#__PURE__*/jsxs(Fragment, {
1679
+ children: [/*#__PURE__*/jsx(Label, _objectSpread$3(_objectSpread$3({
1680
+ className: "mb-1 block"
1681
+ }, optionLabelProps), {}, {
1682
+ children: t("neetoForm.questions.common.questionFields.field.options")
1683
+ })), /*#__PURE__*/jsx("div", {
1684
+ className: "flex w-2/3 flex-col space-y-2",
1685
+ children: optionsAttributes === null || optionsAttributes === void 0 ? void 0 : optionsAttributes.map(function (option, index) {
1686
+ var _option$id;
1687
+ return !option._destroy && /*#__PURE__*/jsxs("div", {
1688
+ className: "flex items-start gap-1",
1689
+ "data-cy": "neeto-form-engine-option-".concat(index),
1690
+ children: [/*#__PURE__*/jsx(InputWithMaxLength, {
1691
+ required: true,
1692
+ disabled: isManageOptionDisabled,
1693
+ name: "optionsAttributes.".concat(index, ".label"),
1694
+ placeholder: t("neetoForm.questions.common.questionFields.field.numberedOption", {
1695
+ number: index + 1
1696
+ })
1697
+ }), !isRemoveOptionDisabled && /*#__PURE__*/jsx(Button, {
1698
+ "data-cy": "neeto-form-engine-delete-option-button",
1699
+ icon: Delete,
1700
+ size: "small",
1701
+ style: "text",
1702
+ className: classnames({
1703
+ invisible: index < MINIMUM_OPTIONS
1704
+ }),
1705
+ tooltipProps: {
1706
+ position: "top",
1707
+ content: t("neetoForm.common.delete")
1708
+ },
1709
+ onClick: function onClick() {
1710
+ return handleRemoveOption(index);
1711
+ }
1712
+ })]
1713
+ }, "question-option-".concat((_option$id = option.id) !== null && _option$id !== void 0 ? _option$id : index));
1714
+ })
1715
+ }), !isAddOptionDisabled && /*#__PURE__*/jsx("div", {
1716
+ className: "mt-3 w-full",
1717
+ children: /*#__PURE__*/jsx(Button, {
1718
+ "data-cy": "neeto-form-engine-add-option-button",
1719
+ icon: Plus,
1720
+ iconPosition: "left",
1721
+ size: "small",
1722
+ style: "text",
1723
+ label: t("neetoForm.questions.common.questionFields.field.addOption"),
1724
+ onClick: handlePush({
1725
+ label: ""
1726
+ })
1727
+ })
1728
+ })]
1729
+ });
1730
+ }
1731
+ })
1732
+ });
1733
+ };
1734
+
1735
+ var RatingItem = function RatingItem(_ref) {
1736
+ var children = _ref.children;
1737
+ return /*#__PURE__*/jsx("div", {
1738
+ className: "flex w-16 flex-col items-center gap-3",
1739
+ children: children
1740
+ });
1741
+ };
1742
+ var Rating = function Rating() {
1743
+ return /*#__PURE__*/jsx("div", {
1744
+ className: "flex flex-col",
1745
+ children: /*#__PURE__*/jsx("div", {
1746
+ className: "w-full",
1747
+ children: /*#__PURE__*/jsx("div", {
1748
+ className: "flex gap-6",
1749
+ children: RATING_OPTIONS.map(function (_ref2) {
1750
+ var Icon = _ref2.icon,
1751
+ name = _ref2.name,
1752
+ color = _ref2.color;
1753
+ return /*#__PURE__*/jsxs(RatingItem, {
1754
+ children: [/*#__PURE__*/jsx(Icon, {
1755
+ color: color,
1756
+ size: 48
1757
+ }), /*#__PURE__*/jsx(InputWithMaxLength, {
1758
+ name: name,
1759
+ "data-cy": "neeto-form-engine-".concat(hyphenate(name))
1760
+ })]
1761
+ }, name);
1762
+ })
1763
+ })
1764
+ })
1765
+ });
1766
+ };
1767
+
1768
+ var StarRating = function StarRating() {
1769
+ var _useTranslation = useTranslation(),
1770
+ t = _useTranslation.t;
1771
+ var _useFormikContext = useFormikContext(),
1772
+ setFieldValue = _useFormikContext.setFieldValue;
1773
+ var _useField = useField("iconType"),
1774
+ _useField2 = _slicedToArray(_useField, 3),
1775
+ iconType = _useField2[0].value;
1776
+ _useField2[1];
1777
+ var setIconType = _useField2[2].setValue;
1778
+ return /*#__PURE__*/jsxs(Fragment, {
1779
+ children: [/*#__PURE__*/jsxs("div", {
1780
+ className: "flex space-x-4",
1781
+ children: [/*#__PURE__*/jsx(Select, {
1782
+ className: "w-1/2",
1783
+ "data-cy": "neeto-form-engine-star-rating-min-value",
1784
+ label: t("neetoForm.common.start"),
1785
+ name: "minValue",
1786
+ options: STAR_RATING_MIN_VALUE_OPTIONS,
1787
+ onChange: function onChange(option) {
1788
+ return setFieldValue("minValue", option === null || option === void 0 ? void 0 : option.value);
1789
+ }
1790
+ }), /*#__PURE__*/jsx(Select, {
1791
+ className: "w-1/2",
1792
+ "data-cy": "neeto-form-engine-star-rating-max-value",
1793
+ label: t("neetoForm.common.end"),
1794
+ name: "maxValue",
1795
+ options: STAR_RATING_MAX_VALUE_OPTIONS,
1796
+ onChange: function onChange(option) {
1797
+ return setFieldValue("maxValue", option === null || option === void 0 ? void 0 : option.value);
1798
+ }
1799
+ })]
1800
+ }), /*#__PURE__*/jsx(Label, {
1801
+ children: t("neetoForm.common.shape")
1802
+ }), /*#__PURE__*/jsx("div", {
1803
+ className: "flex gap-2",
1804
+ children: Object.entries(STAR_RATING_ICONS_MAP).map(function (_ref) {
1805
+ var _ref2 = _slicedToArray(_ref, 2),
1806
+ name = _ref2[0],
1807
+ IconType = _ref2[1];
1808
+ var isActive = name === iconType;
1809
+ return /*#__PURE__*/jsx("div", {
1810
+ "data-cy": "neeto-form-engine-rating-icon-".concat(name),
1811
+ className: classnames("flex h-10 w-10 items-center justify-center gap-2", "neeto-ui-border-gray-800 neeto-ui-rounded-full cursor-pointer border", "transition-all duration-300 ease-in-out", {
1812
+ "neeto-ui-text-gray-800 neeto-ui-bg-gray-200": !isActive,
1813
+ "neeto-ui-text-white neeto-ui-bg-gray-800": isActive
1814
+ }),
1815
+ onClick: function onClick() {
1816
+ return setIconType(name);
1817
+ },
1818
+ children: /*#__PURE__*/jsx(IconType, {})
1819
+ }, name);
1820
+ })
1821
+ })]
1822
+ });
1823
+ };
1824
+
1825
+ var CHECKBOX = QUESTION_TYPES.CHECKBOX,
1826
+ RADIO = QUESTION_TYPES.RADIO,
1827
+ DROPDOWN = QUESTION_TYPES.DROPDOWN,
1828
+ STAR_RATING = QUESTION_TYPES.STAR_RATING,
1829
+ RATING = QUESTION_TYPES.RATING,
1830
+ FILE_UPLOAD = QUESTION_TYPES.FILE_UPLOAD,
1831
+ CAPTCHA = QUESTION_TYPES.CAPTCHA,
1832
+ EMAIL = QUESTION_TYPES.EMAIL;
1833
+ var transformValueForOption = function transformValueForOption(_ref) {
1834
+ var label = _ref.label,
1835
+ type = _ref.type;
1836
+ return "".concat(slugify(label), "-").concat(type);
1837
+ };
1838
+ var renderAdditionalData = function renderAdditionalData(_ref2) {
1839
+ var kind = _ref2.kind,
1840
+ questionProps = _ref2.questionProps,
1841
+ domainRestrictionHelpDocUrl = _ref2.domainRestrictionHelpDocUrl,
1842
+ enableDomainRestriction = _ref2.enableDomainRestriction;
1843
+ switch (kind) {
1844
+ case CHECKBOX:
1845
+ case RADIO:
1846
+ case DROPDOWN:
1847
+ return /*#__PURE__*/jsx(Options, {
1848
+ questionProps: questionProps
1849
+ });
1850
+ case RATING:
1851
+ return /*#__PURE__*/jsx(Rating, {});
1852
+ case STAR_RATING:
1853
+ return /*#__PURE__*/jsx(StarRating, {});
1854
+ case FILE_UPLOAD:
1855
+ return /*#__PURE__*/jsx(FileUpload, {});
1856
+ case CAPTCHA:
1857
+ return /*#__PURE__*/jsx(Captcha, {});
1858
+ case EMAIL:
1859
+ return enableDomainRestriction ? /*#__PURE__*/jsx(Email, {
1860
+ domainRestrictionHelpDocUrl: domainRestrictionHelpDocUrl
1861
+ }) : null;
1862
+ default:
1863
+ return null;
1864
+ }
1865
+ };
1866
+ var resolveActionComponent = function resolveActionComponent(action) {
1867
+ return equals(action, QUESTION_ACTIONS.ADD) ? Add : Edit;
1868
+ };
1869
+ var getQuestionKind = function getQuestionKind(questionKinds, pattern) {
1870
+ var questionKind = findBy(pattern, questionKinds);
1871
+ return questionKind ? assoc("kind", questionKind.type, questionKind) : null;
1872
+ };
1873
+ var buildKindOptions = function buildKindOptions(kinds) {
1874
+ return kinds.map(function (_ref3) {
1875
+ var label = _ref3.label,
1876
+ type = _ref3.type;
1877
+ return {
1878
+ label: label,
1879
+ value: transformValueForOption({
1880
+ label: label,
1881
+ type: type
1882
+ })
1883
+ };
1884
+ });
1885
+ };
1886
+ var extractKindFromOption = pipe(split("-"), last);
1887
+ var buildDefaultValueForKind = function buildDefaultValueForKind(questionKind) {
1888
+ return isPresent(questionKind) ? {
1889
+ value: transformValueForOption(questionKind)
1890
+ } : undefined;
1891
+ };
1892
+
1893
+ var _excluded$1 = ["isOpen", "onClose", "action", "question", "availableQuestionKinds", "fieldCodeHelpDocUrl", "domainRestrictionHelpDocUrl"];
1894
+ 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; }
1895
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1896
+ var ManageQuestionPane = function ManageQuestionPane(_ref) {
1897
+ var isOpen = _ref.isOpen,
1898
+ onClose = _ref.onClose,
1899
+ action = _ref.action,
1900
+ question = _ref.question,
1901
+ availableQuestionKinds = _ref.availableQuestionKinds,
1902
+ fieldCodeHelpDocUrl = _ref.fieldCodeHelpDocUrl,
1903
+ domainRestrictionHelpDocUrl = _ref.domainRestrictionHelpDocUrl,
1904
+ props = _objectWithoutProperties(_ref, _excluded$1);
1905
+ var initialFocusRef = useRef(null);
1906
+ var Component = resolveActionComponent(action);
1907
+ return /*#__PURE__*/jsx(Pane, {
1908
+ initialFocusRef: initialFocusRef,
1909
+ isOpen: isOpen,
1910
+ onClose: onClose,
1911
+ children: /*#__PURE__*/jsx(Component, _objectSpread$2({}, _objectSpread$2({
1912
+ availableQuestionKinds: availableQuestionKinds,
1913
+ domainRestrictionHelpDocUrl: domainRestrictionHelpDocUrl,
1914
+ fieldCodeHelpDocUrl: fieldCodeHelpDocUrl,
1915
+ initialFocusRef: initialFocusRef,
1916
+ isOpen: isOpen,
1917
+ onClose: onClose,
1918
+ question: question
1919
+ }, props)))
1920
+ });
1921
+ };
1922
+
1923
+ var AddQuestion = withT(function (_ref) {
1924
+ var t = _ref.t,
1925
+ onAdd = _ref.onAdd,
1926
+ disabledAddButtonTooltipProps = _ref.disabledAddButtonTooltipProps,
1927
+ isDisabled = _ref.isDisabled;
1928
+ return /*#__PURE__*/jsx(Tooltip, {
1929
+ disabled: !isDisabled,
1930
+ position: "top",
1931
+ content: (disabledAddButtonTooltipProps === null || disabledAddButtonTooltipProps === void 0 ? void 0 : disabledAddButtonTooltipProps.content) || t("neetoForm.questions.common.primaryPanel.noQuestionLeft"),
1932
+ children: /*#__PURE__*/jsx("span", {
1933
+ children: /*#__PURE__*/jsx(Button, {
1934
+ "data-cy": "neeto-form-engine-add-question",
1935
+ disabled: isDisabled,
1936
+ icon: Plus,
1937
+ iconPosition: "left",
1938
+ label: t("neetoForm.questions.common.primaryPanel.addQuestion"),
1939
+ style: "link",
1940
+ onClick: onAdd
1941
+ })
1942
+ })
1943
+ });
1944
+ });
1945
+
1946
+ var _excluded = ["questionKinds", "onValueChange", "formId", "isDeletable", "isRequiredField", "submitButtonProps", "cancelButtonProps", "isKindAlreadyActive", "getActiveKindDetails", "isDisabledFieldLabel", "disabledAddButtonTooltipProps", "enableFieldCode", "isFormEnabled", "savedTitle", "formTitle", "formDescription", "selectedLanguage", "availableLanguages", "onLanguageChange", "additionalActionOptions", "isReordering", "additionalQuestionKindPattern", "showActionBlock", "buildRequestArgs", "fieldCodeHelpDocUrl", "enableDomainRestriction", "domainRestrictionHelpDocUrl"];
1947
+ 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; }
1948
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1949
+ var Form = function Form(_ref) {
1950
+ var questionKinds = _ref.questionKinds,
1951
+ onValueChange = _ref.onValueChange,
1952
+ formId = _ref.formId,
1953
+ isDeletable = _ref.isDeletable,
1954
+ isRequiredField = _ref.isRequiredField,
1955
+ submitButtonProps = _ref.submitButtonProps,
1956
+ cancelButtonProps = _ref.cancelButtonProps,
1957
+ isKindAlreadyActive = _ref.isKindAlreadyActive,
1958
+ getActiveKindDetails = _ref.getActiveKindDetails,
1959
+ isDisabledFieldLabel = _ref.isDisabledFieldLabel,
1960
+ disabledAddButtonTooltipProps = _ref.disabledAddButtonTooltipProps,
1961
+ enableFieldCode = _ref.enableFieldCode,
1962
+ isFormEnabled = _ref.isFormEnabled,
1963
+ savedTitle = _ref.savedTitle,
1964
+ formTitle = _ref.formTitle,
1965
+ formDescription = _ref.formDescription,
1966
+ selectedLanguage = _ref.selectedLanguage,
1967
+ availableLanguages = _ref.availableLanguages,
1968
+ onLanguageChange = _ref.onLanguageChange,
1969
+ additionalActionOptions = _ref.additionalActionOptions,
1970
+ isReordering = _ref.isReordering,
1971
+ additionalQuestionKindPattern = _ref.additionalQuestionKindPattern,
1972
+ showActionBlock = _ref.showActionBlock,
1973
+ buildRequestArgs = _ref.buildRequestArgs,
1974
+ fieldCodeHelpDocUrl = _ref.fieldCodeHelpDocUrl,
1975
+ enableDomainRestriction = _ref.enableDomainRestriction,
1976
+ domainRestrictionHelpDocUrl = _ref.domainRestrictionHelpDocUrl,
1977
+ formDomProps = _objectWithoutProperties(_ref, _excluded);
1978
+ var containerRef = useRef();
1979
+ var _useTranslation = useTranslation(),
1980
+ t = _useTranslation.t;
1981
+ var formikContext = useFormikContext();
1982
+ var _useState = useState(null),
1983
+ _useState2 = _slicedToArray(_useState, 2),
1984
+ selectedQuestion = _useState2[0],
1985
+ setSelectedQuestion = _useState2[1];
1986
+ var _useState3 = useState(""),
1987
+ _useState4 = _slicedToArray(_useState3, 2),
1988
+ selectedAction = _useState4[0],
1989
+ setSelectedAction = _useState4[1];
1990
+ var _useState5 = useState(false),
1991
+ _useState6 = _slicedToArray(_useState5, 2),
1992
+ isDeleteAlertOpen = _useState6[0],
1993
+ setIsDeleteAlertOpen = _useState6[1];
1994
+ var _useState7 = useState(false),
1995
+ _useState8 = _slicedToArray(_useState7, 2),
1996
+ isManageQuestionPaneOpen = _useState8[0],
1997
+ setIsManageQuestionPaneOpen = _useState8[1];
1998
+ var values = formikContext.values,
1999
+ setFieldValue = formikContext.setFieldValue,
2000
+ dirty = formikContext.dirty,
2001
+ isSubmitting = formikContext.isSubmitting,
2002
+ isValid = formikContext.isValid,
2003
+ errors = formikContext.errors,
2004
+ submitForm = formikContext.submitForm,
2005
+ resetForm = formikContext.resetForm;
2006
+ var setFormData = useBuildFormStore(prop("setFormData"));
2007
+ var _useCreateQuestion = useCreateQuestion(formId, selectedLanguage, {
2008
+ onSuccess: showThumbsUpToastr
2009
+ }),
2010
+ createQuestion = _useCreateQuestion.mutate;
2011
+ useEffect(function () {
2012
+ setFormData({
2013
+ formId: formId,
2014
+ enabled: isFormEnabled,
2015
+ title: savedTitle,
2016
+ values: values,
2017
+ dirty: dirty,
2018
+ isSubmitting: isSubmitting,
2019
+ isValid: isValid,
2020
+ errors: errors,
2021
+ submitForm: submitForm,
2022
+ resetForm: resetForm,
2023
+ selectedLanguage: selectedLanguage
2024
+ });
2025
+ }, [formId, isFormEnabled, savedTitle, setFormData, values, dirty, isSubmitting, isValid, errors, submitForm, resetForm, selectedLanguage]);
2026
+ var questions = values.questions;
2027
+ var handleSelect = function handleSelect(question) {
2028
+ setSelectedQuestion(question);
2029
+ };
2030
+ var handleAdd = function handleAdd() {
2031
+ setSelectedAction(QUESTION_ACTIONS.ADD);
2032
+ setIsManageQuestionPaneOpen(true);
2033
+ };
2034
+ var handleEdit = function handleEdit() {
2035
+ setSelectedAction(QUESTION_ACTIONS.EDIT);
2036
+ setIsManageQuestionPaneOpen(true);
2037
+ };
2038
+ var handleClone = function handleClone() {
2039
+ var values = duplicateFieldData({
2040
+ item: selectedQuestion,
2041
+ questionKinds: availableQuestionKinds,
2042
+ questions: questions
2043
+ });
2044
+ var displayOrder = selectedQuestion.displayOrder + 1;
2045
+ var attributes = mergeLeft({
2046
+ displayOrder: displayOrder
2047
+ }, values);
2048
+ var payload = _objectSpread$1({
2049
+ language: selectedLanguage,
2050
+ neetoFormQuestion: formatQuestionAttributesForClone(attributes)
2051
+ }, buildRequestArgs);
2052
+ createQuestion(payload, {
2053
+ onSuccess: function onSuccess(_ref2) {
2054
+ var questions = _ref2.questions;
2055
+ var newQuestion = findBy({
2056
+ displayOrder: displayOrder
2057
+ }, questions);
2058
+ handleSelect(newQuestion);
2059
+ }
2060
+ });
2061
+ };
2062
+ var handleDelete = function handleDelete() {
2063
+ setIsDeleteAlertOpen(true);
2064
+ };
2065
+ useOnClickOutside(containerRef, function () {
2066
+ return handleSelect(null);
2067
+ }, {
2068
+ enabled: !(isDeleteAlertOpen || isManageQuestionPaneOpen)
2069
+ });
2070
+ useEffect(function () {
2071
+ onValueChange === null || onValueChange === void 0 || onValueChange(questions);
2072
+ }, [questions]);
2073
+ var availableQuestionKinds = getAvailableQuestionKinds({
2074
+ allQuestionKinds: questionKinds,
2075
+ activeQuestions: questions,
2076
+ isKindAlreadyActive: isKindAlreadyActive
2077
+ });
2078
+ var hasActiveQuestions = questions && questions.length && questions.some(function (question) {
2079
+ return question._destroy !== true;
2080
+ });
2081
+ var handleLanguageChange = function handleLanguageChange(code) {
2082
+ resetForm();
2083
+ onLanguageChange(code);
2084
+ };
2085
+ var richTextQuestions = filterBy({
2086
+ kind: includes(__, RICH_TEXT_QUESTIONS)
2087
+ }, questions);
2088
+ var resetFormData = function resetFormData() {
2089
+ resetForm();
2090
+ setFormData({
2091
+ richTextFieldsToReset: pluck("fieldCode", richTextQuestions)
2092
+ });
2093
+ };
2094
+ return /*#__PURE__*/jsxs(Fragment, {
2095
+ children: [/*#__PURE__*/jsx(DeleteAlert, {
2096
+ handleSelect: handleSelect,
2097
+ selectedQuestion: selectedQuestion,
2098
+ isOpen: isDeleteAlertOpen,
2099
+ languagesCount: availableLanguages.length,
2100
+ onClose: function onClose() {
2101
+ return setIsDeleteAlertOpen(false);
2102
+ }
2103
+ }), /*#__PURE__*/jsxs(Form$3, _objectSpread$1(_objectSpread$1({
2104
+ className: "neeto-form-nano-form-wrapper flex h-full flex-col"
2105
+ }, formDomProps), {}, {
2106
+ noValidate: true,
2107
+ children: [formTitle && /*#__PURE__*/jsx(Overview, {
2108
+ additionalActionOptions: additionalActionOptions,
2109
+ availableLanguages: availableLanguages,
2110
+ selectedLanguage: selectedLanguage,
2111
+ description: formDescription,
2112
+ title: formTitle,
2113
+ onLanguageChange: handleLanguageChange
2114
+ }), /*#__PURE__*/jsx("div", {
2115
+ className: "neeto-form-nano-form-wrapper__body min-h-0 w-full flex-grow space-y-6 overflow-y-auto px-6 pb-6",
2116
+ children: hasActiveQuestions ? /*#__PURE__*/jsxs("div", {
2117
+ className: "space-y-6",
2118
+ ref: containerRef,
2119
+ children: [/*#__PURE__*/jsx(DragDropContext, {
2120
+ onDragEnd: function onDragEnd(_ref3) {
2121
+ var source = _ref3.source,
2122
+ destination = _ref3.destination;
2123
+ return handleFieldDragEnd({
2124
+ source: source,
2125
+ destination: destination,
2126
+ items: questions,
2127
+ setValue: setFieldValue
2128
+ });
2129
+ },
2130
+ children: /*#__PURE__*/jsx(Questions, {
2131
+ getActiveKindDetails: getActiveKindDetails,
2132
+ isDeletable: isDeletable,
2133
+ questions: questions,
2134
+ selectedQuestion: selectedQuestion,
2135
+ allQuestionKinds: questionKinds,
2136
+ onClone: handleClone,
2137
+ onDelete: handleDelete,
2138
+ onEdit: handleEdit,
2139
+ onSelect: handleSelect
2140
+ })
2141
+ }), /*#__PURE__*/jsx("div", {
2142
+ className: "mb-8 w-full",
2143
+ children: /*#__PURE__*/jsx(AddQuestion, {
2144
+ disabledAddButtonTooltipProps: disabledAddButtonTooltipProps,
2145
+ isDisabled: isEmpty(availableQuestionKinds),
2146
+ onAdd: handleAdd
2147
+ })
2148
+ })]
2149
+ }) : /*#__PURE__*/jsx(AddFirstQuestion, {
2150
+ children: /*#__PURE__*/jsx(AddQuestion, {
2151
+ disabledAddButtonTooltipProps: disabledAddButtonTooltipProps,
2152
+ isDisabled: isEmpty(availableQuestionKinds),
2153
+ onAdd: handleAdd
2154
+ })
2155
+ })
2156
+ }), (showActionBlock || dirty) && /*#__PURE__*/jsx("div", {
2157
+ className: "neeto-ui-border-gray-300 neeto-form-nano-form-wrapper__footer neeto-ui-bg-white sticky bottom-0 flex flex-shrink-0 justify-end border-t px-6 py-4",
2158
+ children: /*#__PURE__*/jsx(ActionBlock, {
2159
+ submitButtonProps: submitButtonProps,
2160
+ isSubmitting: isReordering,
2161
+ cancelButtonProps: _objectSpread$1({
2162
+ label: t("neetoForm.common.reset"),
2163
+ onClick: resetFormData
2164
+ }, cancelButtonProps)
2165
+ })
2166
+ }), /*#__PURE__*/jsx(ManageQuestionPane, {
2167
+ additionalQuestionKindPattern: additionalQuestionKindPattern,
2168
+ availableQuestionKinds: availableQuestionKinds,
2169
+ buildRequestArgs: buildRequestArgs,
2170
+ domainRestrictionHelpDocUrl: domainRestrictionHelpDocUrl,
2171
+ enableDomainRestriction: enableDomainRestriction,
2172
+ enableFieldCode: enableFieldCode,
2173
+ fieldCodeHelpDocUrl: fieldCodeHelpDocUrl,
2174
+ getActiveKindDetails: getActiveKindDetails,
2175
+ handleSelect: handleSelect,
2176
+ isDisabledFieldLabel: isDisabledFieldLabel,
2177
+ isRequiredField: isRequiredField,
2178
+ questions: questions,
2179
+ action: selectedAction,
2180
+ allQuestionKinds: questionKinds,
2181
+ isOpen: isManageQuestionPaneOpen,
2182
+ question: selectedQuestion,
2183
+ onClose: function onClose() {
2184
+ return setIsManageQuestionPaneOpen(false);
2185
+ }
2186
+ })]
2187
+ }))]
2188
+ });
2189
+ };
2190
+
2191
+ 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; }
2192
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2193
+ var BuildForm = function BuildForm(_ref) {
2194
+ var id = _ref.id,
2195
+ onUpdate = _ref.onUpdate,
2196
+ buildRequestArgs = _ref.buildRequestArgs,
2197
+ _ref$nonRemovableFiel = _ref.nonRemovableFields,
2198
+ nonRemovableFields = _ref$nonRemovableFiel === void 0 ? [] : _ref$nonRemovableFiel,
2199
+ _ref$requiredFields = _ref.requiredFields,
2200
+ requiredFields = _ref$requiredFields === void 0 ? [] : _ref$requiredFields,
2201
+ formDomProps = _ref.formDomProps,
2202
+ _ref$showActionBlock = _ref.showActionBlock,
2203
+ showActionBlock = _ref$showActionBlock === void 0 ? false : _ref$showActionBlock,
2204
+ submitButtonProps = _ref.submitButtonProps,
2205
+ cancelButtonProps = _ref.cancelButtonProps,
2206
+ questionKinds = _ref.questionKinds,
2207
+ _ref$isKindAlreadyAct = _ref.isKindAlreadyActive,
2208
+ isKindAlreadyActive = _ref$isKindAlreadyAct === void 0 ? isQuestionKindAlreadyActive : _ref$isKindAlreadyAct,
2209
+ _ref$getActiveKindDet = _ref.getActiveKindDetails,
2210
+ getActiveKindDetails = _ref$getActiveKindDet === void 0 ? getActiveQuestionKindDetails : _ref$getActiveKindDet,
2211
+ isQuestionDeletable = _ref.isQuestionDeletable,
2212
+ isFieldRequired = _ref.isFieldRequired,
2213
+ isFieldLabelDisabled = _ref.isFieldLabelDisabled,
2214
+ _ref$showLoader = _ref.showLoader,
2215
+ showLoader = _ref$showLoader === void 0 ? false : _ref$showLoader,
2216
+ _ref$kindUniqueOn = _ref.kindUniqueOn,
2217
+ kindUniqueOn = _ref$kindUniqueOn === void 0 ? ["type"] : _ref$kindUniqueOn,
2218
+ _ref$allowAdditionalG = _ref.allowAdditionalGuests,
2219
+ allowAdditionalGuests = _ref$allowAdditionalG === void 0 ? false : _ref$allowAdditionalG,
2220
+ disabledAddButtonTooltipProps = _ref.disabledAddButtonTooltipProps,
2221
+ _ref$enableFieldCode = _ref.enableFieldCode,
2222
+ enableFieldCode = _ref$enableFieldCode === void 0 ? false : _ref$enableFieldCode,
2223
+ _ref$availableLanguag = _ref.availableLanguages,
2224
+ availableLanguages = _ref$availableLanguag === void 0 ? DEFAULT_AVAILABLE_LANGUAGES : _ref$availableLanguag,
2225
+ formDescription = _ref.formDescription,
2226
+ _ref$formTitle = _ref.formTitle,
2227
+ formTitle = _ref$formTitle === void 0 ? "" : _ref$formTitle,
2228
+ _ref$selectedLanguage = _ref.selectedLanguage,
2229
+ selectedLanguage = _ref$selectedLanguage === void 0 ? "en" : _ref$selectedLanguage,
2230
+ _ref$onLanguageChange = _ref.onLanguageChange,
2231
+ onLanguageChange = _ref$onLanguageChange === void 0 ? noop : _ref$onLanguageChange,
2232
+ _ref$additionalAction = _ref.additionalActionOptions,
2233
+ additionalActionOptions = _ref$additionalAction === void 0 ? [] : _ref$additionalAction,
2234
+ additionalQuestionKindPattern = _ref.additionalQuestionKindPattern,
2235
+ fieldCodeHelpDocUrl = _ref.fieldCodeHelpDocUrl,
2236
+ _ref$enableDomainRest = _ref.enableDomainRestriction,
2237
+ enableDomainRestriction = _ref$enableDomainRest === void 0 ? true : _ref$enableDomainRest,
2238
+ domainRestrictionHelpDocUrl = _ref.domainRestrictionHelpDocUrl,
2239
+ className = _ref.className;
2240
+ var queryClient = useQueryClient();
2241
+ var _useReorderQuestions = useReorderQuestions(id, {
2242
+ onSuccess: showThumbsUpToastr
2243
+ }),
2244
+ reorderQuestions = _useReorderQuestions.mutate,
2245
+ isReordering = _useReorderQuestions.isPending;
2246
+ var _useFetchQuestions = useFetchQuestions({
2247
+ formId: id,
2248
+ language: selectedLanguage
2249
+ }),
2250
+ data = _useFetchQuestions.data,
2251
+ isLoading = _useFetchQuestions.isLoading,
2252
+ isQuestionsPending = _useFetchQuestions.isPending;
2253
+ var _ref2 = data || QUESTIONS_INITIAL_VALUE,
2254
+ isFormEnabled = _ref2.enabled,
2255
+ savedTitle = _ref2.title,
2256
+ questions = _ref2.questions,
2257
+ isQuestionsLoading = _ref2.isQuestionsLoading;
2258
+ useEffect(function () {
2259
+ if (data) {
2260
+ onUpdate === null || onUpdate === void 0 || onUpdate(data);
2261
+ }
2262
+ }, [data]);
2263
+ if (isLoading || showLoader && isQuestionsLoading && !isQuestionsPending) {
2264
+ return /*#__PURE__*/jsx("div", {
2265
+ className: "flex h-full w-full items-center justify-center py-6",
2266
+ children: /*#__PURE__*/jsx(PageLoader, {})
2267
+ });
2268
+ }
2269
+ var handleSubmit = function handleSubmit(_ref3, _ref4) {
2270
+ var questions = _ref3.questions;
2271
+ var setSubmitting = _ref4.setSubmitting;
2272
+ var payload = {
2273
+ neetoFormQuestions: {
2274
+ questions: buildReorderPayload(questions)
2275
+ }
2276
+ };
2277
+ reorderQuestions(payload, {
2278
+ onSettled: function onSettled() {
2279
+ return setSubmitting(false);
2280
+ }
2281
+ });
2282
+ };
2283
+ var onValueChange = function onValueChange(questions) {
2284
+ var _queryClient$getQuery = queryClient.getQueryState([QUERY_KEYS.QUESTIONS, id, selectedLanguage]),
2285
+ dataUpdateCount = _queryClient$getQuery.dataUpdateCount;
2286
+ if (dataUpdateCount > 0) {
2287
+ queryClient.setQueryData([QUERY_KEYS.QUESTIONS, "preview/".concat(id), selectedLanguage], assoc("questions", questions));
2288
+ }
2289
+ };
2290
+ var isDeletable = isQuestionDeletable !== null && isQuestionDeletable !== void 0 ? isQuestionDeletable : function (question) {
2291
+ return !nonRemovableFields.includes(question.kind);
2292
+ };
2293
+ var isRequiredField = isFieldRequired !== null && isFieldRequired !== void 0 ? isFieldRequired : function (_ref5) {
2294
+ var kind = _ref5.kind;
2295
+ return concat(MANDATORY_KINDS, requiredFields).includes(kind);
2296
+ };
2297
+ var isDisabledFieldLabel = isFieldLabelDisabled !== null && isFieldLabelDisabled !== void 0 ? isFieldLabelDisabled : function () {
2298
+ return false;
2299
+ };
2300
+ var defaultQuestionKinds = allowAdditionalGuests ? QUESTION_KINDS : removeBy({
2301
+ type: QUESTION_KIND.ADDITIONAL_GUESTS.value
2302
+ }, QUESTION_KINDS);
2303
+ return /*#__PURE__*/jsxs("div", {
2304
+ className: classnames("neeto-form-nano-form-outer-wrapper relative", className),
2305
+ children: [/*#__PURE__*/jsx(Formik, {
2306
+ enableReinitialize: true,
2307
+ initialValues: {
2308
+ questions: questions
2309
+ },
2310
+ onSubmit: handleSubmit,
2311
+ children: function children(_ref6) {
2312
+ var errors = _ref6.errors,
2313
+ setFieldError = _ref6.setFieldError;
2314
+ return /*#__PURE__*/jsx(Form, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, formDomProps), {}, {
2315
+ additionalActionOptions: additionalActionOptions,
2316
+ additionalQuestionKindPattern: additionalQuestionKindPattern,
2317
+ availableLanguages: availableLanguages,
2318
+ buildRequestArgs: buildRequestArgs,
2319
+ cancelButtonProps: cancelButtonProps,
2320
+ disabledAddButtonTooltipProps: disabledAddButtonTooltipProps,
2321
+ domainRestrictionHelpDocUrl: domainRestrictionHelpDocUrl,
2322
+ enableDomainRestriction: enableDomainRestriction,
2323
+ enableFieldCode: enableFieldCode,
2324
+ fieldCodeHelpDocUrl: fieldCodeHelpDocUrl,
2325
+ formDescription: formDescription,
2326
+ formTitle: formTitle,
2327
+ getActiveKindDetails: getActiveKindDetails,
2328
+ isDeletable: isDeletable,
2329
+ isDisabledFieldLabel: isDisabledFieldLabel,
2330
+ isFormEnabled: isFormEnabled,
2331
+ isKindAlreadyActive: isKindAlreadyActive,
2332
+ isReordering: isReordering,
2333
+ isRequiredField: isRequiredField,
2334
+ kindUniqueOn: kindUniqueOn,
2335
+ onLanguageChange: onLanguageChange,
2336
+ onValueChange: onValueChange,
2337
+ savedTitle: savedTitle,
2338
+ selectedLanguage: selectedLanguage,
2339
+ showActionBlock: showActionBlock,
2340
+ submitButtonProps: submitButtonProps
2341
+ })), {}, {
2342
+ formId: id,
2343
+ questionKinds: isNil(questionKinds) ? defaultQuestionKinds : questionKinds,
2344
+ onChange: function onChange(event) {
2345
+ if (isEmpty(errors)) return;
2346
+ setFieldError(event.target.name);
2347
+ }
2348
+ }));
2349
+ }
2350
+ }), isQuestionsLoading && !isQuestionsPending && /*#__PURE__*/jsx("div", {
2351
+ className: "neeto-ui-bg-white absolute inset-0 flex items-center justify-center",
2352
+ children: /*#__PURE__*/jsx(PageLoader, {})
2353
+ })]
2354
+ });
2355
+ };
2356
+
2357
+ export { BuildForm as default };
2358
+ //# sourceMappingURL=BuildForm.js.map