@bigbinary/neeto-form-frontend 4.4.9 → 4.4.11

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