@bigbinary/neeto-form-frontend 4.4.9 → 4.4.10

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 (56) hide show
  1. package/README.md +1 -1
  2. package/dist/BuildForm.js +3077 -0
  3. package/dist/BuildForm.js.map +1 -0
  4. package/dist/ExternalForm.js +647 -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 +2832 -0
  9. package/dist/Submission.js.map +1 -0
  10. package/dist/UrlBuilder.js +317 -0
  11. package/dist/UrlBuilder.js.map +1 -0
  12. package/dist/buildForm-CrOWLvLE.js +35 -0
  13. package/dist/buildForm-CrOWLvLE.js.map +1 -0
  14. package/dist/buildForm-DfMpfuSp.js +38 -0
  15. package/dist/buildForm-DfMpfuSp.js.map +1 -0
  16. package/dist/cjs/BuildForm.js +3098 -0
  17. package/dist/cjs/BuildForm.js.map +1 -0
  18. package/dist/cjs/ExternalForm.js +649 -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 +2834 -0
  23. package/dist/cjs/Submission.js.map +1 -0
  24. package/dist/cjs/UrlBuilder.js +319 -0
  25. package/dist/cjs/UrlBuilder.js.map +1 -0
  26. package/dist/cjs/hooks.js +33 -0
  27. package/dist/cjs/hooks.js.map +1 -0
  28. package/dist/cjs/index.js +113 -0
  29. package/dist/cjs/index.js.map +1 -0
  30. package/dist/constants-Cj0XxE8a.js +494 -0
  31. package/dist/constants-Cj0XxE8a.js.map +1 -0
  32. package/dist/constants-D5JlvWws.js +513 -0
  33. package/dist/constants-D5JlvWws.js.map +1 -0
  34. package/dist/hooks.js +20 -0
  35. package/dist/hooks.js.map +1 -0
  36. package/dist/index-Beo6ztaM.js +51 -0
  37. package/dist/index-Beo6ztaM.js.map +1 -0
  38. package/dist/index-DhtQJpD_.js +43 -0
  39. package/dist/index-DhtQJpD_.js.map +1 -0
  40. package/dist/index.js +95 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/main.css +2 -0
  43. package/dist/main.css.map +1 -0
  44. package/dist/useFormSubmission-D3O7sDHp.js +24 -0
  45. package/dist/useFormSubmission-D3O7sDHp.js.map +1 -0
  46. package/dist/useFormSubmission-PLRMfzJ3.js +22 -0
  47. package/dist/useFormSubmission-PLRMfzJ3.js.map +1 -0
  48. package/dist/utils-CI844li1.js +2718 -0
  49. package/dist/utils-CI844li1.js.map +1 -0
  50. package/dist/utils-baAzU7l8.js +2749 -0
  51. package/dist/utils-baAzU7l8.js.map +1 -0
  52. package/dist/yup-CSYHMEsr.js +1014 -0
  53. package/dist/yup-CSYHMEsr.js.map +1 -0
  54. package/dist/yup-DMlViLLB.js +1097 -0
  55. package/dist/yup-DMlViLLB.js.map +1 -0
  56. package/package.json +3 -3
@@ -0,0 +1,3077 @@
1
+ import { useQueryClient } from '@tanstack/react-query';
2
+ import classnames from 'classnames';
3
+ import { isPresent, truncate, findBy, isNotPresent, slugify, existsBy, findById, findIndexById, hyphenate, noop, nullSafe, modifyBy, removeBy } from '@bigbinary/neeto-cist';
4
+ import Spinner from '@bigbinary/neetoui/Spinner';
5
+ import { equals, path, when, assoc, includes, isEmpty, reject, keys, pick, omit, evolve, map, mergeLeft, isNil, pipe, filter, isNotNil, values, uniq, join, pathSatisfies, assocPath, dissoc, append, pluck, test, paths, difference, prop, startsWith, split, last, either, F, T } from 'ramda';
6
+ import { k as useDeleteQuestion, Q as QUESTION_TYPES, b as useForm, l as useCreateQuestion, m as useUpdateQuestion, C as CAPTCHA_TYPES, n as useReorderQuestions, i as QUERY_KEYS } from './constants-Cj0XxE8a.js';
7
+ import { j as QUESTION_ACTIONS, k as INDEPENDENT_LABELS_MAP, l as buildDisplayLabel, m as isElementOverflowing, n as Drag, o as SELECTABLE_KINDS, p as isAutoGeneratedQuestion, q as isRichTextQuestion, r as SPOT_QUESTION_FIELD_CODE, N as NON_BASIC_LATIN_CHARACTERS_REGEX, s as RESERVED_FIELD_CODES, t as renameKey, f as LABEL_FIELDS, u as isDefaultLanguage, v as buildAddQuestionButtonProps, w as validateEditorContent, F as FIELD_CODES_REJECT_CHARS_REGEX, x as isImmutableField, Q as QUESTIONS_WITHOUT_FIELD_CODE, y as NON_HIDEABLE_FIELDS, z as NON_READ_ONLY_FIELDS, O as OPINION_LABEL_MAX_LENGTH, B as RICH_TEXT_QUESTIONS, e as ADDRESS_FIELD_WIDTHS, A as ADDRESS_FIELD_TYPES, G as generateDefaultOptions, M as MINIMUM_ADDRESS_FIELDS, H as getDeletedRecords, J as randomId, K as getActiveRecords, T as FILE_TYPES_MAP, U as FILE_GROUPS, V as OPINION_SCALE_MIN_VALUE_OPTIONS, W as OPINION_SCALE_MAX_VALUE_OPTIONS, D as DEFAULT_CHOICE_QUESTION_ATTRIBUTES, X as MINIMUM_OPTIONS, Y as IMAGE_HEIGHT_SLIDER_DEFAULTS, Z as RATING_OPTIONS, _ as STAR_RATING_MIN_VALUE_OPTIONS, $ as STAR_RATING_MAX_VALUE_OPTIONS, a0 as STAR_RATING_ICONS_MAP, a1 as buildDisabledAddButtonHelpPopoverProps, a2 as buildReorderPayload, a3 as QUESTIONS_INITIAL_VALUE, a4 as isMandatoryField, a5 as QUESTION_KINDS, a as QUESTION_KIND, a6 as getActiveQuestionKindDetails, a7 as DEFAULT_AVAILABLE_LANGUAGES, a8 as DEFAULT_ADVANCED_FEATURES } from './yup-CSYHMEsr.js';
8
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
9
+ import { useState, useRef, useEffect, createElement } from 'react';
10
+ import { Droppable, Draggable, DragDropContext } from '@hello-pangea/dnd';
11
+ import { withT, isMetaKeyPressed, useStateWithDependency, useFuncDebounce, useOnClickOutside } from '@bigbinary/neeto-commons-frontend/react-utils';
12
+ import { showThumbsUpToastr, withEventTargetValue, hyphenize } from '@bigbinary/neeto-commons-frontend/utils';
13
+ import { a as useBuildFormStore } from './buildForm-CrOWLvLE.js';
14
+ import { shallow } from 'zustand/shallow';
15
+ import Alert from '@bigbinary/neetoui/Alert';
16
+ import { useTranslation, Trans } from 'react-i18next';
17
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
18
+ import Typography from '@bigbinary/neetoui/Typography';
19
+ import Modal from '@bigbinary/neetoui/Modal';
20
+ import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
21
+ import Dropdown from '@bigbinary/neetoui/Dropdown';
22
+ import Tooltip from '@bigbinary/neetoui/Tooltip';
23
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
24
+ import { i as isFunction, f as fieldWithFallback, c as isNameQuestion } from './index-DhtQJpD_.js';
25
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
26
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
27
+ import { t } from 'i18next';
28
+ import { v4 } from 'uuid';
29
+ import NoData from '@bigbinary/neetoui/NoData';
30
+ import Button from '@bigbinary/neetoui/Button';
31
+ import Pane from '@bigbinary/neetoui/Pane';
32
+ import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
33
+ import Form$2 from '@bigbinary/neetoui/formik/Form';
34
+ import { useFormikContext, useField } from 'formik';
35
+ import Accordion from '@bigbinary/neetoui/Accordion';
36
+ import Select from '@bigbinary/neetoui/formik/Select';
37
+ import Switch from '@bigbinary/neetoui/formik/Switch';
38
+ import Textarea from '@bigbinary/neetoui/formik/Textarea';
39
+ import NeetoEditor from '@bigbinary/neeto-editor/Editor';
40
+ import Input from '@bigbinary/neetoui/formik/Input';
41
+ import { isEditorEmpty } from '@bigbinary/neeto-editor/utils';
42
+ import * as yup from 'yup';
43
+ import OptionFields from '@bigbinary/neeto-molecules/OptionFields';
44
+ import { AnimatePresence, motion } from 'framer-motion';
45
+ import Radio from '@bigbinary/neetoui/formik/Radio';
46
+ import Label from '@bigbinary/neetoui/Label';
47
+ import CreatableSelect from 'react-select/creatable';
48
+ import _toArray from '@babel/runtime/helpers/toArray';
49
+ import Close from '@bigbinary/neeto-icons/Close';
50
+ import Tag from '@bigbinary/neetoui/Tag';
51
+ import { components } from 'react-select';
52
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
53
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
54
+ import Checkbox$1 from '@bigbinary/neetoui/formik/Checkbox';
55
+ import Checkbox from '@bigbinary/neetoui/Checkbox';
56
+ import Slider from '@bigbinary/neetoui/Slider';
57
+ import HelpPopover from '@bigbinary/neeto-molecules/HelpPopover';
58
+ import '@bigbinary/neeto-commons-frontend/constants';
59
+ import 'axios';
60
+ import 'dompurify';
61
+ import '@bigbinary/neeto-icons/Plus';
62
+ import 'zustand';
63
+ import '@babel/runtime/helpers/typeof';
64
+
65
+ var DeleteAlert = function DeleteAlert(_ref) {
66
+ var selectedQuestion = _ref.selectedQuestion,
67
+ isOpen = _ref.isOpen,
68
+ onClose = _ref.onClose,
69
+ languagesCount = _ref.languagesCount,
70
+ handleSelect = _ref.handleSelect;
71
+ var _useTranslation = useTranslation(),
72
+ t = _useTranslation.t;
73
+ var _useBuildFormStore = useBuildFormStore(function (store) {
74
+ var _store$formState, _store$formState2;
75
+ return {
76
+ selectedLanguage: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["selectedLanguage"],
77
+ onMutateSuccess: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["onMutateSuccess"]
78
+ };
79
+ }, shallow),
80
+ selectedLanguage = _useBuildFormStore.selectedLanguage,
81
+ onMutateSuccess = _useBuildFormStore.onMutateSuccess;
82
+ var renderQuestionLabel = function renderQuestionLabel() {
83
+ var questionKind = selectedQuestion.kind;
84
+ var independentLabel = INDEPENDENT_LABELS_MAP[questionKind];
85
+ if (isPresent(independentLabel)) return independentLabel;
86
+ var questionLabel = buildDisplayLabel(selectedQuestion);
87
+ return truncate(questionLabel, 40);
88
+ };
89
+ var _useDeleteQuestion = useDeleteQuestion(selectedQuestion === null || selectedQuestion === void 0 ? void 0 : selectedQuestion.formId, selectedLanguage, {
90
+ onSuccess: function onSuccess() {
91
+ showThumbsUpToastr();
92
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
93
+ args[_key] = arguments[_key];
94
+ }
95
+ onMutateSuccess === null || onMutateSuccess === void 0 || onMutateSuccess.apply(void 0, [QUESTION_ACTIONS.DELETE].concat(args));
96
+ onClose();
97
+ }
98
+ }),
99
+ deleteQuestion = _useDeleteQuestion.mutate,
100
+ isDeleting = _useDeleteQuestion.isPending;
101
+ var selectNextQuestion = function selectNextQuestion(questions) {
102
+ var selectedQuestionIndex = selectedQuestion.displayOrder;
103
+ var wasLastQuestion = equals(selectedQuestionIndex, questions.length);
104
+ var newDisplayOrder = wasLastQuestion ? selectedQuestionIndex - 1 : selectedQuestionIndex;
105
+ var newQuestion = findBy({
106
+ displayOrder: newDisplayOrder
107
+ }, questions);
108
+ handleSelect(newQuestion);
109
+ };
110
+ var handleSubmit = function handleSubmit() {
111
+ deleteQuestion(selectedQuestion.id, {
112
+ onSuccess: function onSuccess(_ref2) {
113
+ var questions = _ref2.questions;
114
+ return selectNextQuestion(questions);
115
+ }
116
+ });
117
+ };
118
+ return /*#__PURE__*/jsx(Alert, {
119
+ isOpen: isOpen,
120
+ onClose: onClose,
121
+ isSubmitting: isDeleting,
122
+ submitButtonLabel: t("neetoForm.common.delete"),
123
+ title: t("neetoForm.questions.deleteAlert.title"),
124
+ message: isPresent(selectedQuestion) && /*#__PURE__*/jsx(Trans, {
125
+ i18nKey: "neetoForm.questions.deleteAlert.message",
126
+ values: {
127
+ count: languagesCount,
128
+ label: renderQuestionLabel()
129
+ }
130
+ }),
131
+ onSubmit: handleSubmit
132
+ });
133
+ };
134
+
135
+ var DeleteSmsReminderModal = function DeleteSmsReminderModal(_ref) {
136
+ var isOpen = _ref.isOpen,
137
+ onClose = _ref.onClose,
138
+ _ref$hostSpecificData = _ref.hostSpecificData,
139
+ hostSpecificData = _ref$hostSpecificData === void 0 ? {} : _ref$hostSpecificData;
140
+ return /*#__PURE__*/jsxs(Modal, {
141
+ isOpen: isOpen,
142
+ onClose: onClose,
143
+ children: [/*#__PURE__*/jsx(Modal.Header, {
144
+ children: /*#__PURE__*/jsx(Typography, {
145
+ "data-testid": "delete-sms-reminder-modal-header",
146
+ style: "h2",
147
+ weight: "medium",
148
+ children: path(["smsReminder", "deleteModal", "title"], hostSpecificData)
149
+ })
150
+ }), /*#__PURE__*/jsx(Modal.Body, {
151
+ children: /*#__PURE__*/jsx(Typography, {
152
+ "data-testid": "delete-sms-reminder-modal-description",
153
+ style: "body2",
154
+ children: path(["smsReminder", "deleteModal", "description"], hostSpecificData)
155
+ })
156
+ })]
157
+ });
158
+ };
159
+
160
+ var DeleteSpotModal = function DeleteSpotModal(_ref) {
161
+ var isOpen = _ref.isOpen,
162
+ onClose = _ref.onClose,
163
+ _ref$hostSpecificData = _ref.hostSpecificData,
164
+ hostSpecificData = _ref$hostSpecificData === void 0 ? {} : _ref$hostSpecificData;
165
+ var title = path(["spot", "deleteModal", "title"], hostSpecificData);
166
+ var description = path(["spot", "deleteModal", "description"], hostSpecificData);
167
+ return /*#__PURE__*/jsxs(Modal, {
168
+ isOpen: isOpen,
169
+ onClose: onClose,
170
+ children: [/*#__PURE__*/jsx(Modal.Header, {
171
+ children: /*#__PURE__*/jsx(Typography, {
172
+ "data-testid": "delete-spot-modal-header",
173
+ style: "h2",
174
+ weight: "medium",
175
+ children: title
176
+ })
177
+ }), /*#__PURE__*/jsx(Modal.Body, {
178
+ children: /*#__PURE__*/jsx(Typography, {
179
+ "data-testid": "delete-spot-modal-description",
180
+ style: "body2",
181
+ children: description
182
+ })
183
+ })]
184
+ });
185
+ };
186
+
187
+ var ChangeLanguageDropdown = function ChangeLanguageDropdown(_ref) {
188
+ var _findBy;
189
+ var availableLanguages = _ref.availableLanguages;
190
+ var _useTranslation = useTranslation(),
191
+ t = _useTranslation.t;
192
+ var _useBuildFormStore = useBuildFormStore(function (store) {
193
+ var _store$formState, _store$formState2, _store$formState3;
194
+ return {
195
+ selectedLanguage: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["selectedLanguage"],
196
+ onLanguageChange: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["onLanguageChange"],
197
+ isReorderingQuestions: (_store$formState3 = store["formState"]) === null || _store$formState3 === void 0 ? void 0 : _store$formState3["isReorderingQuestions"]
198
+ };
199
+ }, shallow),
200
+ selectedLanguage = _useBuildFormStore.selectedLanguage,
201
+ onLanguageChange = _useBuildFormStore.onLanguageChange,
202
+ isReorderingQuestions = _useBuildFormStore.isReorderingQuestions;
203
+ var selectedLanguageName = (_findBy = findBy({
204
+ code: selectedLanguage
205
+ }, availableLanguages)) === null || _findBy === void 0 ? void 0 : _findBy.name;
206
+ return /*#__PURE__*/jsx(Tooltip, {
207
+ content: t("neetoForm.questions.changeLanguage"),
208
+ children: /*#__PURE__*/jsx("div", {
209
+ children: /*#__PURE__*/jsx(Dropdown, {
210
+ buttonStyle: "secondary",
211
+ disabled: isReorderingQuestions,
212
+ label: selectedLanguageName,
213
+ children: /*#__PURE__*/jsx(Dropdown.Menu, {
214
+ children: availableLanguages.map(function (_ref2) {
215
+ var code = _ref2.code,
216
+ name = _ref2.name;
217
+ return /*#__PURE__*/jsx(Dropdown.MenuItem.Button, {
218
+ isActive: selectedLanguage === code,
219
+ onClick: function onClick() {
220
+ return onLanguageChange(code);
221
+ },
222
+ children: name
223
+ }, code);
224
+ })
225
+ })
226
+ })
227
+ })
228
+ });
229
+ };
230
+
231
+ var Overview = function Overview(_ref) {
232
+ var title = _ref.title,
233
+ description = _ref.description,
234
+ availableLanguages = _ref.availableLanguages,
235
+ additionalActionOptions = _ref.additionalActionOptions;
236
+ return /*#__PURE__*/jsxs("div", {
237
+ className: "neeto-form-nano-form-wrapper__overview mb-4 w-full shrink-0 space-y-4 pt-6",
238
+ children: [/*#__PURE__*/jsxs("div", {
239
+ className: "flex items-center justify-between",
240
+ children: [/*#__PURE__*/jsx(Typography, {
241
+ "data-testid": "neeto-form-engine-overview-title",
242
+ lineHeight: "neeto-ui-leading-normal",
243
+ style: "h2",
244
+ weight: "neeto-ui-font-semibold",
245
+ children: title
246
+ }), /*#__PURE__*/jsxs("div", {
247
+ className: "flex shrink-0 items-center justify-between space-x-1",
248
+ children: [availableLanguages.length > 1 && /*#__PURE__*/jsx(ChangeLanguageDropdown, {
249
+ availableLanguages: availableLanguages
250
+ }), isPresent(additionalActionOptions) && /*#__PURE__*/jsx(MoreDropdown, {
251
+ dropdownButtonProps: {
252
+ isRounded: true,
253
+ style: "tertiary"
254
+ },
255
+ dropdownProps: {
256
+ strategy: "fixed",
257
+ position: "bottom-start"
258
+ },
259
+ menuItems: additionalActionOptions
260
+ })]
261
+ })]
262
+ }), /*#__PURE__*/jsx(Typography, {
263
+ "data-testid": "neeto-form-engine-overview-description",
264
+ style: "body2",
265
+ children: description
266
+ })]
267
+ });
268
+ };
269
+
270
+ var Card = function Card(_ref) {
271
+ var _ref$question = _ref.question,
272
+ question = _ref$question === void 0 ? {} : _ref$question,
273
+ allQuestionKinds = _ref.allQuestionKinds,
274
+ getActiveKindDetails = _ref.getActiveKindDetails,
275
+ isActive = _ref.isActive,
276
+ onSelect = _ref.onSelect,
277
+ onEdit = _ref.onEdit,
278
+ onClone = _ref.onClone,
279
+ onDelete = _ref.onDelete,
280
+ canManageQuestions = _ref.canManageQuestions;
281
+ var _useState = useState(false),
282
+ _useState2 = _slicedToArray(_useState, 2),
283
+ isTooltipEnabled = _useState2[0],
284
+ setIsTooltipEnabled = _useState2[1];
285
+ var questionLabelRef = useRef(null);
286
+ var _useTranslation = useTranslation(),
287
+ t = _useTranslation.t;
288
+ var _getActiveKindDetails = getActiveKindDetails({
289
+ allQuestionKinds: allQuestionKinds,
290
+ item: question
291
+ }),
292
+ isSingular = _getActiveKindDetails.isSingular;
293
+ var questionLabel = buildDisplayLabel(question);
294
+ useEffect(function () {
295
+ var element = questionLabelRef.current;
296
+ if (isNotPresent(element)) return;
297
+ setIsTooltipEnabled(isElementOverflowing(element));
298
+ }, [questionLabel]);
299
+ return /*#__PURE__*/jsxs("div", {
300
+ "data-testid": "neeto-form-engine-".concat(slugify(questionLabel)),
301
+ 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 gap-1 border p-2", {
302
+ "neeto-ui-border-primary-500 neeto-form-nano-form__card--active": isActive
303
+ }),
304
+ onClick: function onClick() {
305
+ return onSelect(question);
306
+ },
307
+ children: [/*#__PURE__*/jsxs("div", {
308
+ className: "flex min-w-0 grow items-center gap-1",
309
+ children: [canManageQuestions && /*#__PURE__*/jsx(Drag, {
310
+ className: "neeto-ui-text-gray-600 shrink-0"
311
+ }), /*#__PURE__*/jsx(Tooltip, {
312
+ content: questionLabel,
313
+ disabled: !isTooltipEnabled,
314
+ position: "top",
315
+ children: /*#__PURE__*/jsx(Typography, {
316
+ className: "line-clamp-2 min-w-0 grow truncate break-words",
317
+ "data-testid": "".concat(slugify(questionLabel), "-question-card-label"),
318
+ lineHeight: "snug",
319
+ ref: questionLabelRef,
320
+ style: "body2",
321
+ weight: "medium",
322
+ children: questionLabel
323
+ })
324
+ })]
325
+ }), canManageQuestions && /*#__PURE__*/jsx(MoreDropdown, {
326
+ dropdownButtonProps: {
327
+ className: "shrink-0"
328
+ },
329
+ dropdownProps: {
330
+ strategy: "fixed"
331
+ },
332
+ menuItems: [{
333
+ "data-testid": "edit-question",
334
+ key: "edit",
335
+ label: t("neetoForm.common.edit"),
336
+ onClick: onEdit
337
+ }, {
338
+ "data-testid": "clone-question",
339
+ key: "clone",
340
+ label: t("neetoForm.common.clone"),
341
+ isVisible: !isSingular && isFunction(onClone),
342
+ onClick: onClone
343
+ }, {
344
+ "data-testid": "delete-question",
345
+ key: "delete",
346
+ label: t("neetoForm.common.delete"),
347
+ isVisible: isFunction(onDelete),
348
+ onClick: function onClick() {
349
+ return onDelete(question);
350
+ }
351
+ }]
352
+ })]
353
+ });
354
+ };
355
+
356
+ function ownKeys$i(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; }
357
+ function _objectSpread$i(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$i(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$i(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
358
+ var Questions = function Questions(_ref) {
359
+ var questions = _ref.questions,
360
+ isDeletable = _ref.isDeletable,
361
+ allQuestionKinds = _ref.allQuestionKinds,
362
+ getActiveKindDetails = _ref.getActiveKindDetails,
363
+ selectedQuestion = _ref.selectedQuestion,
364
+ onEdit = _ref.onEdit,
365
+ onClone = _ref.onClone,
366
+ onDelete = _ref.onDelete,
367
+ onSelect = _ref.onSelect,
368
+ canManageQuestions = _ref.canManageQuestions;
369
+ return /*#__PURE__*/jsx(Droppable, {
370
+ droppableId: "droppable",
371
+ isDropDisabled: !canManageQuestions,
372
+ children: function children(_ref2) {
373
+ var droppableProps = _ref2.droppableProps,
374
+ placeholder = _ref2.placeholder,
375
+ innerRef = _ref2.innerRef;
376
+ return /*#__PURE__*/jsxs("div", _objectSpread$i(_objectSpread$i({}, droppableProps), {}, {
377
+ className: "space-y-2",
378
+ ref: innerRef,
379
+ children: [questions.map(function (question, index) {
380
+ var _question$id, _question$id2;
381
+ return /*#__PURE__*/createElement(Draggable, {
382
+ index: index,
383
+ draggableId: "question-".concat((_question$id = question.id) !== null && _question$id !== void 0 ? _question$id : question.nodeId),
384
+ isDragDisabled: !canManageQuestions,
385
+ key: "question-".concat((_question$id2 = question.id) !== null && _question$id2 !== void 0 ? _question$id2 : question.nodeId)
386
+ }, function (_ref3) {
387
+ var draggableProps = _ref3.draggableProps,
388
+ dragHandleProps = _ref3.dragHandleProps,
389
+ innerRef = _ref3.innerRef;
390
+ return /*#__PURE__*/jsx("div", _objectSpread$i(_objectSpread$i(_objectSpread$i({}, draggableProps), dragHandleProps), {}, {
391
+ ref: innerRef,
392
+ children: /*#__PURE__*/jsx(Card, {
393
+ allQuestionKinds: allQuestionKinds,
394
+ canManageQuestions: canManageQuestions,
395
+ getActiveKindDetails: getActiveKindDetails,
396
+ onClone: onClone,
397
+ onEdit: onEdit,
398
+ onSelect: onSelect,
399
+ question: question,
400
+ isActive: equals(selectedQuestion, question),
401
+ onDelete: isDeletable(question) && onDelete
402
+ })
403
+ }));
404
+ });
405
+ }), placeholder]
406
+ }));
407
+ }
408
+ });
409
+ };
410
+
411
+ var moveItem = function moveItem(arr, sourceIndex, destinationIndex) {
412
+ if (sourceIndex === destinationIndex) return arr;
413
+ if (arr instanceof Array && arr[sourceIndex] !== undefined) {
414
+ var removedItem = arr.splice(sourceIndex, 1)[0];
415
+ arr.splice(destinationIndex, 0, removedItem);
416
+ }
417
+ return arr;
418
+ };
419
+ var arrayHelpers = {
420
+ moveItem: moveItem
421
+ };
422
+
423
+ var _excluded$b = ["fields"];
424
+ function ownKeys$h(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
425
+ function _objectSpread$h(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$h(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$h(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
426
+ var isChoiceQuestion = function isChoiceQuestion(question) {
427
+ return includes(question === null || question === void 0 ? void 0 : question.kind, SELECTABLE_KINDS);
428
+ };
429
+ var isAddressQuestion = function isAddressQuestion(question) {
430
+ return (question === null || question === void 0 ? void 0 : question.kind) === QUESTION_TYPES.ADDRESS;
431
+ };
432
+ var underscoredWithoutSpecialCharacters = function underscoredWithoutSpecialCharacters(string) {
433
+ return string.toLowerCase().replace(/[\s-]/g, "_").replace(/[\W]/gi, "").replace(/_+/g, "_").replace(/^_+|_+$/, "");
434
+ };
435
+ var addSuffixForReservedFieldCode = function addSuffixForReservedFieldCode(fieldCode) {
436
+ return RESERVED_FIELD_CODES.includes(fieldCode) ? "".concat(fieldCode, "_field") : fieldCode;
437
+ };
438
+ var getUniqueNumbersFromExistingFieldCodes = function getUniqueNumbersFromExistingFieldCodes(prefix, questions) {
439
+ return questions.filter(function (question) {
440
+ return question.fieldCode.startsWith(prefix);
441
+ }).map(function (question) {
442
+ return parseInt(question.fieldCode.replace(prefix, "")) || 0;
443
+ });
444
+ };
445
+ var generateFieldCodePrefix = function generateFieldCodePrefix(label, kind) {
446
+ if (kind === QUESTION_TYPES.SPOT) {
447
+ return SPOT_QUESTION_FIELD_CODE;
448
+ }
449
+ var prefix;
450
+ if (isNameQuestion(kind) || NON_BASIC_LATIN_CHARACTERS_REGEX.test(label) || isEmpty(label)) {
451
+ prefix = kind;
452
+ } else {
453
+ var sanitizedLabel = underscoredWithoutSpecialCharacters(label).slice(0, 30);
454
+ prefix = isEmpty(sanitizedLabel) ? kind : sanitizedLabel;
455
+ }
456
+ return addSuffixForReservedFieldCode(prefix) || "";
457
+ };
458
+ var modifyDefaultValues = function modifyDefaultValues(_ref) {
459
+ var values = _ref.values,
460
+ kind = _ref.kind,
461
+ selectedLanguage = _ref.selectedLanguage,
462
+ isUsingDefaultQuestionKinds = _ref.isUsingDefaultQuestionKinds;
463
+ if (isNameQuestion(kind)) {
464
+ return renameKey(LABEL_FIELDS.DEFAULT, LABEL_FIELDS.FULL_NAME, values);
465
+ }
466
+ if (!includes(kind, SELECTABLE_KINDS) || isDefaultLanguage(selectedLanguage) || !isUsingDefaultQuestionKinds) {
467
+ return values;
468
+ }
469
+ return evolve({
470
+ optionsAttributes: map(assoc("label", ""))
471
+ }, values);
472
+ };
473
+ var generateUniqueFieldCode = function generateUniqueFieldCode(_ref2) {
474
+ var questions = _ref2.questions,
475
+ _ref2$label = _ref2.label,
476
+ label = _ref2$label === void 0 ? "" : _ref2$label,
477
+ _ref2$kind = _ref2.kind,
478
+ kind = _ref2$kind === void 0 ? "" : _ref2$kind;
479
+ var prefix = generateFieldCodePrefix(label, kind);
480
+ var uniqueNumber = Math.max.apply(Math, [0].concat(_toConsumableArray(getUniqueNumbersFromExistingFieldCodes(prefix, questions))));
481
+ var candidateFieldCode = "";
482
+
483
+ //We need to continue this while loop until we can generate a unique fieldCode
484
+
485
+ while (true) {
486
+ candidateFieldCode = "".concat(prefix).concat(uniqueNumber === 0 ? "" : uniqueNumber);
487
+ if (!findBy({
488
+ fieldCode: candidateFieldCode
489
+ }, questions)) break;
490
+ uniqueNumber += 1;
491
+ }
492
+ return candidateFieldCode;
493
+ };
494
+ var isQuestionKindAlreadyActive = function isQuestionKindAlreadyActive(_ref3) {
495
+ var activeQuestions = _ref3.activeQuestions,
496
+ kind = _ref3.kind;
497
+ return existsBy({
498
+ kind: kind.type
499
+ }, activeQuestions);
500
+ };
501
+ var handleFieldDragEnd = function handleFieldDragEnd(_ref4) {
502
+ var items = _ref4.items,
503
+ setValue = _ref4.setValue,
504
+ source = _ref4.source,
505
+ destination = _ref4.destination;
506
+ if (!(destination && items instanceof Array)) return;
507
+ var nextItems = _toConsumableArray(items);
508
+ arrayHelpers.moveItem(nextItems, source.index, destination.index);
509
+ var orderedItems = nextItems.map(function (item, index) {
510
+ return _objectSpread$h(_objectSpread$h({}, item), {}, {
511
+ displayOrder: index
512
+ });
513
+ });
514
+ setValue(orderedItems);
515
+ };
516
+ var createFieldData = function createFieldData(_ref5) {
517
+ var _ref5$kind = _ref5.kind,
518
+ defaults = _ref5$kind.defaults,
519
+ type = _ref5$kind.type,
520
+ metadata = _ref5$kind.metadata,
521
+ _ref5$isRequired = _ref5.isRequired,
522
+ isRequired = _ref5$isRequired === void 0 ? undefined : _ref5$isRequired,
523
+ questions = _ref5.questions,
524
+ selectedLanguage = _ref5.selectedLanguage,
525
+ isUsingDefaultQuestionKinds = _ref5.isUsingDefaultQuestionKinds;
526
+ var modifiedDefaultValues = modifyDefaultValues({
527
+ values: defaults,
528
+ kind: type,
529
+ selectedLanguage: selectedLanguage,
530
+ isUsingDefaultQuestionKinds: isUsingDefaultQuestionKinds
531
+ });
532
+ return _objectSpread$h(_objectSpread$h({}, modifiedDefaultValues), {}, {
533
+ metadata: metadata,
534
+ isRequired: isRequired,
535
+ kind: type,
536
+ nodeId: v4(),
537
+ fieldCode: generateUniqueFieldCode({
538
+ questions: questions,
539
+ kind: type,
540
+ label: defaults["label"]
541
+ })
542
+ });
543
+ };
544
+ var duplicateFieldData = function duplicateFieldData(_ref6) {
545
+ var item = _ref6.item,
546
+ questionKinds = _ref6.questionKinds,
547
+ questions = _ref6.questions;
548
+ var isRequired = item.isRequired,
549
+ kind = item.kind,
550
+ optionsAttributes = item.optionsAttributes;
551
+ var questionKind = findBy({
552
+ type: kind
553
+ }, questionKinds);
554
+ var label = fieldWithFallback(item, "label");
555
+ var defaultAttributeNames = keys(questionKind.defaults || {});
556
+ var _pick = pick(defaultAttributeNames, item),
557
+ fields = _pick.fields,
558
+ defaultAttributes = _objectWithoutProperties(_pick, _excluded$b);
559
+ var newQuestionLabel = isRichTextQuestion(kind) ? label : t("neetoForm.common.clonedElementLabel", {
560
+ label: label
561
+ });
562
+ return _objectSpread$h(_objectSpread$h({}, defaultAttributes), {}, {
563
+ isRequired: isRequired,
564
+ kind: kind,
565
+ label: newQuestionLabel,
566
+ optionsAttributes: optionsAttributes && optionsAttributes.map(omit(["id"])),
567
+ fieldsAttributes: fields && fields.map(omit(["id"])),
568
+ nodeId: v4(),
569
+ fieldCode: generateUniqueFieldCode({
570
+ questions: questions,
571
+ kind: kind,
572
+ label: newQuestionLabel
573
+ }),
574
+ displayOrder: item.displayOrder + 1
575
+ });
576
+ };
577
+ var getAvailableQuestionKinds = function getAvailableQuestionKinds(_ref7) {
578
+ var allQuestionKinds = _ref7.allQuestionKinds,
579
+ _ref7$activeQuestions = _ref7.activeQuestions,
580
+ activeQuestions = _ref7$activeQuestions === void 0 ? [] : _ref7$activeQuestions,
581
+ isKindAlreadyActive = _ref7.isKindAlreadyActive;
582
+ if (isEmpty(activeQuestions)) return allQuestionKinds;
583
+ return reject(function (kind) {
584
+ var isSingularKind = kind.isSingular;
585
+ return isAutoGeneratedQuestion(kind.type) || isSingularKind && isKindAlreadyActive({
586
+ activeQuestions: activeQuestions,
587
+ kind: kind
588
+ });
589
+ }, allQuestionKinds);
590
+ };
591
+ var formatQuestionAttributesForClone = when(function (question) {
592
+ return isChoiceQuestion(question) || isAddressQuestion(question);
593
+ }, assoc("isCloning", true));
594
+
595
+ var HelpText = withT(function (_ref) {
596
+ var t = _ref.t,
597
+ href = _ref.href;
598
+ return /*#__PURE__*/jsxs(Fragment, {
599
+ children: [t("neetoForm.questions.common.helpText.learnAbout"), " ", /*#__PURE__*/jsx(Button, {
600
+ href: href,
601
+ label: t("neetoForm.questions.common.helpText.howToAddNewQuestions"),
602
+ style: "link",
603
+ target: "_blank"
604
+ })]
605
+ });
606
+ });
607
+
608
+ var AddFirstQuestion = function AddFirstQuestion(_ref) {
609
+ var onAdd = _ref.onAdd,
610
+ isDisabled = _ref.isDisabled,
611
+ disabledAddButtonHelpPopoverProps = _ref.disabledAddButtonHelpPopoverProps;
612
+ var _useTranslation = useTranslation(),
613
+ t = _useTranslation.t;
614
+ var _disabledAddButtonHel = disabledAddButtonHelpPopoverProps.helpLinkProps,
615
+ _disabledAddButtonHel2 = _disabledAddButtonHel === void 0 ? {} : _disabledAddButtonHel,
616
+ href = _disabledAddButtonHel2.href;
617
+ return /*#__PURE__*/jsx("div", {
618
+ className: "flex h-full flex-col items-center justify-center py-8",
619
+ children: /*#__PURE__*/jsx(NoData, {
620
+ className: "min-h-80",
621
+ helpText: isPresent(href) ? /*#__PURE__*/jsx(HelpText, {
622
+ href: href
623
+ }) : null,
624
+ primaryButtonProps: buildAddQuestionButtonProps(onAdd, isDisabled),
625
+ title: t("neetoForm.questions.common.noData")
626
+ })
627
+ });
628
+ };
629
+
630
+ var NAME = QUESTION_TYPES.NAME,
631
+ PHONE = QUESTION_TYPES.PHONE,
632
+ EMAIL$1 = QUESTION_TYPES.EMAIL,
633
+ ADDITIONAL_GUESTS = QUESTION_TYPES.ADDITIONAL_GUESTS,
634
+ TEXT = QUESTION_TYPES.TEXT,
635
+ TEXTAREA = QUESTION_TYPES.TEXTAREA,
636
+ RICH_TEXT = QUESTION_TYPES.RICH_TEXT,
637
+ INTEGER = QUESTION_TYPES.INTEGER,
638
+ DECIMAL = QUESTION_TYPES.DECIMAL,
639
+ STAR_RATING$1 = QUESTION_TYPES.STAR_RATING,
640
+ OPINION_SCALE$1 = QUESTION_TYPES.OPINION_SCALE,
641
+ RATING$1 = QUESTION_TYPES.RATING,
642
+ DATE = QUESTION_TYPES.DATE,
643
+ FILE_UPLOAD$1 = QUESTION_TYPES.FILE_UPLOAD,
644
+ CAPTCHA$1 = QUESTION_TYPES.CAPTCHA,
645
+ SMS_REMINDER = QUESTION_TYPES.SMS_REMINDER,
646
+ ADDRESS$1 = QUESTION_TYPES.ADDRESS;
647
+ var QUESTIONS_WITH_ADDITIONAL_DATA = [].concat(_toConsumableArray(SELECTABLE_KINDS), [STAR_RATING$1, OPINION_SCALE$1, RATING$1, FILE_UPLOAD$1, CAPTCHA$1, EMAIL$1, ADDRESS$1]);
648
+ var QUESTIONS_WITH_PLACEHOLDERS = [NAME, PHONE, EMAIL$1, ADDITIONAL_GUESTS, TEXT, TEXTAREA, RICH_TEXT, INTEGER, DECIMAL, DATE, SMS_REMINDER];
649
+ var DEFAULT_PLACEHOLDERS = {
650
+ CHECKBOX: t("neetoForm.questions.common.questionFields.field.labelExample", {
651
+ what: t("neetoForm.common.hobbies")
652
+ }),
653
+ RADIO: t("neetoForm.questions.common.questionFields.field.labelExample", {
654
+ what: t("neetoForm.common.country")
655
+ }),
656
+ DROPDOWN: t("neetoForm.questions.common.questionFields.field.labelExample", {
657
+ what: t("neetoForm.common.company")
658
+ })
659
+ };
660
+ var INITIAL_VALUES = {
661
+ kind: "",
662
+ label: "",
663
+ fieldCode: "",
664
+ isSplitMode: false
665
+ };
666
+ var VALID_FIELD_CODE_REGEX = /^[a-z0-9]+(_[a-z0-9]+)*$/;
667
+ var DRAFT_ID_PREFIX = "draft-";
668
+
669
+ var useHelpDoc = function useHelpDoc(key) {
670
+ return useBuildFormStore(path(["formState", "helpDocUrls", key]));
671
+ };
672
+
673
+ var _excluded$a = ["label", "name"];
674
+ function ownKeys$g(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
675
+ function _objectSpread$g(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$g(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$g(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
676
+ var FormikAdaptiveInput = function FormikAdaptiveInput(_ref) {
677
+ var label = _ref.label,
678
+ name = _ref.name,
679
+ otherProps = _objectWithoutProperties(_ref, _excluded$a);
680
+ var _useFormikContext = useFormikContext(),
681
+ dirty = _useFormikContext.dirty,
682
+ isValid = _useFormikContext.isValid,
683
+ submitForm = _useFormikContext.submitForm;
684
+ var handleKeyDown = function handleKeyDown(event) {
685
+ if (event.key !== "Enter" || event.shiftKey) return;
686
+ event.preventDefault();
687
+ if (isMetaKeyPressed(event)) return;
688
+ dirty && isValid && submitForm();
689
+ };
690
+ var handleFocus = function handleFocus(element) {
691
+ var end = element.value.length;
692
+ element.setSelectionRange(end, end);
693
+ };
694
+ return /*#__PURE__*/jsx(Textarea, _objectSpread$g({
695
+ label: label,
696
+ name: name,
697
+ className: "neeto-form-nano-adaptive-input",
698
+ resize: "none",
699
+ size: "small",
700
+ onFocus: function onFocus(_ref2) {
701
+ var target = _ref2.target;
702
+ return handleFocus(target);
703
+ },
704
+ onKeyDown: handleKeyDown
705
+ }, otherProps));
706
+ };
707
+
708
+ function ownKeys$f(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
709
+ function _objectSpread$f(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$f(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$f(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
710
+ var LabelWithPlaceholder = function LabelWithPlaceholder(_ref) {
711
+ var kind = _ref.kind,
712
+ isLabelDisabled = _ref.isLabelDisabled,
713
+ handleLabelChange = _ref.handleLabelChange,
714
+ _ref$labelProps = _ref.labelProps,
715
+ labelProps = _ref$labelProps === void 0 ? {} : _ref$labelProps,
716
+ _ref$placeholderProps = _ref.placeholderProps,
717
+ placeholderProps = _ref$placeholderProps === void 0 ? {} : _ref$placeholderProps;
718
+ var _useTranslation = useTranslation(),
719
+ t = _useTranslation.t;
720
+ var shouldShowPlaceholder = includes(kind, QUESTIONS_WITH_PLACEHOLDERS);
721
+ return /*#__PURE__*/jsxs("div", {
722
+ className: "space-y-4",
723
+ children: [/*#__PURE__*/jsx(FormikAdaptiveInput, _objectSpread$f({
724
+ required: true,
725
+ disabled: isLabelDisabled,
726
+ label: t("neetoForm.questions.common.questionFields.field.question"),
727
+ name: "label",
728
+ placeholder: DEFAULT_PLACEHOLDERS[kind],
729
+ onChange: withEventTargetValue(handleLabelChange)
730
+ }, labelProps)), shouldShowPlaceholder && /*#__PURE__*/jsx(FormikAdaptiveInput, _objectSpread$f({
731
+ className: "neeto-form-nano-placeholder-input neeto-form-nano-placeholder-input-".concat(kind),
732
+ name: "placeholder",
733
+ label: t("neetoForm.questions.common.questionFields.field.placeholder")
734
+ }, placeholderProps))]
735
+ });
736
+ };
737
+
738
+ 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; }
739
+ 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), true).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; }
740
+ var Name = function Name(_ref) {
741
+ var isLabelDisabled = _ref.isLabelDisabled,
742
+ _handleLabelChange = _ref.handleLabelChange;
743
+ var _useFormikContext = useFormikContext(),
744
+ _useFormikContext$val = _useFormikContext.values.isSplitMode,
745
+ isSplitMode = _useFormikContext$val === void 0 ? false : _useFormikContext$val;
746
+ var _useTranslation = useTranslation(),
747
+ t = _useTranslation.t;
748
+ var usesCustomSubmissionComponent = useBuildFormStore(path(["formState", "usesCustomSubmissionComponent"]));
749
+ var commonProps = {
750
+ kind: QUESTION_TYPES.NAME,
751
+ isLabelDisabled: isLabelDisabled
752
+ };
753
+ return /*#__PURE__*/jsxs("div", {
754
+ className: "space-y-4",
755
+ children: [!usesCustomSubmissionComponent && /*#__PURE__*/jsx(Switch, {
756
+ label: t("neetoForm.common.splitAsFirstAndLastNames"),
757
+ name: "isSplitMode"
758
+ }), isSplitMode && !usesCustomSubmissionComponent ? /*#__PURE__*/jsxs(Fragment, {
759
+ children: [/*#__PURE__*/jsx(LabelWithPlaceholder, _objectSpread$e(_objectSpread$e({}, commonProps), {}, {
760
+ handleLabelChange: function handleLabelChange(value) {
761
+ return _handleLabelChange(value, LABEL_FIELDS.FIRST_NAME);
762
+ },
763
+ labelProps: {
764
+ label: t("neetoForm.questions.common.questionFields.field.firstNameQuestion"),
765
+ name: LABEL_FIELDS.FIRST_NAME
766
+ },
767
+ placeholderProps: {
768
+ label: t("neetoForm.questions.common.questionFields.field.firstNamePlaceholder"),
769
+ name: "firstNamePlaceholder"
770
+ }
771
+ })), /*#__PURE__*/jsx(LabelWithPlaceholder, _objectSpread$e(_objectSpread$e({}, commonProps), {}, {
772
+ handleLabelChange: function handleLabelChange(value) {
773
+ return _handleLabelChange(value, LABEL_FIELDS.LAST_NAME);
774
+ },
775
+ labelProps: {
776
+ label: t("neetoForm.questions.common.questionFields.field.lastNameQuestion"),
777
+ name: LABEL_FIELDS.LAST_NAME
778
+ },
779
+ placeholderProps: {
780
+ label: t("neetoForm.questions.common.questionFields.field.lastNamePlaceholder"),
781
+ name: "lastNamePlaceholder"
782
+ }
783
+ }))]
784
+ }) : /*#__PURE__*/jsx(LabelWithPlaceholder, _objectSpread$e(_objectSpread$e({}, commonProps), {}, {
785
+ labelProps: {
786
+ name: LABEL_FIELDS.FULL_NAME
787
+ },
788
+ placeholderProps: {
789
+ name: "fullNamePlaceholder"
790
+ },
791
+ handleLabelChange: function handleLabelChange(value) {
792
+ return _handleLabelChange(value, LABEL_FIELDS.FULL_NAME);
793
+ }
794
+ }))]
795
+ });
796
+ };
797
+
798
+ var Properties = function Properties(_ref) {
799
+ var kind = _ref.kind,
800
+ isLabelDisabled = _ref.isLabelDisabled,
801
+ handleLabelChange = _ref.handleLabelChange,
802
+ questionProps = _ref.questionProps;
803
+ var _useBuildFormStore = useBuildFormStore(function (store) {
804
+ var _store$formState;
805
+ return {
806
+ usesCustomSubmissionComponent: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["usesCustomSubmissionComponent"]
807
+ };
808
+ }, shallow),
809
+ usesCustomSubmissionComponent = _useBuildFormStore.usesCustomSubmissionComponent;
810
+ var hasAdditionalData = includes(kind, QUESTIONS_WITH_ADDITIONAL_DATA);
811
+ if (isNameQuestion(kind)) {
812
+ return /*#__PURE__*/jsx(Name, {
813
+ handleLabelChange: handleLabelChange,
814
+ isLabelDisabled: isLabelDisabled
815
+ });
816
+ }
817
+ return /*#__PURE__*/jsxs("div", {
818
+ className: "space-y-4",
819
+ children: [/*#__PURE__*/jsx(LabelWithPlaceholder, {
820
+ handleLabelChange: handleLabelChange,
821
+ isLabelDisabled: isLabelDisabled,
822
+ kind: kind
823
+ }), hasAdditionalData && renderAdditionalData({
824
+ kind: kind,
825
+ questionProps: questionProps,
826
+ usesCustomSubmissionComponent: usesCustomSubmissionComponent
827
+ })]
828
+ });
829
+ };
830
+
831
+ var Block = function Block(_ref) {
832
+ var title = _ref.title,
833
+ children = _ref.children,
834
+ dataTestid = _ref.dataTestid;
835
+ return /*#__PURE__*/jsxs("div", {
836
+ className: "mt-4 space-y-3",
837
+ "data-testid": dataTestid,
838
+ children: [/*#__PURE__*/jsx("div", {
839
+ className: "flex items-center justify-between",
840
+ "data-testid": "properties-header",
841
+ children: /*#__PURE__*/jsx(Typography, {
842
+ lineHeight: "normal",
843
+ style: "body1",
844
+ weight: "semibold",
845
+ children: title
846
+ })
847
+ }), /*#__PURE__*/jsx("div", {
848
+ className: "space-y-4",
849
+ children: children
850
+ })]
851
+ });
852
+ };
853
+
854
+ var useUpdateEditorContent = function useUpdateEditorContent(_ref) {
855
+ var editorRef = _ref.editorRef,
856
+ fieldName = _ref.fieldName,
857
+ value = _ref.value;
858
+ var initialStateRef = useRef({
859
+ language: "",
860
+ value: null
861
+ });
862
+ var _useBuildFormStore = useBuildFormStore(function (store) {
863
+ var _store$formState, _store$formState2;
864
+ return {
865
+ formId: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["formId"],
866
+ selectedLanguage: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["selectedLanguage"]
867
+ };
868
+ }, shallow),
869
+ formId = _useBuildFormStore.formId,
870
+ language = _useBuildFormStore.selectedLanguage;
871
+ var setEditorContent = function setEditorContent(content) {
872
+ var _editorRef$current$ed;
873
+ 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);
874
+ };
875
+ var _useForm = useForm({
876
+ formId: formId,
877
+ language: language
878
+ }),
879
+ data = _useForm.data;
880
+ useEffect(function () {
881
+ if (!data) return;
882
+ var pathArray = fieldName.split(".").map(function (part) {
883
+ var parsedPart = parseInt(part);
884
+ return isNaN(parsedPart) ? part : parsedPart;
885
+ });
886
+ setEditorContent(path(pathArray, data));
887
+ }, [data]);
888
+ useEffect(function () {
889
+ if (initialStateRef.current["language"] !== language) {
890
+ initialStateRef.current["language"] = language;
891
+ initialStateRef.current["value"] = null;
892
+ return;
893
+ }
894
+ if (initialStateRef.current["value"] === null && value !== null) {
895
+ setEditorContent(value);
896
+ initialStateRef.current["value"] = value;
897
+ }
898
+ }, [language, value]);
899
+ };
900
+
901
+ var Editor = function Editor() {
902
+ var editorRef = useRef({
903
+ editor: {}
904
+ });
905
+ var fieldName = "label";
906
+ var _useField = useField({
907
+ name: fieldName,
908
+ validate: validateEditorContent(editorRef)
909
+ }),
910
+ _useField2 = _slicedToArray(_useField, 3),
911
+ value = _useField2[0].value,
912
+ _useField2$ = _useField2[1],
913
+ touched = _useField2$.touched,
914
+ error = _useField2$.error,
915
+ _useField2$2 = _useField2[2],
916
+ setTouched = _useField2$2.setTouched,
917
+ setValue = _useField2$2.setValue;
918
+ useUpdateEditorContent({
919
+ editorRef: editorRef,
920
+ fieldName: fieldName,
921
+ value: value
922
+ });
923
+ return /*#__PURE__*/jsx("div", {
924
+ className: "w-full cursor-auto",
925
+ children: /*#__PURE__*/jsx(NeetoEditor, {
926
+ required: true,
927
+ error: touched ? error : "",
928
+ id: "editor",
929
+ initialValue: value,
930
+ name: fieldName,
931
+ ref: editorRef,
932
+ onBlur: function onBlur() {
933
+ return setTouched(true);
934
+ },
935
+ onChange: setValue
936
+ })
937
+ });
938
+ };
939
+
940
+ var RequiredSwitch = withT(function (_ref) {
941
+ var t = _ref.t;
942
+ return /*#__PURE__*/jsx("div", {
943
+ className: "w-full",
944
+ children: /*#__PURE__*/jsx(Switch, {
945
+ label: t("neetoForm.common.required"),
946
+ name: "isRequired"
947
+ })
948
+ });
949
+ });
950
+
951
+ var _excluded$9 = ["maxLength"];
952
+ 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; }
953
+ 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), true).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; }
954
+ var InputWithMaxLength = function InputWithMaxLength(_ref) {
955
+ var maxLength = _ref.maxLength,
956
+ props = _objectWithoutProperties(_ref, _excluded$9);
957
+ var _useField = useField(props),
958
+ _useField2 = _slicedToArray(_useField, 3),
959
+ value = _useField2[0].value,
960
+ setValue = _useField2[2].setValue;
961
+ useEffect(function () {
962
+ if (value && value.length > maxLength) {
963
+ setValue(value.substring(0, maxLength));
964
+ }
965
+ }, [value, maxLength, setValue]);
966
+ var shouldShowMaxLength = value && value.length > maxLength - 10;
967
+ return /*#__PURE__*/jsx(Input, _objectSpread$d(_objectSpread$d({}, props), shouldShowMaxLength && {
968
+ maxLength: maxLength
969
+ }));
970
+ };
971
+
972
+ var FieldCode = function FieldCode() {
973
+ var helpDocUrl = useHelpDoc("fieldCode");
974
+ var _useTranslation = useTranslation(),
975
+ t = _useTranslation.t;
976
+ return /*#__PURE__*/jsx(InputWithMaxLength, {
977
+ required: true,
978
+ label: t("neetoForm.questions.common.questionFields.field.fieldCode"),
979
+ name: "fieldCode",
980
+ rejectCharsRegex: FIELD_CODES_REJECT_CHARS_REGEX,
981
+ helpText: helpDocUrl && /*#__PURE__*/jsx(Trans, {
982
+ i18nKey: "neetoForm.questions.common.questionFields.field.fieldCodeHelpDescription",
983
+ components: {
984
+ Link: /*#__PURE__*/jsx(Button, {
985
+ className: "text-xs",
986
+ href: helpDocUrl,
987
+ style: "link",
988
+ target: "_blank"
989
+ })
990
+ }
991
+ })
992
+ });
993
+ };
994
+
995
+ var Form$1 = function Form(_ref) {
996
+ var questions = _ref.questions,
997
+ initialFocusRef = _ref.initialFocusRef,
998
+ isRequiredField = _ref.isRequiredField,
999
+ isDisabledFieldLabel = _ref.isDisabledFieldLabel,
1000
+ allQuestionKinds = _ref.allQuestionKinds,
1001
+ availableQuestionKinds = _ref.availableQuestionKinds,
1002
+ getActiveKindDetails = _ref.getActiveKindDetails,
1003
+ kindUniqueOn = _ref.kindUniqueOn,
1004
+ _ref$isEdit = _ref.isEdit,
1005
+ isEdit = _ref$isEdit === void 0 ? false : _ref$isEdit;
1006
+ var _useState = useState(false),
1007
+ _useState2 = _slicedToArray(_useState, 2),
1008
+ isFieldCodeInvalid = _useState2[0],
1009
+ setIsFieldCodeInvalid = _useState2[1];
1010
+ var _useTranslation = useTranslation(),
1011
+ t = _useTranslation.t;
1012
+ var _useFormikContext = useFormikContext(),
1013
+ values = _useFormikContext.values,
1014
+ setValues = _useFormikContext.setValues,
1015
+ setErrors = _useFormikContext.setErrors,
1016
+ setTouched = _useFormikContext.setTouched,
1017
+ setFieldValue = _useFormikContext.setFieldValue,
1018
+ errors = _useFormikContext.errors,
1019
+ submitCount = _useFormikContext.submitCount;
1020
+ var hideQuestionHelpDocUrl = useHelpDoc("hideQuestion");
1021
+ var readOnlyHelpDocUrl = useHelpDoc("readOnly");
1022
+ var responseVisibleOnlyToHostHelpDocUrl = useHelpDoc("responseVisibleOnlyToHost");
1023
+ var _useBuildFormStore = useBuildFormStore(function (store) {
1024
+ var _store$formState, _store$formState2, _store$formState3, _store$formState4;
1025
+ return {
1026
+ advancedFeatures: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["advancedFeatures"],
1027
+ selectedLanguage: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["selectedLanguage"],
1028
+ isUsingDefaultQuestionKinds: (_store$formState3 = store["formState"]) === null || _store$formState3 === void 0 ? void 0 : _store$formState3["isUsingDefaultQuestionKinds"],
1029
+ usesCustomSubmissionComponent: (_store$formState4 = store["formState"]) === null || _store$formState4 === void 0 ? void 0 : _store$formState4["usesCustomSubmissionComponent"]
1030
+ };
1031
+ }, shallow),
1032
+ advancedFeatures = _useBuildFormStore.advancedFeatures,
1033
+ selectedLanguage = _useBuildFormStore.selectedLanguage,
1034
+ isUsingDefaultQuestionKinds = _useBuildFormStore.isUsingDefaultQuestionKinds,
1035
+ usesCustomSubmissionComponent = _useBuildFormStore.usesCustomSubmissionComponent;
1036
+ var isFieldCodeEnabled = advancedFeatures.fieldCode,
1037
+ markResponsesAsReadOnly = advancedFeatures.markResponsesAsReadOnly,
1038
+ restrictResponseVisibilityToHost = advancedFeatures.restrictResponseVisibilityToHost;
1039
+ var kind = values.kind;
1040
+ var questionKinds = isEdit ? allQuestionKinds : availableQuestionKinds;
1041
+ var questionKindUniquenessPattern = mergeLeft(isEdit && kindUniqueOn ? kindUniqueOn(values) : {}, {
1042
+ type: kind
1043
+ });
1044
+ var _useStateWithDependen = useStateWithDependency(getQuestionKind(questionKinds, questionKindUniquenessPattern), [kind]),
1045
+ _useStateWithDependen2 = _slicedToArray(_useStateWithDependen, 1),
1046
+ questionKind = _useStateWithDependen2[0];
1047
+ var _ref2 = questionKind ? getActiveKindDetails({
1048
+ allQuestionKinds: allQuestionKinds,
1049
+ item: questionKind
1050
+ }) : {},
1051
+ _ref2$questionProps = _ref2.questionProps,
1052
+ questionProps = _ref2$questionProps === void 0 ? {} : _ref2$questionProps;
1053
+ useEffect(function () {
1054
+ if (submitCount > 0 && isPresent(errors === null || errors === void 0 ? void 0 : errors.fieldCode)) {
1055
+ setIsFieldCodeInvalid(true);
1056
+ }
1057
+ }, [submitCount]);
1058
+ var isRequired = questionKind && isRequiredField(questionKind);
1059
+ var isLabelDisabled = questionKind && isDisabledFieldLabel(questionKind);
1060
+ var isImmutable = questionKind && isImmutableField(questionKind);
1061
+ var shouldShowFieldCode = isFieldCodeEnabled && !includes(kind, QUESTIONS_WITHOUT_FIELD_CODE);
1062
+ var shouldShowHideSwitch = isFieldCodeEnabled && !usesCustomSubmissionComponent && !includes(kind, NON_HIDEABLE_FIELDS);
1063
+ var canRestrictResponseVisibilityToHost = restrictResponseVisibilityToHost && !includes(kind, NON_HIDEABLE_FIELDS);
1064
+ var canMarkResponsesAsReadOnly = markResponsesAsReadOnly && !includes(kind, NON_READ_ONLY_FIELDS);
1065
+ var isBasicSettingsVisible = !isRequired && (!isImmutable || shouldShowHideSwitch);
1066
+ var isSettingsBlockVisible = kind !== QUESTION_TYPES.SPOT && (isBasicSettingsVisible || canMarkResponsesAsReadOnly);
1067
+ var handleKindChange = function handleKindChange(option) {
1068
+ var data = buildQuestionData(option);
1069
+ updateFormState(data);
1070
+ };
1071
+ var buildQuestionData = function buildQuestionData(option) {
1072
+ if (isNil(option)) {
1073
+ return INITIAL_VALUES;
1074
+ }
1075
+ var label = option.label,
1076
+ value = option.value;
1077
+ var kind = extractKindFromOption(value);
1078
+ var questionKind = getQuestionKind(availableQuestionKinds, {
1079
+ type: kind,
1080
+ label: label
1081
+ });
1082
+ return createFieldData({
1083
+ kind: questionKind,
1084
+ isRequired: isRequired,
1085
+ questions: questions,
1086
+ selectedLanguage: selectedLanguage,
1087
+ isUsingDefaultQuestionKinds: isUsingDefaultQuestionKinds
1088
+ });
1089
+ };
1090
+ var updateFormState = function updateFormState(data) {
1091
+ setValues(data);
1092
+ setErrors({});
1093
+ setTouched({});
1094
+ };
1095
+ var handleLabelChange = function handleLabelChange(label) {
1096
+ var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LABEL_FIELDS.DEFAULT;
1097
+ setFieldValue(name, label);
1098
+ if (isEdit) return;
1099
+ var uniqueFieldCode = generateUniqueFieldCode({
1100
+ questions: questions,
1101
+ label: label,
1102
+ kind: kind
1103
+ });
1104
+ setFieldValue("fieldCode", uniqueFieldCode);
1105
+ };
1106
+ return /*#__PURE__*/jsx(Pane.Body, {
1107
+ children: /*#__PURE__*/jsxs("div", {
1108
+ className: "w-full space-y-4",
1109
+ children: [/*#__PURE__*/jsx(Select, {
1110
+ isClearable: true,
1111
+ isSearchable: true,
1112
+ defaultValue: buildDefaultValueForKind(questionKind),
1113
+ innerRef: initialFocusRef,
1114
+ isDisabled: isEdit,
1115
+ name: "kind",
1116
+ options: buildKindOptions(questionKinds),
1117
+ label: t("neetoForm.questions.common.questionFields.field.questionType"),
1118
+ onChange: handleKindChange
1119
+ }), isRichTextQuestion(kind) ? /*#__PURE__*/jsx(Editor, {
1120
+ isLabelDisabled: isLabelDisabled
1121
+ }) : /*#__PURE__*/jsxs("div", {
1122
+ className: "space-y-6",
1123
+ children: [/*#__PURE__*/jsx(Properties, {
1124
+ handleLabelChange: handleLabelChange,
1125
+ isLabelDisabled: isLabelDisabled,
1126
+ kind: kind,
1127
+ questionProps: questionProps
1128
+ }), isSettingsBlockVisible && /*#__PURE__*/jsxs(Block, {
1129
+ dataTestid: "settings-card",
1130
+ title: t("neetoForm.common.settings"),
1131
+ children: [isBasicSettingsVisible && /*#__PURE__*/jsxs(Fragment, {
1132
+ children: [!isImmutable && kind !== QUESTION_TYPES.ADDRESS && kind !== QUESTION_TYPES.SPOT && /*#__PURE__*/jsx(RequiredSwitch, {}), shouldShowHideSwitch && /*#__PURE__*/jsx(Switch, {
1133
+ label: t("neetoForm.common.hideQuestion"),
1134
+ name: "isHidden",
1135
+ labelProps: hideSwitchLabelProps(hideQuestionHelpDocUrl)
1136
+ }), canRestrictResponseVisibilityToHost && /*#__PURE__*/jsx(Switch, {
1137
+ label: t("neetoForm.common.responseVisibleOnlyToHost"),
1138
+ name: "isResponseVisibleOnlyToHost",
1139
+ labelProps: responseVisibleOnlyToHostSwitchLabelProps(responseVisibleOnlyToHostHelpDocUrl)
1140
+ })]
1141
+ }), canMarkResponsesAsReadOnly && /*#__PURE__*/jsx(Switch, {
1142
+ label: t("neetoForm.common.readOnly"),
1143
+ labelProps: readOnlySwitchLabelProps(readOnlyHelpDocUrl),
1144
+ name: "isReadOnly"
1145
+ })]
1146
+ }), shouldShowFieldCode && /*#__PURE__*/jsx(Accordion, {
1147
+ className: "neeto-form-nano-advanced-properties-accordion",
1148
+ "data-testid": "advanced-properties-card",
1149
+ defaultActiveKey: isFieldCodeInvalid ? 0 : null // This is to open the accordion when field code is invalid
1150
+ ,
1151
+ children: /*#__PURE__*/jsx(Accordion.Item, {
1152
+ title: t("neetoForm.common.advancedProperties"),
1153
+ children: /*#__PURE__*/jsx("div", {
1154
+ className: "flex flex-col space-y-4",
1155
+ children: shouldShowFieldCode && /*#__PURE__*/jsx(FieldCode, {})
1156
+ })
1157
+ })
1158
+ })]
1159
+ })]
1160
+ })
1161
+ });
1162
+ };
1163
+
1164
+ /* eslint-disable @bigbinary/neeto/file-name-and-export-name-standards */
1165
+ var requiredLabelValidation = function requiredLabelValidation(schema, field) {
1166
+ return schema.trim().required(t("neetoForm.common.fieldReq", {
1167
+ field: field
1168
+ }));
1169
+ };
1170
+ var fieldCodeValidation = function fieldCodeValidation(schema, field) {
1171
+ return schema.trim().required(t("neetoForm.common.fieldReq", {
1172
+ field: field
1173
+ })).matches(VALID_FIELD_CODE_REGEX, t("neetoForm.error.invalidField", {
1174
+ label: field
1175
+ }));
1176
+ };
1177
+ var richTextFieldMissingErrorMessage = function richTextFieldMissingErrorMessage(kind) {
1178
+ var field = equals(kind, QUESTION_TYPES.PARAGRAPH) ? t("neetoForm.fields.def") : t("neetoForm.fields.tcf");
1179
+ return t("neetoForm.error.fieldCantBeEmpty", {
1180
+ field: field
1181
+ });
1182
+ };
1183
+ var buildLabelValidationSchema = function buildLabelValidationSchema(kind, schema) {
1184
+ if (isNameQuestion(kind)) {
1185
+ return schema.notRequired();
1186
+ }
1187
+ return includes(kind, RICH_TEXT_QUESTIONS) ? schema.test("required", richTextFieldMissingErrorMessage(kind), function (value) {
1188
+ return !isEditorEmpty(value);
1189
+ }) : requiredLabelValidation(schema, t("neetoForm.questions.common.questionFields.field.question"));
1190
+ };
1191
+ var buildNameLabelValidationSchema = function buildNameLabelValidationSchema(question, schema) {
1192
+ var isFullName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1193
+ var isRequired = isFullName ? !question.isSplitMode : question.isSplitMode;
1194
+ return isNameQuestion(question.kind) && isRequired ? requiredLabelValidation(schema, t("neetoForm.questions.common.questionFields.field.question")) : schema.notRequired();
1195
+ };
1196
+ var buildOpinionScaleLabelValidationSchema = function buildOpinionScaleLabelValidationSchema(label) {
1197
+ return stringSchema.when("hasOpinionLabels", {
1198
+ is: true,
1199
+ then: requiredLabelValidation(stringSchema, label).max(OPINION_LABEL_MAX_LENGTH, t("neetoForm.error.mustBeOrLessThanOrEqualTo", {
1200
+ value: OPINION_LABEL_MAX_LENGTH
1201
+ })),
1202
+ otherwise: stringSchema.notRequired()
1203
+ });
1204
+ };
1205
+ var stringSchema = yup.string();
1206
+ var formValidationSchema = function formValidationSchema(question) {
1207
+ var isFieldCodeEnabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1208
+ return yup.object().shape({
1209
+ kind: yup.string().trim().required(t("neetoForm.common.fieldReq", {
1210
+ field: t("neetoForm.questions.common.questionFields.field.questionType")
1211
+ })),
1212
+ label: yup.string().when("kind", buildLabelValidationSchema),
1213
+ fullNameLabel: buildNameLabelValidationSchema(question, stringSchema, true),
1214
+ firstNameLabel: buildNameLabelValidationSchema(question, stringSchema),
1215
+ lastNameLabel: buildNameLabelValidationSchema(question, stringSchema),
1216
+ fieldCode: yup.string().trim().notOneOf(RESERVED_FIELD_CODES, t("neetoForm.error.invalidFieldCode")).when("kind", function (kind, schema) {
1217
+ return isFieldCodeEnabled && !includes(kind, QUESTIONS_WITHOUT_FIELD_CODE) ? fieldCodeValidation(schema, t("neetoForm.questions.common.questionFields.field.fieldCode")) : schema.notRequired();
1218
+ }),
1219
+ optionsAttributes: yup.array().when("kind", function (kind, schema) {
1220
+ return includes(kind, SELECTABLE_KINDS) ? schema.of(yup.object().shape({
1221
+ label: yup.string().when("_destroy", {
1222
+ is: true,
1223
+ otherwise: requiredLabelValidation(yup.string(), t("neetoForm.questions.common.questionFields.field.option"))
1224
+ })
1225
+ })) : schema.notRequired();
1226
+ }),
1227
+ fields: yup.array().when("kind", function (kind, schema) {
1228
+ return kind === QUESTION_TYPES.ADDRESS ? schema.of(yup.object().shape({
1229
+ label: yup.string().when("_destroy", {
1230
+ is: true,
1231
+ otherwise: yup.string().trim().required(t("neetoForm.error.allFieldsRequired"))
1232
+ })
1233
+ })) : schema.notRequired();
1234
+ }),
1235
+ highestRatingLabel: yup.string().nullable(),
1236
+ averageRatingLabel: yup.string().nullable(),
1237
+ lowestRatingLabel: yup.string().nullable(),
1238
+ leftOpinionLabel: buildOpinionScaleLabelValidationSchema(t("neetoForm.questions.opinionScale.leftLabel")),
1239
+ rightOpinionLabel: buildOpinionScaleLabelValidationSchema(t("neetoForm.questions.opinionScale.rightLabel"))
1240
+ });
1241
+ };
1242
+
1243
+ var _excluded$8 = ["question", "onClose", "questions", "handleSelect", "isOpen"];
1244
+ 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; }
1245
+ 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), true).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; }
1246
+ var Add = function Add(_ref) {
1247
+ var question = _ref.question,
1248
+ onClose = _ref.onClose,
1249
+ questions = _ref.questions,
1250
+ handleSelect = _ref.handleSelect,
1251
+ isOpen = _ref.isOpen,
1252
+ props = _objectWithoutProperties(_ref, _excluded$8);
1253
+ var _useBuildFormStore = useBuildFormStore(function (store) {
1254
+ var _store$formState, _store$formState2, _store$formState3;
1255
+ return {
1256
+ formId: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["formId"],
1257
+ selectedLanguage: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["selectedLanguage"],
1258
+ onMutateSuccess: (_store$formState3 = store["formState"]) === null || _store$formState3 === void 0 ? void 0 : _store$formState3["onMutateSuccess"]
1259
+ };
1260
+ }, shallow),
1261
+ formId = _useBuildFormStore.formId,
1262
+ language = _useBuildFormStore.selectedLanguage,
1263
+ onMutateSuccess = _useBuildFormStore.onMutateSuccess;
1264
+ var isFieldCodeEnabled = useBuildFormStore(path(["advancedFeatures", "fieldCode"]));
1265
+ var _useTranslation = useTranslation(),
1266
+ t = _useTranslation.t;
1267
+ var _useCreateQuestion = useCreateQuestion(formId, language, {
1268
+ onSuccess: function onSuccess() {
1269
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1270
+ args[_key] = arguments[_key];
1271
+ }
1272
+ onMutateSuccess === null || onMutateSuccess === void 0 || onMutateSuccess.apply(void 0, [QUESTION_ACTIONS.ADD].concat(args));
1273
+ showThumbsUpToastr();
1274
+ onClose();
1275
+ }
1276
+ }),
1277
+ createQuestion = _useCreateQuestion.mutate,
1278
+ isCreating = _useCreateQuestion.isPending;
1279
+ var handleSubmit = function handleSubmit(values) {
1280
+ if (isCreating || !isOpen) return;
1281
+ var displayOrder = question ? question.displayOrder + 1 : questions.length;
1282
+ createQuestion({
1283
+ language: language,
1284
+ neetoFormQuestion: mergeLeft({
1285
+ displayOrder: displayOrder
1286
+ }, transformValues(values))
1287
+ }, {
1288
+ onSuccess: function onSuccess(_ref2) {
1289
+ var questions = _ref2.questions;
1290
+ var newQuestion = findBy({
1291
+ displayOrder: displayOrder
1292
+ }, questions);
1293
+ handleSelect(newQuestion);
1294
+ }
1295
+ });
1296
+ };
1297
+ return /*#__PURE__*/jsxs(Fragment, {
1298
+ children: [/*#__PURE__*/jsx(Pane.Header, {
1299
+ children: /*#__PURE__*/jsx(Typography, {
1300
+ "data-testid": "add-question-pane-header",
1301
+ style: "h2",
1302
+ children: t("neetoForm.questions.common.primaryPanel.addQuestion")
1303
+ })
1304
+ }), /*#__PURE__*/jsx(Form$2, {
1305
+ formikProps: {
1306
+ initialValues: INITIAL_VALUES,
1307
+ validationSchema: formValidationSchema(INITIAL_VALUES, isFieldCodeEnabled),
1308
+ onSubmit: handleSubmit
1309
+ },
1310
+ children: /*#__PURE__*/jsxs(Fragment, {
1311
+ children: [/*#__PURE__*/jsx(Form$1, _objectSpread$c({}, _objectSpread$c(_objectSpread$c({}, props), {}, {
1312
+ question: question,
1313
+ questions: questions
1314
+ }))), /*#__PURE__*/jsx(Pane.Footer, {
1315
+ children: /*#__PURE__*/jsx(ActionBlock, {
1316
+ cancelButtonProps: {
1317
+ onClick: onClose
1318
+ },
1319
+ isSubmitting: isCreating
1320
+ })
1321
+ })]
1322
+ })
1323
+ })]
1324
+ });
1325
+ };
1326
+
1327
+ var _excluded$7 = ["question", "isOpen", "onClose"];
1328
+ 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; }
1329
+ 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), true).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; }
1330
+ var Edit = function Edit(_ref) {
1331
+ var question = _ref.question,
1332
+ isOpen = _ref.isOpen,
1333
+ onClose = _ref.onClose,
1334
+ props = _objectWithoutProperties(_ref, _excluded$7);
1335
+ var _useTranslation = useTranslation(),
1336
+ t = _useTranslation.t;
1337
+ var _useBuildFormStore = useBuildFormStore(function (store) {
1338
+ var _store$formState, _store$formState2;
1339
+ return {
1340
+ selectedLanguage: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["selectedLanguage"],
1341
+ onMutateSuccess: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["onMutateSuccess"]
1342
+ };
1343
+ }, shallow),
1344
+ language = _useBuildFormStore.selectedLanguage,
1345
+ onMutateSuccess = _useBuildFormStore.onMutateSuccess;
1346
+ var isFieldCodeEnabled = useBuildFormStore(path(["advancedFeatures", "fieldCode"]));
1347
+ var _useUpdateQuestion = useUpdateQuestion(question === null || question === void 0 ? void 0 : question.formId, language),
1348
+ updateQuestion = _useUpdateQuestion.mutate,
1349
+ isUpdating = _useUpdateQuestion.isPending;
1350
+ var handleSubmit = function handleSubmit(values, _ref2) {
1351
+ var setSubmitting = _ref2.setSubmitting;
1352
+ if (isUpdating || !isOpen) return;
1353
+ var payload = {
1354
+ language: language,
1355
+ neetoFormQuestion: transformValues(values)
1356
+ };
1357
+ updateQuestion({
1358
+ questionId: question.id,
1359
+ payload: payload
1360
+ }, {
1361
+ onSuccess: function onSuccess() {
1362
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1363
+ args[_key] = arguments[_key];
1364
+ }
1365
+ onMutateSuccess === null || onMutateSuccess === void 0 || onMutateSuccess.apply(void 0, [QUESTION_ACTIONS.EDIT].concat(args));
1366
+ showThumbsUpToastr();
1367
+ onClose();
1368
+ },
1369
+ onSettled: function onSettled() {
1370
+ return setSubmitting(false);
1371
+ }
1372
+ });
1373
+ };
1374
+ return /*#__PURE__*/jsxs(Fragment, {
1375
+ children: [/*#__PURE__*/jsx(Pane.Header, {
1376
+ children: /*#__PURE__*/jsx(Typography, {
1377
+ "data-testid": "edit-question-pane-header",
1378
+ style: "h2",
1379
+ children: t("neetoForm.questions.common.editQuestion")
1380
+ })
1381
+ }), /*#__PURE__*/jsx(Form$2, {
1382
+ formikProps: {
1383
+ initialValues: question,
1384
+ validationSchema: formValidationSchema(question, isFieldCodeEnabled),
1385
+ onSubmit: handleSubmit
1386
+ },
1387
+ children: /*#__PURE__*/jsxs(Fragment, {
1388
+ children: [/*#__PURE__*/jsx(Form$1, _objectSpread$b(_objectSpread$b({}, _objectSpread$b({
1389
+ question: question
1390
+ }, props)), {}, {
1391
+ isEdit: true
1392
+ })), /*#__PURE__*/jsx(Pane.Footer, {
1393
+ children: /*#__PURE__*/jsx(ActionBlock, {
1394
+ cancelButtonProps: {
1395
+ onClick: onClose
1396
+ },
1397
+ isSubmitting: isUpdating
1398
+ })
1399
+ })]
1400
+ })
1401
+ })]
1402
+ });
1403
+ };
1404
+
1405
+ var VARIANTS = {
1406
+ hidden: {
1407
+ opacity: 0,
1408
+ height: 0,
1409
+ overflow: "hidden"
1410
+ },
1411
+ visible: {
1412
+ opacity: 1,
1413
+ height: "auto"
1414
+ }
1415
+ };
1416
+
1417
+ var _excluded$6 = ["open", "className", "children"];
1418
+ 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; }
1419
+ 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), true).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; }
1420
+ var Collapsible = function Collapsible(_ref) {
1421
+ var open = _ref.open,
1422
+ _ref$className = _ref.className,
1423
+ className = _ref$className === void 0 ? "" : _ref$className,
1424
+ children = _ref.children,
1425
+ otherProps = _objectWithoutProperties(_ref, _excluded$6);
1426
+ return /*#__PURE__*/jsx(AnimatePresence, {
1427
+ children: open && /*#__PURE__*/jsx(motion.div, _objectSpread$a(_objectSpread$a({
1428
+ animate: "visible",
1429
+ exit: "hidden",
1430
+ initial: "hidden",
1431
+ transition: {
1432
+ duration: 0.3
1433
+ },
1434
+ variants: VARIANTS
1435
+ }, otherProps), {}, {
1436
+ children: /*#__PURE__*/jsx("div", {
1437
+ className: className,
1438
+ children: children
1439
+ })
1440
+ }))
1441
+ });
1442
+ };
1443
+
1444
+ var ADDRESS_FIELD_WIDTH_OPTIONS = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ADDRESS_FIELD_WIDTHS.FULL, {
1445
+ label: t("neetoForm.questions.address.widths.full"),
1446
+ value: ADDRESS_FIELD_WIDTHS.FULL
1447
+ }), ADDRESS_FIELD_WIDTHS.HALF, {
1448
+ label: t("neetoForm.questions.address.widths.half"),
1449
+ value: ADDRESS_FIELD_WIDTHS.HALF
1450
+ }), ADDRESS_FIELD_WIDTHS.ONE_FOURTH, {
1451
+ label: t("neetoForm.questions.address.widths.oneFourth"),
1452
+ value: ADDRESS_FIELD_WIDTHS.ONE_FOURTH
1453
+ }), ADDRESS_FIELD_WIDTHS.THREE_FOURTH, {
1454
+ label: t("neetoForm.questions.address.widths.threeFourth"),
1455
+ value: ADDRESS_FIELD_WIDTHS.THREE_FOURTH
1456
+ });
1457
+ var ADDRESS_FIELD_TYPE_OPTIONS = _defineProperty(_defineProperty({}, ADDRESS_FIELD_TYPES.INPUT, {
1458
+ label: t("neetoForm.questions.address.types.textInput"),
1459
+ value: ADDRESS_FIELD_TYPES.INPUT
1460
+ }), ADDRESS_FIELD_TYPES.SELECT, {
1461
+ label: t("neetoForm.questions.address.types.dropdown"),
1462
+ value: ADDRESS_FIELD_TYPES.SELECT
1463
+ });
1464
+ var ADDRESS_FIELD_FORM_VALIDATION_SCHEMA = yup.object().shape({
1465
+ label: yup.string().trim().required(t("neetoForm.error.requiredField", {
1466
+ label: t("neetoForm.questions.common.questionFields.field.label")
1467
+ })),
1468
+ width: yup.object().nullable().required(t("neetoForm.error.requiredField", {
1469
+ label: t("neetoForm.questions.address.width")
1470
+ })),
1471
+ fieldType: yup.object().nullable().required(t("neetoForm.error.requiredField", {
1472
+ label: t("neetoForm.questions.address.type")
1473
+ })),
1474
+ properties: yup.object().shape({
1475
+ options: yup.array().of(yup.object().shape({
1476
+ label: yup.string().required(t("neetoForm.error.requiredField", {
1477
+ label: t("neetoForm.common.option")
1478
+ }))
1479
+ })).unique("label", t("neetoForm.error.removeDuplicates"))
1480
+ })
1481
+ });
1482
+ var ERROR_MESSAGE_DELIMITER$1 = ". ";
1483
+
1484
+ 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; }
1485
+ 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), true).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; }
1486
+ var removeDuplicateErrorMessages$1 = pipe(filter(isNotNil), map(values), uniq, join(ERROR_MESSAGE_DELIMITER$1));
1487
+ var getAddressModalInitialValues = function getAddressModalInitialValues(field) {
1488
+ return field ? _objectSpread$9(_objectSpread$9({}, field), {}, {
1489
+ width: ADDRESS_FIELD_WIDTH_OPTIONS[field.width],
1490
+ fieldType: ADDRESS_FIELD_TYPE_OPTIONS[field.fieldType]
1491
+ }) : {
1492
+ label: "",
1493
+ isRequired: false,
1494
+ width: ADDRESS_FIELD_WIDTH_OPTIONS[ADDRESS_FIELD_WIDTHS.FULL],
1495
+ fieldType: ADDRESS_FIELD_TYPE_OPTIONS[ADDRESS_FIELD_TYPES.INPUT]
1496
+ };
1497
+ };
1498
+ var sanitizeAddressField = function sanitizeAddressField(field, isSelectField, defaultOptions) {
1499
+ var hasOptions = pathSatisfies(isPresent, ["properties", "options"], field);
1500
+ if (isSelectField && !hasOptions) {
1501
+ return assocPath(["properties", "options"], defaultOptions, field);
1502
+ }
1503
+ if (!isSelectField && hasOptions) {
1504
+ return dissoc("properties", field);
1505
+ }
1506
+ return field;
1507
+ };
1508
+ var formatErrorMessage$1 = function formatErrorMessage(error) {
1509
+ if (typeof error === "string") return error;
1510
+ return removeDuplicateErrorMessages$1(error);
1511
+ };
1512
+
1513
+ var _excluded$5 = ["width", "fieldType"];
1514
+ 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; }
1515
+ 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), true).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; }
1516
+ var ManagePane = function ManagePane(_ref) {
1517
+ var isOpen = _ref.isOpen,
1518
+ selectedFieldId = _ref.selectedFieldId,
1519
+ onClose = _ref.onClose,
1520
+ title = _ref.title,
1521
+ fields = _ref.fields,
1522
+ initialFocusRef = _ref.initialFocusRef;
1523
+ var _useField = useField("fields"),
1524
+ _useField2 = _slicedToArray(_useField, 3),
1525
+ allFields = _useField2[0].value,
1526
+ setValue = _useField2[2].setValue;
1527
+ var _useTranslation = useTranslation(),
1528
+ t = _useTranslation.t;
1529
+ var defaultOptions = generateDefaultOptions(MINIMUM_ADDRESS_FIELDS);
1530
+ var editingField = findById(selectedFieldId, fields);
1531
+ var initialValues = getAddressModalInitialValues(editingField);
1532
+ var handleSubmit = function handleSubmit(_ref2) {
1533
+ var width = _ref2.width,
1534
+ fieldType = _ref2.fieldType,
1535
+ field = _objectWithoutProperties(_ref2, _excluded$5);
1536
+ var deletedFields = getDeletedRecords(allFields);
1537
+ var isSelectField = fieldType.value === ADDRESS_FIELD_TYPES.SELECT;
1538
+ var sanitizedField = sanitizeAddressField(field, isSelectField, defaultOptions);
1539
+ if (isNil(selectedFieldId)) {
1540
+ var position = fields.length;
1541
+ var id = "draft-".concat(randomId());
1542
+ var newField = _objectSpread$8(_objectSpread$8({
1543
+ id: id
1544
+ }, sanitizedField), {}, {
1545
+ altId: "alt-".concat(randomId()),
1546
+ position: position,
1547
+ width: width.value,
1548
+ fieldType: fieldType.value
1549
+ });
1550
+ var nextFields = append(newField, fields);
1551
+ setValue([].concat(_toConsumableArray(nextFields), _toConsumableArray(deletedFields)));
1552
+ } else {
1553
+ var selectedFieldIndex = findIndexById(selectedFieldId, fields);
1554
+ setValue(assoc(selectedFieldIndex, _objectSpread$8(_objectSpread$8({}, sanitizedField), {}, {
1555
+ width: width.value,
1556
+ fieldType: fieldType.value
1557
+ }), [].concat(_toConsumableArray(fields), _toConsumableArray(deletedFields))));
1558
+ }
1559
+ onClose();
1560
+ };
1561
+ var handleFieldTypeChange = function handleFieldTypeChange(setFieldValue, values) {
1562
+ return function (fieldType) {
1563
+ var _values$properties;
1564
+ setFieldValue("fieldType", fieldType);
1565
+ if (fieldType.value === ADDRESS_FIELD_TYPES.SELECT && isNotPresent((_values$properties = values.properties) === null || _values$properties === void 0 ? void 0 : _values$properties.options)) {
1566
+ setFieldValue("properties.options", defaultOptions);
1567
+ }
1568
+ };
1569
+ };
1570
+ return /*#__PURE__*/jsxs(Pane, {
1571
+ initialFocusRef: initialFocusRef,
1572
+ isOpen: isOpen,
1573
+ onClose: onClose,
1574
+ children: [/*#__PURE__*/jsx(Pane.Header, {
1575
+ children: /*#__PURE__*/jsx(Typography, {
1576
+ "data-testid": "add-address-field-title",
1577
+ style: "h2",
1578
+ weight: "semibold",
1579
+ children: title
1580
+ })
1581
+ }), /*#__PURE__*/jsx(Form$2, {
1582
+ formikProps: {
1583
+ initialValues: initialValues,
1584
+ validationSchema: ADDRESS_FIELD_FORM_VALIDATION_SCHEMA,
1585
+ onSubmit: handleSubmit
1586
+ },
1587
+ children: function children(_ref3) {
1588
+ var _values$fieldType;
1589
+ var values = _ref3.values,
1590
+ setFieldValue = _ref3.setFieldValue;
1591
+ return /*#__PURE__*/jsxs(Fragment, {
1592
+ children: [/*#__PURE__*/jsx(Pane.Body, {
1593
+ children: /*#__PURE__*/jsxs("div", {
1594
+ className: "w-full space-y-6",
1595
+ children: [/*#__PURE__*/jsx(Input, {
1596
+ name: "label",
1597
+ ref: initialFocusRef,
1598
+ label: t("neetoForm.questions.common.questionFields.field.label"),
1599
+ placeholder: t("neetoForm.questions.address.fieldLabelPlaceholder")
1600
+ }), /*#__PURE__*/jsxs("div", {
1601
+ className: "grid grid-cols-2 gap-6",
1602
+ children: [/*#__PURE__*/jsx(Select, {
1603
+ label: t("neetoForm.questions.address.width"),
1604
+ name: "width",
1605
+ options: Object.values(ADDRESS_FIELD_WIDTH_OPTIONS)
1606
+ }), /*#__PURE__*/jsx(Select, {
1607
+ label: t("neetoForm.questions.address.type"),
1608
+ name: "fieldType",
1609
+ options: Object.values(ADDRESS_FIELD_TYPE_OPTIONS),
1610
+ onChange: handleFieldTypeChange(setFieldValue, values)
1611
+ })]
1612
+ }), /*#__PURE__*/jsx(Collapsible, {
1613
+ open: (values === null || values === void 0 || (_values$fieldType = values.fieldType) === null || _values$fieldType === void 0 ? void 0 : _values$fieldType.value) === ADDRESS_FIELD_TYPES.SELECT,
1614
+ children: /*#__PURE__*/jsx("div", {
1615
+ className: "flex flex-col",
1616
+ children: /*#__PURE__*/jsx(OptionFields, {
1617
+ draggable: true,
1618
+ minOptions: MINIMUM_ADDRESS_FIELDS,
1619
+ name: "properties.options"
1620
+ })
1621
+ })
1622
+ }), /*#__PURE__*/jsx("div", {
1623
+ className: "flex items-center gap-4",
1624
+ children: /*#__PURE__*/jsx(Switch, {
1625
+ label: t("neetoForm.common.required"),
1626
+ name: "isRequired"
1627
+ })
1628
+ })]
1629
+ })
1630
+ }), /*#__PURE__*/jsx(Pane.Footer, {
1631
+ children: /*#__PURE__*/jsx("div", {
1632
+ className: "flex items-center gap-2",
1633
+ children: /*#__PURE__*/jsx(ActionBlock, {
1634
+ className: "flex gap-x-2",
1635
+ cancelButtonProps: {
1636
+ type: "reset",
1637
+ onClick: onClose,
1638
+ disabled: false
1639
+ },
1640
+ submitButtonProps: {
1641
+ label: t("neetoForm.common.saveChanges")
1642
+ }
1643
+ })
1644
+ })
1645
+ })]
1646
+ });
1647
+ }
1648
+ })]
1649
+ });
1650
+ };
1651
+
1652
+ var Address = function Address() {
1653
+ var _findById;
1654
+ var _useState = useState(false),
1655
+ _useState2 = _slicedToArray(_useState, 2),
1656
+ isAddressFieldPaneOpen = _useState2[0],
1657
+ setIsAddressFieldPaneOpen = _useState2[1];
1658
+ var _useState3 = useState(false),
1659
+ _useState4 = _slicedToArray(_useState3, 2),
1660
+ isDeleteAddressFieldAlertOpen = _useState4[0],
1661
+ setIsDeleteAddressFieldAlertOpen = _useState4[1];
1662
+ var _useState5 = useState(null),
1663
+ _useState6 = _slicedToArray(_useState5, 2),
1664
+ selectedFieldId = _useState6[0],
1665
+ setSelectedFieldId = _useState6[1];
1666
+ var initialFocusRef = useRef(null);
1667
+ var _useTranslation = useTranslation(),
1668
+ t = _useTranslation.t;
1669
+ var _useBuildFormStore = useBuildFormStore(function (store) {
1670
+ var _store$formState;
1671
+ return {
1672
+ selectedLanguage: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["selectedLanguage"]
1673
+ };
1674
+ }, shallow),
1675
+ selectedLanguage = _useBuildFormStore.selectedLanguage;
1676
+ var name = "fields";
1677
+ var _useField = useField(name),
1678
+ _useField2 = _slicedToArray(_useField, 3),
1679
+ fields = _useField2[0].value,
1680
+ _useField2$ = _useField2[1],
1681
+ error = _useField2$.error,
1682
+ touched = _useField2$.touched,
1683
+ setFields = _useField2[2].setValue;
1684
+ var handleDelete = function handleDelete() {
1685
+ var deletedFields = getDeletedRecords(fields);
1686
+ var nextFields = getActiveRecords(fields);
1687
+ var selectedFieldIndex = findIndexById(selectedFieldId, nextFields);
1688
+ nextFields = assocPath([selectedFieldIndex, "deleted"], true, nextFields);
1689
+ setFields([].concat(_toConsumableArray(nextFields), _toConsumableArray(deletedFields)));
1690
+ };
1691
+ return /*#__PURE__*/jsxs(Fragment, {
1692
+ children: [/*#__PURE__*/jsx(Block, {
1693
+ dataTestid: "address-fields-block",
1694
+ title: t("neetoForm.questions.address.fields"),
1695
+ children: /*#__PURE__*/jsxs("div", {
1696
+ children: [/*#__PURE__*/jsx(OptionFields, {
1697
+ name: name,
1698
+ draggable: true,
1699
+ shouldDestroy: true,
1700
+ editable: false,
1701
+ isNewItemsPrefilled: isDefaultLanguage(selectedLanguage),
1702
+ itemLabel: t("neetoForm.common.field"),
1703
+ minOptions: MINIMUM_ADDRESS_FIELDS,
1704
+ shouldResetEmptyOptionOnBlur: false,
1705
+ buttonProps: {
1706
+ label: t("neetoForm.questions.address.addField"),
1707
+ onClick: function onClick() {
1708
+ return setIsAddressFieldPaneOpen(true);
1709
+ }
1710
+ },
1711
+ onDelete: function onDelete(id) {
1712
+ setSelectedFieldId(id);
1713
+ setIsDeleteAddressFieldAlertOpen(true);
1714
+ },
1715
+ onEdit: function onEdit(id) {
1716
+ setSelectedFieldId(id);
1717
+ setIsAddressFieldPaneOpen(true);
1718
+ }
1719
+ }), touched && error && /*#__PURE__*/jsx("p", {
1720
+ className: "neeto-form-engine-input__error",
1721
+ "data-testid": "neeto-form-engine-address-fields-error",
1722
+ children: formatErrorMessage$1(error)
1723
+ })]
1724
+ })
1725
+ }), /*#__PURE__*/jsx(ManagePane, {
1726
+ initialFocusRef: initialFocusRef,
1727
+ selectedFieldId: selectedFieldId,
1728
+ fields: getActiveRecords(fields),
1729
+ isOpen: isAddressFieldPaneOpen,
1730
+ title: isNotNil(selectedFieldId) ? t("neetoForm.questions.address.editField") : t("neetoForm.questions.address.addField"),
1731
+ onClose: function onClose() {
1732
+ setIsAddressFieldPaneOpen(false);
1733
+ setSelectedFieldId(null);
1734
+ }
1735
+ }), /*#__PURE__*/jsx(Alert, {
1736
+ isOpen: isDeleteAddressFieldAlertOpen,
1737
+ submitButtonLabel: t("neetoForm.common.delete"),
1738
+ title: t("neetoForm.questions.address.deleteAlert.title"),
1739
+ message: /*#__PURE__*/jsx(Trans, {
1740
+ i18nKey: "neetoForm.questions.address.deleteAlert.message",
1741
+ values: {
1742
+ label: (_findById = findById(selectedFieldId, fields)) === null || _findById === void 0 ? void 0 : _findById.label
1743
+ }
1744
+ }),
1745
+ onClose: function onClose() {
1746
+ setIsDeleteAddressFieldAlertOpen(false);
1747
+ setSelectedFieldId(null);
1748
+ },
1749
+ onSubmit: function onSubmit() {
1750
+ setIsDeleteAddressFieldAlertOpen(false);
1751
+ handleDelete();
1752
+ setSelectedFieldId(null);
1753
+ }
1754
+ })]
1755
+ });
1756
+ };
1757
+
1758
+ var Captcha = withT(function (_ref) {
1759
+ var t = _ref.t;
1760
+ return /*#__PURE__*/jsxs(Radio, {
1761
+ label: t("neetoForm.common.captchaType"),
1762
+ labelProps: {
1763
+ required: true
1764
+ },
1765
+ name: "variant",
1766
+ children: [/*#__PURE__*/jsx(Radio.Item, {
1767
+ label: t("neetoForm.common.reCaptchaV2"),
1768
+ value: CAPTCHA_TYPES.RECAPTCHA_V2
1769
+ }), /*#__PURE__*/jsx(Radio.Item, {
1770
+ label: t("neetoForm.common.mathCaptcha"),
1771
+ value: CAPTCHA_TYPES.MATH_CAPTCHA
1772
+ })]
1773
+ });
1774
+ });
1775
+
1776
+ var _excluded$4 = ["name", "title", "className"];
1777
+ 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; }
1778
+ 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), true).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; }
1779
+ var SwitchBlock = function SwitchBlock(_ref) {
1780
+ var name = _ref.name,
1781
+ title = _ref.title,
1782
+ _ref$className = _ref.className,
1783
+ className = _ref$className === void 0 ? "" : _ref$className,
1784
+ otherProps = _objectWithoutProperties(_ref, _excluded$4);
1785
+ return /*#__PURE__*/jsxs(Label, {
1786
+ className: classnames("flex items-center justify-start gap-2 ", className),
1787
+ "data-testid": "neeto-form-engine-".concat(hyphenate(title && name), "-toggle-label"),
1788
+ children: [/*#__PURE__*/jsx(Switch, _objectSpread$7(_objectSpread$7({}, _objectSpread$7(_objectSpread$7({}, otherProps), {}, {
1789
+ name: name
1790
+ })), {}, {
1791
+ "data-testid": "neeto-form-engine-".concat(hyphenate(title && name), "-switch")
1792
+ })), /*#__PURE__*/jsx(Typography, {
1793
+ component: "span",
1794
+ style: "body1",
1795
+ children: title
1796
+ })]
1797
+ });
1798
+ };
1799
+
1800
+ var DOMAIN_RESTRICTION_TRANSLATIONS = {
1801
+ whitelistedDomains: {
1802
+ title: t("neetoForm.domainRestriction.whitelistedDomains.label"),
1803
+ description: t("neetoForm.domainRestriction.whitelistedDomains.description"),
1804
+ popoverDescription: t("neetoForm.domainRestriction.whitelistedDomains.popoverDescription")
1805
+ },
1806
+ blacklistedDomains: {
1807
+ title: t("neetoForm.domainRestriction.blacklistedDomains.label"),
1808
+ description: t("neetoForm.domainRestriction.blacklistedDomains.description"),
1809
+ popoverDescription: t("neetoForm.domainRestriction.blacklistedDomains.popoverDescription")
1810
+ }
1811
+ };
1812
+ var EMAIL_VERIFICATION_TRANSLATIONS = {
1813
+ title: t("neetoForm.emailVerification.label"),
1814
+ popoverDescription: t("neetoForm.emailVerification.popoverDescription")
1815
+ };
1816
+
1817
+ var _excluded$3 = ["children"];
1818
+ 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; }
1819
+ 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), true).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; }
1820
+ var STYLES = {
1821
+ border: {
1822
+ "default": "1px solid rgb(var(--neeto-ui-gray-400))",
1823
+ error: "1px solid rgb(var(--neeto-ui-error-800)) !important"
1824
+ },
1825
+ color: {
1826
+ "default": "rgb(var(--neeto-ui-gray-800))",
1827
+ error: "rgb(var(--neeto-ui-error-800)) !important"
1828
+ }
1829
+ };
1830
+ var MultiValueRemove = function MultiValueRemove(props) {
1831
+ return /*#__PURE__*/jsx(components.MultiValueRemove, _objectSpread$6(_objectSpread$6({}, props), {}, {
1832
+ innerProps: _objectSpread$6(_objectSpread$6({}, props.innerProps), {}, _defineProperty({}, "data-testid", "".concat(hyphenize(props.data.label), "-remove-icon"))),
1833
+ children: /*#__PURE__*/jsx(Close, {
1834
+ size: 16
1835
+ })
1836
+ }));
1837
+ };
1838
+ var ValueContainer = function ValueContainer(_ref) {
1839
+ var children = _ref.children,
1840
+ props = _objectWithoutProperties(_ref, _excluded$3);
1841
+ var _useTranslation = useTranslation(),
1842
+ t = _useTranslation.t;
1843
+ var getValue = props.getValue,
1844
+ _props$selectProps = props.selectProps,
1845
+ isFocused = _props$selectProps.isFocused,
1846
+ visibleDomainsCount = _props$selectProps.visibleDomainsCount;
1847
+ var value = getValue();
1848
+ var _children = _toArray(children),
1849
+ firstChild = _children[0],
1850
+ rest = _children.slice(1);
1851
+ var shouldCollapse = !isFocused && value.length > visibleDomainsCount;
1852
+ return /*#__PURE__*/jsxs(components.ValueContainer, _objectSpread$6(_objectSpread$6({}, props), {}, {
1853
+ innerProps: _objectSpread$6(_objectSpread$6({}, props.innerProps), {}, _defineProperty({}, "data-testid", "multi-domain-input-container")),
1854
+ children: [shouldCollapse ? firstChild.slice(0, visibleDomainsCount) : firstChild, shouldCollapse && /*#__PURE__*/jsx(Tag, {
1855
+ style: "secondary",
1856
+ label: t("neetoForm.common.remainingItemsCount", {
1857
+ count: value.length - visibleDomainsCount
1858
+ })
1859
+ }), rest]
1860
+ }));
1861
+ };
1862
+ var ClearIndicator = function ClearIndicator(props) {
1863
+ return /*#__PURE__*/jsx(components.ClearIndicator, _objectSpread$6(_objectSpread$6({}, props), {}, {
1864
+ innerProps: _objectSpread$6(_objectSpread$6({}, props.innerProps), {}, _defineProperty({}, "data-testid", "clear-all-button")),
1865
+ children: /*#__PURE__*/jsx(Close, {
1866
+ className: "cursor-pointer",
1867
+ size: 16
1868
+ })
1869
+ }));
1870
+ };
1871
+ var ERROR_MESSAGE_DELIMITER = ". ";
1872
+ var DELIMITER_KEYS = ["Enter", "Tab", ",", " "];
1873
+ var DOMAIN_SEPARATION_REGEX = /[^\s,]+/g;
1874
+ var FLEXIBLE_DOMAIN_REGEX = /^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/;
1875
+ var VALID_DOMAIN_REGEX = /^(?:[a-zA-Z0-9-]{1,63}\.)+[a-zA-Z0-9-]{2,63}$/;
1876
+ var DOMAIN_VALIDATION_SCHEMA = yup.string().required(t("neetoForm.error.requiredField", {
1877
+ label: t("neetoForm.common.domain")
1878
+ })).test("verify domains", t("neetoForm.error.invalidDomain"), function (domain) {
1879
+ return VALID_DOMAIN_REGEX.test(domain);
1880
+ });
1881
+ var CUSTOM_STYLES = {
1882
+ input: assoc("overflow", "hidden"),
1883
+ multiValue: function multiValue(styles, _ref2) {
1884
+ var valid = _ref2.data.valid;
1885
+ return _objectSpread$6(_objectSpread$6({}, styles), {}, {
1886
+ border: valid ? STYLES.border["default"] : STYLES.border.error,
1887
+ color: valid ? STYLES.color["default"] : STYLES.color.error
1888
+ });
1889
+ }
1890
+ };
1891
+ var CUSTOM_COMPONENTS = {
1892
+ DropdownIndicator: null,
1893
+ MultiValueRemove: MultiValueRemove,
1894
+ ValueContainer: ValueContainer,
1895
+ ClearIndicator: ClearIndicator
1896
+ };
1897
+
1898
+ var removeDuplicateErrorMessages = pipe(filter(isNotNil), uniq, join(ERROR_MESSAGE_DELIMITER));
1899
+ var formatDomainInputOptions = function formatDomainInputOptions(domain) {
1900
+ var isValid;
1901
+ try {
1902
+ DOMAIN_VALIDATION_SCHEMA.validateSync(domain);
1903
+ isValid = true;
1904
+ } catch (_unused) {
1905
+ isValid = false;
1906
+ }
1907
+ return {
1908
+ label: domain,
1909
+ value: domain,
1910
+ valid: isValid
1911
+ };
1912
+ };
1913
+ var pruneDuplicates = pipe(pluck("value"), uniq, map(formatDomainInputOptions));
1914
+ var getValidDomains = function getValidDomains(domains) {
1915
+ return domains.filter(function (domain) {
1916
+ return domain === null || domain === void 0 ? void 0 : domain.valid;
1917
+ });
1918
+ };
1919
+ var getValidDomainsCount = function getValidDomainsCount(domains) {
1920
+ return getValidDomains(domains).length;
1921
+ };
1922
+ var formatErrorMessage = function formatErrorMessage(error) {
1923
+ if (typeof error === "string") return error;
1924
+ return removeDuplicateErrorMessages(error);
1925
+ };
1926
+
1927
+ var _excluded$2 = ["label", "value", "onChange", "error", "onBlur"];
1928
+ 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; }
1929
+ 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), true).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; }
1930
+ var MultiDomainInput = function MultiDomainInput(_ref) {
1931
+ var _ref$label = _ref.label,
1932
+ label = _ref$label === void 0 ? "" : _ref$label,
1933
+ _ref$value = _ref.value,
1934
+ value = _ref$value === void 0 ? [] : _ref$value,
1935
+ _ref$onChange = _ref.onChange,
1936
+ onChange = _ref$onChange === void 0 ? noop : _ref$onChange,
1937
+ _ref$error = _ref.error,
1938
+ error = _ref$error === void 0 ? "" : _ref$error,
1939
+ _ref$onBlur = _ref.onBlur,
1940
+ onBlur = _ref$onBlur === void 0 ? noop : _ref$onBlur,
1941
+ otherProps = _objectWithoutProperties(_ref, _excluded$2);
1942
+ var _useState = useState(""),
1943
+ _useState2 = _slicedToArray(_useState, 2),
1944
+ inputValue = _useState2[0],
1945
+ setInputValue = _useState2[1];
1946
+ var _useState3 = useState(false),
1947
+ _useState4 = _slicedToArray(_useState3, 2),
1948
+ isFocused = _useState4[0],
1949
+ setIsFocused = _useState4[1];
1950
+ var _useTranslation = useTranslation(),
1951
+ t = _useTranslation.t;
1952
+ var handleFilterDomains = function handleFilterDomains() {
1953
+ return onChange(getValidDomains(value));
1954
+ };
1955
+ var handleDomainChange = function handleDomainChange() {
1956
+ var inputValues = inputValue.match(DOMAIN_SEPARATION_REGEX) || [];
1957
+ var domainMatches = filter(test(FLEXIBLE_DOMAIN_REGEX), inputValues);
1958
+ var domains = domainMatches.map(formatDomainInputOptions);
1959
+ onChange(pruneDuplicates([].concat(_toConsumableArray(value), _toConsumableArray(domains))));
1960
+ setInputValue("");
1961
+ };
1962
+ var handleKeyDown = function handleKeyDown(event) {
1963
+ if (!inputValue) return;
1964
+ if (includes(event.key, DELIMITER_KEYS)) {
1965
+ handleDomainChange();
1966
+ event.preventDefault();
1967
+ event.stopPropagation();
1968
+ }
1969
+ };
1970
+ var onCreateOption = function onCreateOption(input) {
1971
+ var domain = formatDomainInputOptions(input);
1972
+ onChange(pruneDuplicates([].concat(_toConsumableArray(value), [domain])));
1973
+ };
1974
+ var handleBlur = function handleBlur(event) {
1975
+ inputValue ? handleDomainChange() : onBlur(event);
1976
+ setIsFocused(false);
1977
+ };
1978
+ var isFilterDomainsLinkVisible = value.length > getValidDomainsCount(value);
1979
+ return /*#__PURE__*/jsxs("div", {
1980
+ className: "neeto-ui-input__wrapper neeto-ui-email-input__wrapper",
1981
+ children: [/*#__PURE__*/jsx("div", {
1982
+ className: "neeto-ui-email-input__label-wrapper",
1983
+ children: /*#__PURE__*/jsx(Label, {
1984
+ className: "neeto-ui-email-input__label",
1985
+ "data-testid": "".concat(hyphenize(label), "-input-label"),
1986
+ children: label
1987
+ })
1988
+ }), /*#__PURE__*/jsx(CreatableSelect, _objectSpread$5({
1989
+ isMulti: true,
1990
+ required: true,
1991
+ classNamePrefix: "neeto-ui-react-select",
1992
+ components: CUSTOM_COMPONENTS,
1993
+ menuIsOpen: false,
1994
+ visibleDomainsCount: 3,
1995
+ className: classnames("neeto-ui-react-select__container neeto-ui-react-select__container--medium neeto-ui-email-input__select", {
1996
+ "neeto-ui-react-select__container--error": !!error
1997
+ }),
1998
+ styles: _objectSpread$5(_objectSpread$5({}, CUSTOM_STYLES), {}, {
1999
+ control: mergeLeft({
2000
+ maxHeight: "200px",
2001
+ overflowY: "auto"
2002
+ })
2003
+ }),
2004
+ onBlur: handleBlur,
2005
+ onFocus: function onFocus() {
2006
+ return setIsFocused(true);
2007
+ },
2008
+ onInputChange: setInputValue,
2009
+ onKeyDown: handleKeyDown
2010
+ }, _objectSpread$5({
2011
+ inputValue: inputValue,
2012
+ isFocused: isFocused,
2013
+ onChange: onChange,
2014
+ onCreateOption: onCreateOption,
2015
+ value: value
2016
+ }, otherProps))), !!error && /*#__PURE__*/jsxs("p", {
2017
+ className: "neeto-ui-input__error",
2018
+ "data-testid": "".concat(hyphenize(label), "-input-error"),
2019
+ children: [formatErrorMessage(error), isFilterDomainsLinkVisible && /*#__PURE__*/jsxs("span", {
2020
+ className: "neeto-ui-font-semibold cursor-pointer",
2021
+ onClick: handleFilterDomains,
2022
+ children: [ERROR_MESSAGE_DELIMITER, t("neetoForm.domainRestriction.removeInvalidDomains")]
2023
+ })]
2024
+ }), /*#__PURE__*/jsx("p", {
2025
+ className: "neeto-ui-input__help-text",
2026
+ "data-testid": "".concat(hyphenize(label), "-input-help"),
2027
+ children: t("neetoForm.domainRestriction.helpText")
2028
+ })]
2029
+ });
2030
+ };
2031
+
2032
+ 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; }
2033
+ 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), true).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; }
2034
+ var validateDomains = function validateDomains(value) {
2035
+ var schema = yup.array().of(yup.string().test("verify domains", t("neetoForm.error.invalidDomain"), function (domain) {
2036
+ return VALID_DOMAIN_REGEX.test(domain);
2037
+ })).ensure().compact().min(1, t("neetoForm.error.minOneEntity", {
2038
+ entity: t("neetoForm.common.domain")
2039
+ }));
2040
+
2041
+ // eslint-disable-next-line no-async-promise-executor
2042
+ return new Promise(/*#__PURE__*/function () {
2043
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve) {
2044
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
2045
+ while (1) switch (_context.prev = _context.next) {
2046
+ case 0:
2047
+ _context.prev = 0;
2048
+ _context.next = 3;
2049
+ return schema.validate(value);
2050
+ case 3:
2051
+ resolve(undefined);
2052
+ _context.next = 9;
2053
+ break;
2054
+ case 6:
2055
+ _context.prev = 6;
2056
+ _context.t0 = _context["catch"](0);
2057
+ resolve(_context.t0.message);
2058
+ case 9:
2059
+ case "end":
2060
+ return _context.stop();
2061
+ }
2062
+ }, _callee, null, [[0, 6]]);
2063
+ }));
2064
+ return function (_x) {
2065
+ return _ref.apply(this, arguments);
2066
+ };
2067
+ }());
2068
+ };
2069
+ var buildHelpPopoverLabelProps = function buildHelpPopoverLabelProps(popoverDescription, helpLink) {
2070
+ return {
2071
+ helpIconProps: {
2072
+ "data-testid": "help-popover-button",
2073
+ popoverProps: _objectSpread$4({
2074
+ description: popoverDescription
2075
+ }, helpLink && {
2076
+ helpLinkProps: {
2077
+ href: helpLink,
2078
+ label: t("neetoForm.common.viewHelpArticle")
2079
+ }
2080
+ })
2081
+ }
2082
+ };
2083
+ };
2084
+
2085
+ var EmailDomains = function EmailDomains(_ref) {
2086
+ var name = _ref.name,
2087
+ label = _ref.label;
2088
+ var _useTranslation = useTranslation(),
2089
+ t = _useTranslation.t;
2090
+ var _useField = useField({
2091
+ name: name,
2092
+ validate: validateDomains
2093
+ }),
2094
+ _useField2 = _slicedToArray(_useField, 3),
2095
+ _useField2$0$value = _useField2[0].value,
2096
+ domains = _useField2$0$value === void 0 ? [] : _useField2$0$value,
2097
+ meta = _useField2[1],
2098
+ _useField2$ = _useField2[2],
2099
+ setValue = _useField2$.setValue,
2100
+ setTouched = _useField2$.setTouched;
2101
+ var formattedDomains = map(formatDomainInputOptions, domains);
2102
+ return /*#__PURE__*/jsx("div", {
2103
+ className: "mb-4",
2104
+ children: /*#__PURE__*/jsx(MultiDomainInput, {
2105
+ label: label,
2106
+ name: name,
2107
+ error: meta.touched ? meta.error : "",
2108
+ placeholder: t("neetoForm.domainRestriction.placeholder"),
2109
+ value: formattedDomains,
2110
+ onBlur: function onBlur() {
2111
+ return setTouched(true);
2112
+ },
2113
+ onChange: function onChange(value) {
2114
+ return setValue(nullSafe(pluck)("value", value));
2115
+ }
2116
+ })
2117
+ });
2118
+ };
2119
+
2120
+ var RestrictDomainsBlock = function RestrictDomainsBlock(_ref) {
2121
+ var switchName = _ref.switchName,
2122
+ domainName = _ref.domainName,
2123
+ isDomainRestrictionEnabled = _ref.isDomainRestrictionEnabled;
2124
+ var _useBuildFormStore = useBuildFormStore(paths([["formState", "helpDocUrls", domainName], ["formState", "hostSpecificData", domainName]])),
2125
+ _useBuildFormStore2 = _slicedToArray(_useBuildFormStore, 2),
2126
+ helpLink = _useBuildFormStore2[0],
2127
+ hostSpecificTranslations = _useBuildFormStore2[1];
2128
+ var _mergeLeft = mergeLeft(hostSpecificTranslations, DOMAIN_RESTRICTION_TRANSLATIONS[domainName]),
2129
+ title = _mergeLeft.title,
2130
+ description = _mergeLeft.description,
2131
+ popoverDescription = _mergeLeft.popoverDescription;
2132
+ return /*#__PURE__*/jsxs("div", {
2133
+ className: "flex flex-col space-y-4",
2134
+ "data-testid": "".concat(hyphenate(switchName), "-container"),
2135
+ children: [/*#__PURE__*/jsx(SwitchBlock, {
2136
+ label: title,
2137
+ labelProps: buildHelpPopoverLabelProps(popoverDescription, helpLink),
2138
+ name: switchName
2139
+ }), isDomainRestrictionEnabled && /*#__PURE__*/jsx(EmailDomains, {
2140
+ label: description,
2141
+ name: domainName
2142
+ })]
2143
+ });
2144
+ };
2145
+
2146
+ var VerifyEmails = function VerifyEmails() {
2147
+ var _useBuildFormStore = useBuildFormStore(paths([["formState", "helpDocUrls", "emailVerification"], ["formState", "hostSpecificData", "emailVerification"]])),
2148
+ _useBuildFormStore2 = _slicedToArray(_useBuildFormStore, 2),
2149
+ helpLink = _useBuildFormStore2[0],
2150
+ hostSpecificTranslations = _useBuildFormStore2[1];
2151
+ var _mergeLeft = mergeLeft(hostSpecificTranslations, EMAIL_VERIFICATION_TRANSLATIONS),
2152
+ title = _mergeLeft.title,
2153
+ popoverDescription = _mergeLeft.popoverDescription;
2154
+ return /*#__PURE__*/jsx("div", {
2155
+ "data-testid": "email-verification-switch-container",
2156
+ children: /*#__PURE__*/jsx(Switch, {
2157
+ label: title,
2158
+ labelProps: buildHelpPopoverLabelProps(popoverDescription, helpLink),
2159
+ name: "isVerificationEnabled"
2160
+ })
2161
+ });
2162
+ };
2163
+
2164
+ var Email = function Email(_ref) {
2165
+ var usesCustomSubmissionComponent = _ref.usesCustomSubmissionComponent;
2166
+ var _useFormikContext = useFormikContext(),
2167
+ _useFormikContext$val = _useFormikContext.values,
2168
+ _useFormikContext$val2 = _useFormikContext$val.isDomainWhitelistingEnabled,
2169
+ isDomainWhitelistingEnabled = _useFormikContext$val2 === void 0 ? false : _useFormikContext$val2,
2170
+ _useFormikContext$val3 = _useFormikContext$val.isDomainBlacklistingEnabled,
2171
+ isDomainBlacklistingEnabled = _useFormikContext$val3 === void 0 ? false : _useFormikContext$val3;
2172
+ return /*#__PURE__*/jsx("div", {
2173
+ className: "flex flex-col space-y-4",
2174
+ children: !usesCustomSubmissionComponent && /*#__PURE__*/jsxs(Fragment, {
2175
+ children: [/*#__PURE__*/jsx(RestrictDomainsBlock, {
2176
+ domainName: "whitelistedDomains",
2177
+ isDomainRestrictionEnabled: isDomainWhitelistingEnabled,
2178
+ switchName: "isDomainWhitelistingEnabled"
2179
+ }), /*#__PURE__*/jsx(RestrictDomainsBlock, {
2180
+ domainName: "blacklistedDomains",
2181
+ isDomainRestrictionEnabled: isDomainBlacklistingEnabled,
2182
+ switchName: "isDomainBlacklistingEnabled"
2183
+ }), /*#__PURE__*/jsx(VerifyEmails, {})]
2184
+ })
2185
+ });
2186
+ };
2187
+
2188
+ var FileGroup = function FileGroup(_ref) {
2189
+ var name = _ref.name,
2190
+ label = _ref.label,
2191
+ checked = _ref.checked,
2192
+ handleAllowedFileTypesChange = _ref.handleAllowedFileTypesChange;
2193
+ return /*#__PURE__*/jsx(Checkbox, {
2194
+ checked: checked,
2195
+ label: label,
2196
+ name: name,
2197
+ "data-testid": "neeto-form-engine-file-type-".concat(name),
2198
+ id: name,
2199
+ onChange: handleAllowedFileTypesChange
2200
+ });
2201
+ };
2202
+
2203
+ var buildFileTypesList = function buildFileTypesList(fileTypes) {
2204
+ return (fileTypes !== null && fileTypes !== void 0 ? fileTypes : "").split(", ");
2205
+ };
2206
+ var getAllowedFileTypes = function getAllowedFileTypes(_ref) {
2207
+ var type = _ref.type,
2208
+ isChecked = _ref.isChecked,
2209
+ allowedFileTypes = _ref.allowedFileTypes;
2210
+ var fileTypes = buildFileTypesList(allowedFileTypes);
2211
+ if (isChecked) {
2212
+ var fileTypesSet = new Set([].concat(_toConsumableArray(FILE_TYPES_MAP[type]), _toConsumableArray(fileTypes)));
2213
+ return Array.from(fileTypesSet).join(", ");
2214
+ }
2215
+ var newFileTypes = difference(fileTypes, FILE_TYPES_MAP[type]);
2216
+ return newFileTypes.join(", ");
2217
+ };
2218
+ var isFileTypeEnabled = function isFileTypeEnabled(type, allowedFileTypes) {
2219
+ var fileTypes = buildFileTypesList(allowedFileTypes);
2220
+ return isEmpty(difference(FILE_TYPES_MAP[type], fileTypes));
2221
+ };
2222
+
2223
+ var FileUpload = function FileUpload() {
2224
+ var _useTranslation = useTranslation(),
2225
+ t = _useTranslation.t;
2226
+ var _useFormikContext = useFormikContext(),
2227
+ values = _useFormikContext.values,
2228
+ setFieldValue = _useFormikContext.setFieldValue;
2229
+ var allowedFileTypes = prop("allowedFileTypes", values);
2230
+ var handleAllowedFileTypesChange = function handleAllowedFileTypesChange(_ref) {
2231
+ var _ref$target = _ref.target,
2232
+ fileType = _ref$target.name,
2233
+ checked = _ref$target.checked;
2234
+ return setFieldValue("allowedFileTypes", getAllowedFileTypes({
2235
+ type: fileType,
2236
+ isChecked: checked,
2237
+ allowedFileTypes: allowedFileTypes
2238
+ }));
2239
+ };
2240
+ return /*#__PURE__*/jsxs(Fragment, {
2241
+ children: [/*#__PURE__*/jsx("div", {
2242
+ className: "w-full",
2243
+ children: /*#__PURE__*/jsx(Checkbox$1, {
2244
+ id: "multipleFilesAllowed",
2245
+ label: t("neetoForm.fileUpload.enableMultipleFilesUpload"),
2246
+ name: "multipleFilesAllowed"
2247
+ })
2248
+ }), /*#__PURE__*/jsxs("div", {
2249
+ className: "flex flex-col space-y-3",
2250
+ children: [/*#__PURE__*/jsx(Typography, {
2251
+ style: "body1",
2252
+ weight: "semibold",
2253
+ children: t("neetoForm.fileUpload.fileTypes")
2254
+ }), /*#__PURE__*/jsx("div", {
2255
+ className: "flex space-x-4",
2256
+ children: FILE_GROUPS.map(function (_ref2) {
2257
+ var name = _ref2.name,
2258
+ label = _ref2.label;
2259
+ return /*#__PURE__*/createElement(FileGroup, {
2260
+ handleAllowedFileTypesChange: handleAllowedFileTypesChange,
2261
+ label: label,
2262
+ name: name,
2263
+ checked: isFileTypeEnabled(name, allowedFileTypes),
2264
+ key: name
2265
+ });
2266
+ })
2267
+ })]
2268
+ })]
2269
+ });
2270
+ };
2271
+
2272
+ var OpinionScale = function OpinionScale() {
2273
+ var _useTranslation = useTranslation(),
2274
+ t = _useTranslation.t;
2275
+ var _useFormikContext = useFormikContext(),
2276
+ setFieldValue = _useFormikContext.setFieldValue,
2277
+ _useFormikContext$val = _useFormikContext.values.hasOpinionLabels,
2278
+ hasOpinionLabels = _useFormikContext$val === void 0 ? false : _useFormikContext$val;
2279
+ return /*#__PURE__*/jsxs(Fragment, {
2280
+ children: [/*#__PURE__*/jsxs("div", {
2281
+ className: "flex space-x-4",
2282
+ children: [/*#__PURE__*/jsx(Select, {
2283
+ className: "w-1/2",
2284
+ "data-testid": "neeto-form-engine-opinion-scale-min-value",
2285
+ label: t("neetoForm.common.start"),
2286
+ name: "minValue",
2287
+ options: OPINION_SCALE_MIN_VALUE_OPTIONS,
2288
+ onChange: function onChange(option) {
2289
+ return setFieldValue("minValue", option === null || option === void 0 ? void 0 : option.value);
2290
+ }
2291
+ }), /*#__PURE__*/jsx(Select, {
2292
+ className: "w-1/2",
2293
+ "data-testid": "neeto-form-engine-opinion-scale-max-value",
2294
+ label: t("neetoForm.common.end"),
2295
+ name: "maxValue",
2296
+ options: OPINION_SCALE_MAX_VALUE_OPTIONS,
2297
+ onChange: function onChange(option) {
2298
+ return setFieldValue("maxValue", option === null || option === void 0 ? void 0 : option.value);
2299
+ }
2300
+ })]
2301
+ }), /*#__PURE__*/jsx(Switch, {
2302
+ "data-testid": "neeto-form-engine-opinion-scale-show-labels-switch",
2303
+ label: t("neetoForm.questions.opinionScale.showLabels"),
2304
+ name: "hasOpinionLabels"
2305
+ }), hasOpinionLabels && /*#__PURE__*/jsxs("div", {
2306
+ className: "flex space-x-4",
2307
+ children: [/*#__PURE__*/jsx(Input, {
2308
+ className: "w-1/2",
2309
+ "data-testid": "neeto-form-engine-opinion-scale-left-label",
2310
+ label: t("neetoForm.questions.opinionScale.leftLabel"),
2311
+ maxLength: OPINION_LABEL_MAX_LENGTH,
2312
+ name: "leftOpinionLabel"
2313
+ }), /*#__PURE__*/jsx(Input, {
2314
+ className: "w-1/2",
2315
+ "data-testid": "neeto-form-engine-opinion-scale-right-label",
2316
+ label: t("neetoForm.questions.opinionScale.rightLabel"),
2317
+ maxLength: OPINION_LABEL_MAX_LENGTH,
2318
+ name: "rightOpinionLabel"
2319
+ })]
2320
+ })]
2321
+ });
2322
+ };
2323
+
2324
+ 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; }
2325
+ 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), true).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; }
2326
+ var Options = function Options(_ref) {
2327
+ var questionProps = _ref.questionProps;
2328
+ var _useTranslation = useTranslation(),
2329
+ t = _useTranslation.t;
2330
+ var _useBuildFormStore = useBuildFormStore(function (store) {
2331
+ var _store$formState, _store$formState2;
2332
+ return {
2333
+ selectedLanguage: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["selectedLanguage"],
2334
+ isPictureChoiceEnabled: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["isPictureChoiceEnabled"]
2335
+ };
2336
+ }, shallow),
2337
+ selectedLanguage = _useBuildFormStore.selectedLanguage,
2338
+ isPictureChoiceEnabled = _useBuildFormStore.isPictureChoiceEnabled;
2339
+ var bulkAddHelpDocUrl = useHelpDoc("bulkAddOptions");
2340
+ var _useFormikContext = useFormikContext(),
2341
+ values = _useFormikContext.values,
2342
+ setFieldValue = _useFormikContext.setFieldValue;
2343
+ var name = "optionsAttributes";
2344
+ var _useField = useField(name),
2345
+ _useField2 = _slicedToArray(_useField, 3);
2346
+ _useField2[0];
2347
+ _useField2[1];
2348
+ var setOptionsAttributes = _useField2[2].setValue;
2349
+ var _ref2 = questionProps || {},
2350
+ _ref2$optionLabelProp = _ref2.optionLabelProps,
2351
+ optionLabelProps = _ref2$optionLabelProp === void 0 ? {} : _ref2$optionLabelProp,
2352
+ _ref2$freezeOptions = _ref2.freezeOptions,
2353
+ freezeOptions = _ref2$freezeOptions === void 0 ? false : _ref2$freezeOptions,
2354
+ _ref2$disableAddOptio = _ref2.disableAddOption,
2355
+ disableAddOption = _ref2$disableAddOptio === void 0 ? false : _ref2$disableAddOptio,
2356
+ _ref2$disableRemoveOp = _ref2.disableRemoveOption,
2357
+ disableRemoveOption = _ref2$disableRemoveOp === void 0 ? false : _ref2$disableRemoveOp;
2358
+ var isManageOptionDisabled = isFunction(freezeOptions) ? freezeOptions(selectedLanguage) : freezeOptions;
2359
+ var isAddOptionDisabled = disableAddOption || isManageOptionDisabled;
2360
+ var isRemoveOptionDisabled = disableRemoveOption || isManageOptionDisabled;
2361
+ var isDropdown = values.kind === QUESTION_TYPES.DROPDOWN;
2362
+ var isPictureChoice = isPictureChoiceEnabled && !isDropdown && (values.isPictureChoice || DEFAULT_CHOICE_QUESTION_ATTRIBUTES.isPictureChoice);
2363
+ var imageHeight = values.imageHeight || DEFAULT_CHOICE_QUESTION_ATTRIBUTES.imageHeight;
2364
+ var handleImageHeightChange = function handleImageHeightChange(value) {
2365
+ setFieldValue("imageHeight", value);
2366
+ };
2367
+ return /*#__PURE__*/jsxs("div", {
2368
+ className: "w-full space-y-4",
2369
+ children: [/*#__PURE__*/jsxs("div", {
2370
+ children: [/*#__PURE__*/jsx(Label, _objectSpread$3(_objectSpread$3({
2371
+ className: "mb-2 block"
2372
+ }, optionLabelProps), {}, {
2373
+ children: t("neetoForm.questions.common.questionFields.field.options")
2374
+ })), /*#__PURE__*/jsx("div", {
2375
+ className: classnames(["neeto-form-engine-fields-wrapper", {
2376
+ "neeto-form-engine-fields-wrapper--fit-image": values.shouldFitImages
2377
+ }]),
2378
+ style: {
2379
+ "--neeto-form-engine-picture-choice-image-height": "".concat(values.imageHeight, "px")
2380
+ },
2381
+ children: /*#__PURE__*/jsx(OptionFields, {
2382
+ isPictureChoice: isPictureChoice,
2383
+ name: name,
2384
+ shouldDestroy: true,
2385
+ bulkActionProps: {
2386
+ enabled: true,
2387
+ bulkAddHelpDocUrl: bulkAddHelpDocUrl
2388
+ },
2389
+ destroyFlagName: "_destroy",
2390
+ disabled: isManageOptionDisabled,
2391
+ draggable: !isManageOptionDisabled,
2392
+ isAddOptionEnabled: !isAddOptionDisabled,
2393
+ isDeleteOptionEnabled: !isRemoveOptionDisabled,
2394
+ isNewItemsPrefilled: isDefaultLanguage(selectedLanguage),
2395
+ minOptions: MINIMUM_OPTIONS,
2396
+ shouldResetEmptyOptionOnBlur: false,
2397
+ onChange: setOptionsAttributes
2398
+ })
2399
+ })]
2400
+ }), !isDropdown && isPictureChoiceEnabled && /*#__PURE__*/jsxs(Block, {
2401
+ title: t("neetoForm.questions.common.questionFields.field.pictureChoiceSettings"),
2402
+ children: [/*#__PURE__*/jsx(Switch, {
2403
+ name: "isPictureChoice",
2404
+ label: t("neetoForm.questions.common.questionFields.field.addPicturesToOptions")
2405
+ }), isPictureChoice && /*#__PURE__*/jsxs(Fragment, {
2406
+ children: [/*#__PURE__*/jsx(Switch, {
2407
+ name: "shouldFitImages",
2408
+ label: t("neetoForm.questions.common.questionFields.field.fitImages"),
2409
+ labelProps: {
2410
+ helpIconProps: {
2411
+ "data-testid": "fit-images-help-popover-button",
2412
+ popoverProps: {
2413
+ position: "top",
2414
+ description: t("neetoForm.questions.common.questionFields.field.fitImagesHelpDescription")
2415
+ }
2416
+ }
2417
+ }
2418
+ }), /*#__PURE__*/jsxs("div", {
2419
+ className: "mt-4",
2420
+ children: [/*#__PURE__*/jsx(Typography, {
2421
+ style: "body2",
2422
+ weight: "medium",
2423
+ children: t("neetoForm.questions.common.questionFields.field.imageHeight")
2424
+ }), /*#__PURE__*/jsx(Slider, {
2425
+ max: IMAGE_HEIGHT_SLIDER_DEFAULTS.max,
2426
+ min: IMAGE_HEIGHT_SLIDER_DEFAULTS.min,
2427
+ value: imageHeight,
2428
+ onChange: handleImageHeightChange
2429
+ })]
2430
+ })]
2431
+ })]
2432
+ })]
2433
+ });
2434
+ };
2435
+
2436
+ var RatingItem = function RatingItem(_ref) {
2437
+ var children = _ref.children;
2438
+ return /*#__PURE__*/jsx("div", {
2439
+ className: "flex w-16 flex-col items-center gap-3",
2440
+ children: children
2441
+ });
2442
+ };
2443
+ var Rating = function Rating() {
2444
+ return /*#__PURE__*/jsx("div", {
2445
+ className: "flex flex-col",
2446
+ children: /*#__PURE__*/jsx("div", {
2447
+ className: "w-full",
2448
+ children: /*#__PURE__*/jsx("div", {
2449
+ className: "flex gap-6",
2450
+ children: RATING_OPTIONS.map(function (_ref2) {
2451
+ var Icon = _ref2.icon,
2452
+ name = _ref2.name,
2453
+ color = _ref2.color;
2454
+ return /*#__PURE__*/jsxs(RatingItem, {
2455
+ children: [/*#__PURE__*/jsx(Icon, {
2456
+ color: color,
2457
+ size: 48
2458
+ }), /*#__PURE__*/jsx(InputWithMaxLength, {
2459
+ name: name,
2460
+ "data-testid": "neeto-form-engine-".concat(hyphenate(name))
2461
+ })]
2462
+ }, name);
2463
+ })
2464
+ })
2465
+ })
2466
+ });
2467
+ };
2468
+
2469
+ var StarRating = function StarRating() {
2470
+ var _useTranslation = useTranslation(),
2471
+ t = _useTranslation.t;
2472
+ var _useFormikContext = useFormikContext(),
2473
+ setFieldValue = _useFormikContext.setFieldValue;
2474
+ var _useField = useField("iconType"),
2475
+ _useField2 = _slicedToArray(_useField, 3),
2476
+ iconType = _useField2[0].value;
2477
+ _useField2[1];
2478
+ var setIconType = _useField2[2].setValue;
2479
+ return /*#__PURE__*/jsxs(Fragment, {
2480
+ children: [/*#__PURE__*/jsxs("div", {
2481
+ className: "flex space-x-4",
2482
+ children: [/*#__PURE__*/jsx(Select, {
2483
+ className: "w-1/2",
2484
+ "data-testid": "neeto-form-engine-star-rating-min-value",
2485
+ label: t("neetoForm.common.start"),
2486
+ name: "minValue",
2487
+ options: STAR_RATING_MIN_VALUE_OPTIONS,
2488
+ onChange: function onChange(option) {
2489
+ return setFieldValue("minValue", option === null || option === void 0 ? void 0 : option.value);
2490
+ }
2491
+ }), /*#__PURE__*/jsx(Select, {
2492
+ className: "w-1/2",
2493
+ "data-testid": "neeto-form-engine-star-rating-max-value",
2494
+ label: t("neetoForm.common.end"),
2495
+ name: "maxValue",
2496
+ options: STAR_RATING_MAX_VALUE_OPTIONS,
2497
+ onChange: function onChange(option) {
2498
+ return setFieldValue("maxValue", option === null || option === void 0 ? void 0 : option.value);
2499
+ }
2500
+ })]
2501
+ }), /*#__PURE__*/jsx(Label, {
2502
+ children: t("neetoForm.common.shape")
2503
+ }), /*#__PURE__*/jsx("div", {
2504
+ className: "flex gap-2",
2505
+ children: Object.entries(STAR_RATING_ICONS_MAP).map(function (_ref) {
2506
+ var _ref2 = _slicedToArray(_ref, 2),
2507
+ name = _ref2[0],
2508
+ IconType = _ref2[1];
2509
+ var isActive = name === iconType;
2510
+ return /*#__PURE__*/jsx("div", {
2511
+ "data-testid": "neeto-form-engine-star-rating-icon-".concat(name),
2512
+ 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", {
2513
+ "neeto-ui-text-gray-800 neeto-ui-bg-gray-200": !isActive,
2514
+ "neeto-ui-text-white neeto-ui-bg-gray-800": isActive
2515
+ }),
2516
+ onClick: function onClick() {
2517
+ return setIconType(name);
2518
+ },
2519
+ children: /*#__PURE__*/jsx(IconType, {})
2520
+ }, name);
2521
+ })
2522
+ })]
2523
+ });
2524
+ };
2525
+
2526
+ var _excluded$1 = ["fields"];
2527
+ 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; }
2528
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2529
+ var CHECKBOX = QUESTION_TYPES.CHECKBOX,
2530
+ RADIO = QUESTION_TYPES.RADIO,
2531
+ DROPDOWN = QUESTION_TYPES.DROPDOWN,
2532
+ STAR_RATING = QUESTION_TYPES.STAR_RATING,
2533
+ OPINION_SCALE = QUESTION_TYPES.OPINION_SCALE,
2534
+ RATING = QUESTION_TYPES.RATING,
2535
+ FILE_UPLOAD = QUESTION_TYPES.FILE_UPLOAD,
2536
+ CAPTCHA = QUESTION_TYPES.CAPTCHA,
2537
+ EMAIL = QUESTION_TYPES.EMAIL,
2538
+ ADDRESS = QUESTION_TYPES.ADDRESS;
2539
+ var transformValueForOption = function transformValueForOption(_ref) {
2540
+ var label = _ref.label,
2541
+ type = _ref.type;
2542
+ return "".concat(slugify(label), "-").concat(type);
2543
+ };
2544
+ var omitDraftId = modifyBy({
2545
+ id: startsWith(DRAFT_ID_PREFIX)
2546
+ }, omit(["id"]));
2547
+ var renderAdditionalData = function renderAdditionalData(_ref2) {
2548
+ var kind = _ref2.kind,
2549
+ questionProps = _ref2.questionProps,
2550
+ usesCustomSubmissionComponent = _ref2.usesCustomSubmissionComponent;
2551
+ switch (kind) {
2552
+ case CHECKBOX:
2553
+ case RADIO:
2554
+ case DROPDOWN:
2555
+ return /*#__PURE__*/jsx(Options, {
2556
+ questionProps: questionProps
2557
+ });
2558
+ case RATING:
2559
+ return /*#__PURE__*/jsx(Rating, {});
2560
+ case STAR_RATING:
2561
+ return /*#__PURE__*/jsx(StarRating, {});
2562
+ case OPINION_SCALE:
2563
+ return /*#__PURE__*/jsx(OpinionScale, {});
2564
+ case FILE_UPLOAD:
2565
+ return /*#__PURE__*/jsx(FileUpload, {});
2566
+ case CAPTCHA:
2567
+ return /*#__PURE__*/jsx(Captcha, {});
2568
+ case ADDRESS:
2569
+ return /*#__PURE__*/jsx(Address, {});
2570
+ case EMAIL:
2571
+ return !usesCustomSubmissionComponent && /*#__PURE__*/jsx(Email, {
2572
+ usesCustomSubmissionComponent: usesCustomSubmissionComponent
2573
+ });
2574
+ default:
2575
+ return null;
2576
+ }
2577
+ };
2578
+ var resolveActionComponent = function resolveActionComponent(action) {
2579
+ return equals(action, QUESTION_ACTIONS.ADD) ? Add : Edit;
2580
+ };
2581
+ var getQuestionKind = function getQuestionKind(questionKinds, pattern) {
2582
+ var questionKind = findBy(pattern, questionKinds);
2583
+ return questionKind ? assoc("kind", questionKind.type, questionKind) : null;
2584
+ };
2585
+ var buildKindOptions = function buildKindOptions(kinds) {
2586
+ return kinds.map(function (_ref3) {
2587
+ var label = _ref3.label,
2588
+ type = _ref3.type;
2589
+ return {
2590
+ label: label,
2591
+ value: transformValueForOption({
2592
+ label: label,
2593
+ type: type
2594
+ })
2595
+ };
2596
+ });
2597
+ };
2598
+ var extractKindFromOption = pipe(split("-"), last);
2599
+ var buildDefaultValueForKind = function buildDefaultValueForKind(questionKind) {
2600
+ return isPresent(questionKind) ? {
2601
+ value: transformValueForOption(questionKind)
2602
+ } : undefined;
2603
+ };
2604
+ var hideSwitchLabelProps = function hideSwitchLabelProps(helpUrl) {
2605
+ return helpUrl ? {
2606
+ helpIconProps: {
2607
+ "data-testid": "help-popover-button",
2608
+ popoverProps: {
2609
+ description: t("neetoForm.questions.common.questionFields.field.hideQuestionHelpDescription"),
2610
+ helpLinkProps: {
2611
+ href: helpUrl,
2612
+ label: t("neetoForm.common.viewHelpArticle")
2613
+ }
2614
+ }
2615
+ }
2616
+ } : undefined;
2617
+ };
2618
+ var responseVisibleOnlyToHostSwitchLabelProps = function responseVisibleOnlyToHostSwitchLabelProps(helpUrl) {
2619
+ return {
2620
+ helpIconProps: {
2621
+ "data-testid": "help-popover-button",
2622
+ popoverProps: {
2623
+ description: t("neetoForm.questions.common.questionFields.field.responseVisibleOnlyToHostHelpDescription"),
2624
+ helpLinkProps: {
2625
+ href: helpUrl,
2626
+ label: t("neetoForm.common.viewHelpArticle")
2627
+ }
2628
+ }
2629
+ }
2630
+ };
2631
+ };
2632
+ var readOnlySwitchLabelProps = function readOnlySwitchLabelProps(helpUrl) {
2633
+ return {
2634
+ helpIconProps: {
2635
+ "data-testid": "help-popover-button",
2636
+ popoverProps: {
2637
+ description: t("neetoForm.questions.common.questionFields.field.readOnlyHelpDescription"),
2638
+ helpLinkProps: helpUrl ? {
2639
+ href: helpUrl,
2640
+ label: t("neetoForm.common.viewHelpArticle")
2641
+ } : undefined
2642
+ }
2643
+ }
2644
+ };
2645
+ };
2646
+ var transformValues = function transformValues(values) {
2647
+ switch (values.kind) {
2648
+ case QUESTION_TYPES.ADDRESS:
2649
+ {
2650
+ var _values$fields = values.fields,
2651
+ fields = _values$fields === void 0 ? [] : _values$fields,
2652
+ rest = _objectWithoutProperties(values, _excluded$1);
2653
+ return _objectSpread$2(_objectSpread$2({}, rest), {}, {
2654
+ fieldsAttributes: map(renameKey("deleted", "_destroy"), omitDraftId(fields))
2655
+ });
2656
+ }
2657
+ default:
2658
+ return values;
2659
+ }
2660
+ };
2661
+
2662
+ var _excluded = ["isOpen", "onClose", "action", "question", "availableQuestionKinds"];
2663
+ 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; }
2664
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2665
+ var ManageQuestionPane = function ManageQuestionPane(_ref) {
2666
+ var isOpen = _ref.isOpen,
2667
+ onClose = _ref.onClose,
2668
+ action = _ref.action,
2669
+ question = _ref.question,
2670
+ availableQuestionKinds = _ref.availableQuestionKinds,
2671
+ props = _objectWithoutProperties(_ref, _excluded);
2672
+ var initialFocusRef = useRef(null);
2673
+ var Component = resolveActionComponent(action);
2674
+ return /*#__PURE__*/jsx(Pane, {
2675
+ initialFocusRef: initialFocusRef,
2676
+ isOpen: isOpen,
2677
+ onClose: onClose,
2678
+ children: /*#__PURE__*/jsx(Component, _objectSpread$1({}, _objectSpread$1({
2679
+ availableQuestionKinds: availableQuestionKinds,
2680
+ initialFocusRef: initialFocusRef,
2681
+ isOpen: isOpen,
2682
+ onClose: onClose,
2683
+ question: question
2684
+ }, props)))
2685
+ });
2686
+ };
2687
+
2688
+ 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; }
2689
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2690
+ var AddQuestion = function AddQuestion(_ref) {
2691
+ var onAdd = _ref.onAdd,
2692
+ disabledAddButtonHelpPopoverProps = _ref.disabledAddButtonHelpPopoverProps,
2693
+ isDisabled = _ref.isDisabled,
2694
+ addQuestionHelpProps = _ref.addQuestionHelpProps;
2695
+ var helpPopoverProps = isDisabled ? buildDisabledAddButtonHelpPopoverProps(disabledAddButtonHelpPopoverProps) : {};
2696
+ return /*#__PURE__*/jsxs("div", {
2697
+ className: "mb-8 flex w-full items-center gap-x-1",
2698
+ children: [/*#__PURE__*/jsx(Button, _objectSpread({}, buildAddQuestionButtonProps(onAdd, isDisabled))), isDisabled && /*#__PURE__*/jsx(HelpPopover, _objectSpread({}, helpPopoverProps)), isPresent(addQuestionHelpProps) && !isDisabled && /*#__PURE__*/jsx("span", {
2699
+ children: /*#__PURE__*/jsx(HelpPopover, _objectSpread({}, addQuestionHelpProps))
2700
+ })]
2701
+ });
2702
+ };
2703
+
2704
+ var Form = function Form(_ref) {
2705
+ var questionKinds = _ref.questionKinds,
2706
+ onValueChange = _ref.onValueChange,
2707
+ formId = _ref.formId,
2708
+ isDeletable = _ref.isDeletable,
2709
+ isRequiredField = _ref.isRequiredField,
2710
+ isKindAlreadyActive = _ref.isKindAlreadyActive,
2711
+ getActiveKindDetails = _ref.getActiveKindDetails,
2712
+ isDisabledFieldLabel = _ref.isDisabledFieldLabel,
2713
+ disabledAddButtonHelpPopoverProps = _ref.disabledAddButtonHelpPopoverProps,
2714
+ isFormEnabled = _ref.isFormEnabled,
2715
+ canManageQuestions = _ref.canManageQuestions,
2716
+ savedTitle = _ref.savedTitle,
2717
+ formTitle = _ref.formTitle,
2718
+ formDescription = _ref.formDescription,
2719
+ selectedLanguage = _ref.selectedLanguage,
2720
+ availableLanguages = _ref.availableLanguages,
2721
+ onLanguageChange = _ref.onLanguageChange,
2722
+ additionalActionOptions = _ref.additionalActionOptions,
2723
+ kindUniqueOn = _ref.kindUniqueOn,
2724
+ helpDocUrls = _ref.helpDocUrls,
2725
+ hostSpecificData = _ref.hostSpecificData,
2726
+ addQuestionHelpProps = _ref.addQuestionHelpProps,
2727
+ isUsingDefaultQuestionKinds = _ref.isUsingDefaultQuestionKinds,
2728
+ usesCustomSubmissionComponent = _ref.usesCustomSubmissionComponent,
2729
+ questionsFromCache = _ref.questionsFromCache,
2730
+ onMutateSuccess = _ref.onMutateSuccess,
2731
+ advancedFeatures = _ref.advancedFeatures,
2732
+ isPictureChoiceEnabled = _ref.isPictureChoiceEnabled;
2733
+ var containerRef = useRef();
2734
+ var _useStateWithDependen = useStateWithDependency(questionsFromCache),
2735
+ _useStateWithDependen2 = _slicedToArray(_useStateWithDependen, 2),
2736
+ questions = _useStateWithDependen2[0],
2737
+ setQuestions = _useStateWithDependen2[1];
2738
+ var _useState = useState({}),
2739
+ _useState2 = _slicedToArray(_useState, 2),
2740
+ selectedQuestion = _useState2[0],
2741
+ setSelectedQuestion = _useState2[1];
2742
+ var _useState3 = useState(""),
2743
+ _useState4 = _slicedToArray(_useState3, 2),
2744
+ selectedAction = _useState4[0],
2745
+ setSelectedAction = _useState4[1];
2746
+ var _useState5 = useState(false),
2747
+ _useState6 = _slicedToArray(_useState5, 2),
2748
+ isDeleteAlertOpen = _useState6[0],
2749
+ setIsDeleteAlertOpen = _useState6[1];
2750
+ var _useState7 = useState(false),
2751
+ _useState8 = _slicedToArray(_useState7, 2),
2752
+ isDeleteSmsReminderModalOpen = _useState8[0],
2753
+ setIsDeleteSmsReminderModalOpen = _useState8[1];
2754
+ var _useState9 = useState(false),
2755
+ _useState10 = _slicedToArray(_useState9, 2),
2756
+ isDeleteSpotModalOpen = _useState10[0],
2757
+ setIsDeleteSpotModalOpen = _useState10[1];
2758
+ var _useState11 = useState(false),
2759
+ _useState12 = _slicedToArray(_useState11, 2),
2760
+ isManageQuestionPaneOpen = _useState12[0],
2761
+ setIsManageQuestionPaneOpen = _useState12[1];
2762
+ var setFormData = useBuildFormStore(prop("setFormData"));
2763
+ var _useCreateQuestion = useCreateQuestion(formId, selectedLanguage, {
2764
+ onSuccess: function onSuccess() {
2765
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2766
+ args[_key] = arguments[_key];
2767
+ }
2768
+ onMutateSuccess === null || onMutateSuccess === void 0 || onMutateSuccess.apply(void 0, [QUESTION_ACTIONS.CLONE].concat(args));
2769
+ showThumbsUpToastr();
2770
+ }
2771
+ }),
2772
+ createQuestion = _useCreateQuestion.mutate;
2773
+ var _useReorderQuestions = useReorderQuestions(formId, selectedLanguage, {
2774
+ onSuccess: function onSuccess() {
2775
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2776
+ args[_key2] = arguments[_key2];
2777
+ }
2778
+ onMutateSuccess === null || onMutateSuccess === void 0 || onMutateSuccess.apply(void 0, [QUESTION_ACTIONS.REORDER].concat(args));
2779
+ setFormData({
2780
+ isReorderingQuestions: false
2781
+ });
2782
+ }
2783
+ }),
2784
+ reorderQuestions = _useReorderQuestions.mutate;
2785
+ var debouncedReorderQuestions = useFuncDebounce(reorderQuestions, 1000);
2786
+ var handleReorder = function handleReorder(questions) {
2787
+ var payload = {
2788
+ neetoFormQuestions: {
2789
+ questions: buildReorderPayload(questions)
2790
+ },
2791
+ language: selectedLanguage
2792
+ };
2793
+ setFormData({
2794
+ isReorderingQuestions: true
2795
+ });
2796
+ debouncedReorderQuestions(payload);
2797
+ };
2798
+ useEffect(function () {
2799
+ setFormData({
2800
+ formId: formId,
2801
+ enabled: isFormEnabled,
2802
+ title: savedTitle,
2803
+ selectedLanguage: selectedLanguage,
2804
+ helpDocUrls: helpDocUrls,
2805
+ isUsingDefaultQuestionKinds: isUsingDefaultQuestionKinds,
2806
+ usesCustomSubmissionComponent: usesCustomSubmissionComponent,
2807
+ hostSpecificData: hostSpecificData,
2808
+ onMutateSuccess: onMutateSuccess,
2809
+ advancedFeatures: advancedFeatures,
2810
+ onLanguageChange: onLanguageChange,
2811
+ isPictureChoiceEnabled: isPictureChoiceEnabled
2812
+ });
2813
+ }, [formId, isFormEnabled, savedTitle, setFormData, selectedLanguage, helpDocUrls, isUsingDefaultQuestionKinds, usesCustomSubmissionComponent, hostSpecificData, onMutateSuccess, advancedFeatures, onLanguageChange, isPictureChoiceEnabled]);
2814
+ var handleSelect = function handleSelect(question) {
2815
+ setSelectedQuestion(question);
2816
+ };
2817
+ var handleAdd = function handleAdd() {
2818
+ setSelectedAction(QUESTION_ACTIONS.ADD);
2819
+ setIsManageQuestionPaneOpen(true);
2820
+ };
2821
+ var handleEdit = function handleEdit() {
2822
+ setSelectedAction(QUESTION_ACTIONS.EDIT);
2823
+ setIsManageQuestionPaneOpen(true);
2824
+ };
2825
+ var handleClone = function handleClone() {
2826
+ var values = duplicateFieldData({
2827
+ item: selectedQuestion,
2828
+ questionKinds: availableQuestionKinds,
2829
+ questions: questions
2830
+ });
2831
+ var displayOrder = selectedQuestion.displayOrder + 1;
2832
+ var attributes = mergeLeft({
2833
+ displayOrder: displayOrder
2834
+ }, values);
2835
+ var payload = {
2836
+ language: selectedLanguage,
2837
+ neetoFormQuestion: formatQuestionAttributesForClone(attributes)
2838
+ };
2839
+ createQuestion(payload, {
2840
+ onSuccess: function onSuccess(_ref2) {
2841
+ var questions = _ref2.questions;
2842
+ var newQuestion = findBy({
2843
+ displayOrder: displayOrder
2844
+ }, questions);
2845
+ handleSelect(newQuestion);
2846
+ }
2847
+ });
2848
+ };
2849
+ var handleDelete = function handleDelete(question) {
2850
+ if (question.kind === QUESTION_TYPES.SMS_REMINDER) {
2851
+ setIsDeleteSmsReminderModalOpen(true);
2852
+ } else if (question.kind === QUESTION_TYPES.SPOT) {
2853
+ setIsDeleteSpotModalOpen(true);
2854
+ } else {
2855
+ setIsDeleteAlertOpen(true);
2856
+ }
2857
+ };
2858
+ useOnClickOutside(containerRef, function () {
2859
+ return handleSelect({});
2860
+ }, {
2861
+ enabled: !(isDeleteAlertOpen || isManageQuestionPaneOpen || isDeleteSmsReminderModalOpen || isDeleteSpotModalOpen)
2862
+ });
2863
+ useEffect(function () {
2864
+ onValueChange === null || onValueChange === void 0 || onValueChange(questions);
2865
+ }, [questions]);
2866
+ var availableQuestionKinds = getAvailableQuestionKinds({
2867
+ allQuestionKinds: questionKinds,
2868
+ activeQuestions: questions,
2869
+ isKindAlreadyActive: isKindAlreadyActive
2870
+ });
2871
+ return /*#__PURE__*/jsxs(Fragment, {
2872
+ children: [/*#__PURE__*/jsx(DeleteAlert, {
2873
+ handleSelect: handleSelect,
2874
+ selectedQuestion: selectedQuestion,
2875
+ isOpen: isDeleteAlertOpen,
2876
+ languagesCount: availableLanguages.length,
2877
+ onClose: function onClose() {
2878
+ return setIsDeleteAlertOpen(false);
2879
+ }
2880
+ }), /*#__PURE__*/jsx(DeleteSmsReminderModal, {
2881
+ hostSpecificData: hostSpecificData,
2882
+ isOpen: isDeleteSmsReminderModalOpen,
2883
+ onClose: function onClose() {
2884
+ return setIsDeleteSmsReminderModalOpen(false);
2885
+ }
2886
+ }), /*#__PURE__*/jsx(DeleteSpotModal, {
2887
+ hostSpecificData: hostSpecificData,
2888
+ isOpen: isDeleteSpotModalOpen,
2889
+ onClose: function onClose() {
2890
+ return setIsDeleteSpotModalOpen(false);
2891
+ }
2892
+ }), /*#__PURE__*/jsxs("div", {
2893
+ className: "neeto-form-nano-form-wrapper flex h-full flex-col",
2894
+ children: [formTitle && /*#__PURE__*/jsx(Overview, {
2895
+ additionalActionOptions: additionalActionOptions,
2896
+ availableLanguages: availableLanguages,
2897
+ description: formDescription,
2898
+ title: formTitle
2899
+ }), /*#__PURE__*/jsx("div", {
2900
+ className: "neeto-form-nano-form-wrapper__body min-h-0 w-full grow space-y-6 overflow-y-auto pb-6",
2901
+ children: isPresent(questions) ? /*#__PURE__*/jsxs("div", {
2902
+ className: "space-y-6",
2903
+ ref: containerRef,
2904
+ children: [/*#__PURE__*/jsx(DragDropContext, {
2905
+ onDragEnd: function onDragEnd(_ref3) {
2906
+ var source = _ref3.source,
2907
+ destination = _ref3.destination;
2908
+ return handleFieldDragEnd({
2909
+ source: source,
2910
+ destination: destination,
2911
+ items: questions,
2912
+ setValue: function setValue(orderedQuestions) {
2913
+ setQuestions(orderedQuestions);
2914
+ handleReorder(orderedQuestions);
2915
+ }
2916
+ });
2917
+ },
2918
+ children: /*#__PURE__*/jsx(Questions, {
2919
+ canManageQuestions: canManageQuestions,
2920
+ getActiveKindDetails: getActiveKindDetails,
2921
+ isDeletable: isDeletable,
2922
+ questions: questions,
2923
+ selectedQuestion: selectedQuestion,
2924
+ allQuestionKinds: questionKinds,
2925
+ onClone: handleClone,
2926
+ onDelete: handleDelete,
2927
+ onEdit: handleEdit,
2928
+ onSelect: handleSelect
2929
+ })
2930
+ }), canManageQuestions && /*#__PURE__*/jsx("div", {
2931
+ className: "mb-8 flex w-full items-center gap-x-1",
2932
+ children: /*#__PURE__*/jsx(AddQuestion, {
2933
+ addQuestionHelpProps: addQuestionHelpProps,
2934
+ disabledAddButtonHelpPopoverProps: disabledAddButtonHelpPopoverProps,
2935
+ isDisabled: isEmpty(availableQuestionKinds),
2936
+ onAdd: handleAdd
2937
+ })
2938
+ })]
2939
+ }) : /*#__PURE__*/jsx(AddFirstQuestion, {
2940
+ disabledAddButtonHelpPopoverProps: disabledAddButtonHelpPopoverProps,
2941
+ isDisabled: isEmpty(availableQuestionKinds) || !canManageQuestions,
2942
+ onAdd: handleAdd
2943
+ })
2944
+ }), /*#__PURE__*/jsx(ManageQuestionPane, {
2945
+ availableQuestionKinds: availableQuestionKinds,
2946
+ getActiveKindDetails: getActiveKindDetails,
2947
+ handleSelect: handleSelect,
2948
+ isDisabledFieldLabel: isDisabledFieldLabel,
2949
+ isRequiredField: isRequiredField,
2950
+ kindUniqueOn: kindUniqueOn,
2951
+ questions: questions,
2952
+ action: selectedAction,
2953
+ allQuestionKinds: questionKinds,
2954
+ isOpen: isManageQuestionPaneOpen,
2955
+ question: selectedQuestion,
2956
+ onClose: function onClose() {
2957
+ return setIsManageQuestionPaneOpen(false);
2958
+ }
2959
+ })]
2960
+ })]
2961
+ });
2962
+ };
2963
+
2964
+ var BuildForm = function BuildForm(_ref) {
2965
+ var id = _ref.id,
2966
+ questionKinds = _ref.questionKinds,
2967
+ _ref$isKindAlreadyAct = _ref.isKindAlreadyActive,
2968
+ isKindAlreadyActive = _ref$isKindAlreadyAct === void 0 ? isQuestionKindAlreadyActive : _ref$isKindAlreadyAct,
2969
+ _ref$getActiveKindDet = _ref.getActiveKindDetails,
2970
+ getActiveKindDetails = _ref$getActiveKindDet === void 0 ? getActiveQuestionKindDetails : _ref$getActiveKindDet,
2971
+ kindUniqueOn = _ref.kindUniqueOn,
2972
+ _ref$isQuestionDeleta = _ref.isQuestionDeletable,
2973
+ isQuestionDeletable = _ref$isQuestionDeleta === void 0 ? T : _ref$isQuestionDeleta,
2974
+ _ref$isFieldRequired = _ref.isFieldRequired,
2975
+ isFieldRequired = _ref$isFieldRequired === void 0 ? F : _ref$isFieldRequired,
2976
+ isFieldLabelDisabled = _ref.isFieldLabelDisabled,
2977
+ _ref$formTitle = _ref.formTitle,
2978
+ formTitle = _ref$formTitle === void 0 ? "" : _ref$formTitle,
2979
+ formDescription = _ref.formDescription,
2980
+ _ref$availableLanguag = _ref.availableLanguages,
2981
+ availableLanguages = _ref$availableLanguag === void 0 ? DEFAULT_AVAILABLE_LANGUAGES : _ref$availableLanguag,
2982
+ _ref$selectedLanguage = _ref.selectedLanguage,
2983
+ selectedLanguage = _ref$selectedLanguage === void 0 ? "en" : _ref$selectedLanguage,
2984
+ _ref$onLanguageChange = _ref.onLanguageChange,
2985
+ onLanguageChange = _ref$onLanguageChange === void 0 ? noop : _ref$onLanguageChange,
2986
+ _ref$addQuestionHelpP = _ref.addQuestionHelpProps,
2987
+ addQuestionHelpProps = _ref$addQuestionHelpP === void 0 ? {} : _ref$addQuestionHelpP,
2988
+ _ref$disabledAddButto = _ref.disabledAddButtonHelpPopoverProps,
2989
+ disabledAddButtonHelpPopoverProps = _ref$disabledAddButto === void 0 ? {} : _ref$disabledAddButto,
2990
+ _ref$additionalAction = _ref.additionalActionOptions,
2991
+ additionalActionOptions = _ref$additionalAction === void 0 ? [] : _ref$additionalAction,
2992
+ _ref$allowAdditionalG = _ref.allowAdditionalGuests,
2993
+ allowAdditionalGuests = _ref$allowAdditionalG === void 0 ? false : _ref$allowAdditionalG,
2994
+ _ref$advancedFeatures = _ref.advancedFeatures,
2995
+ advancedFeatures = _ref$advancedFeatures === void 0 ? DEFAULT_ADVANCED_FEATURES : _ref$advancedFeatures,
2996
+ helpDocUrls = _ref.helpDocUrls,
2997
+ className = _ref.className,
2998
+ _ref$usesCustomSubmis = _ref.usesCustomSubmissionComponent,
2999
+ usesCustomSubmissionComponent = _ref$usesCustomSubmis === void 0 ? false : _ref$usesCustomSubmis,
3000
+ _ref$onMutateSuccess = _ref.onMutateSuccess,
3001
+ onMutateSuccess = _ref$onMutateSuccess === void 0 ? noop : _ref$onMutateSuccess,
3002
+ hostSpecificData = _ref.hostSpecificData,
3003
+ _ref$canManageQuestio = _ref.canManageQuestions,
3004
+ canManageQuestions = _ref$canManageQuestio === void 0 ? false : _ref$canManageQuestio,
3005
+ _ref$isPictureChoiceE = _ref.isPictureChoiceEnabled,
3006
+ isPictureChoiceEnabled = _ref$isPictureChoiceE === void 0 ? false : _ref$isPictureChoiceE;
3007
+ var queryClient = useQueryClient();
3008
+ var _useForm = useForm({
3009
+ formId: id,
3010
+ language: selectedLanguage
3011
+ }),
3012
+ data = _useForm.data,
3013
+ isLoading = _useForm.isLoading,
3014
+ isQuestionsPending = _useForm.isPending;
3015
+ var _ref2 = data || QUESTIONS_INITIAL_VALUE,
3016
+ isFormEnabled = _ref2.enabled,
3017
+ savedTitle = _ref2.title,
3018
+ questionsFromCache = _ref2.questions,
3019
+ isQuestionsLoading = _ref2.isQuestionsLoading;
3020
+ if (isLoading || isQuestionsLoading && !isQuestionsPending) {
3021
+ return /*#__PURE__*/jsx("div", {
3022
+ className: "flex h-full w-full items-center justify-center py-6",
3023
+ children: /*#__PURE__*/jsx(Spinner, {})
3024
+ });
3025
+ }
3026
+ var onValueChange = function onValueChange(questions) {
3027
+ var _queryClient$getQuery = queryClient.getQueryState([QUERY_KEYS.QUESTIONS, id, selectedLanguage]),
3028
+ dataUpdateCount = _queryClient$getQuery.dataUpdateCount;
3029
+ if (dataUpdateCount > 0) {
3030
+ queryClient.setQueryData([QUERY_KEYS.QUESTIONS, "preview/".concat(id), selectedLanguage], assoc("questions", questions));
3031
+ }
3032
+ };
3033
+ var isRequiredField = either(isMandatoryField, isFieldRequired);
3034
+ var isDisabledFieldLabel = function isDisabledFieldLabel(field) {
3035
+ return isImmutableField(field) || (isFieldLabelDisabled !== null && isFieldLabelDisabled !== void 0 ? isFieldLabelDisabled : F)(field);
3036
+ };
3037
+ var defaultQuestionKinds = allowAdditionalGuests ? QUESTION_KINDS : removeBy({
3038
+ type: QUESTION_KIND.ADDITIONAL_GUESTS.value
3039
+ }, QUESTION_KINDS);
3040
+ var isUsingDefaultQuestionKinds = isNil(questionKinds);
3041
+ return /*#__PURE__*/jsx("div", {
3042
+ className: classnames("neeto-form-nano-form-outer-wrapper relative", className),
3043
+ children: /*#__PURE__*/jsx(Form, {
3044
+ addQuestionHelpProps: addQuestionHelpProps,
3045
+ additionalActionOptions: additionalActionOptions,
3046
+ advancedFeatures: advancedFeatures,
3047
+ availableLanguages: availableLanguages,
3048
+ canManageQuestions: canManageQuestions,
3049
+ disabledAddButtonHelpPopoverProps: disabledAddButtonHelpPopoverProps,
3050
+ formDescription: formDescription,
3051
+ formTitle: formTitle,
3052
+ getActiveKindDetails: getActiveKindDetails,
3053
+ helpDocUrls: helpDocUrls,
3054
+ hostSpecificData: hostSpecificData,
3055
+ isDisabledFieldLabel: isDisabledFieldLabel,
3056
+ isFormEnabled: isFormEnabled,
3057
+ isKindAlreadyActive: isKindAlreadyActive,
3058
+ isPictureChoiceEnabled: isPictureChoiceEnabled,
3059
+ isRequiredField: isRequiredField,
3060
+ isUsingDefaultQuestionKinds: isUsingDefaultQuestionKinds,
3061
+ kindUniqueOn: kindUniqueOn,
3062
+ onLanguageChange: onLanguageChange,
3063
+ onMutateSuccess: onMutateSuccess,
3064
+ onValueChange: onValueChange,
3065
+ questionsFromCache: questionsFromCache,
3066
+ savedTitle: savedTitle,
3067
+ selectedLanguage: selectedLanguage,
3068
+ usesCustomSubmissionComponent: usesCustomSubmissionComponent,
3069
+ formId: id,
3070
+ isDeletable: isQuestionDeletable,
3071
+ questionKinds: isUsingDefaultQuestionKinds ? defaultQuestionKinds : questionKinds
3072
+ })
3073
+ });
3074
+ };
3075
+
3076
+ export { BuildForm as default };
3077
+ //# sourceMappingURL=BuildForm.js.map