@bigbinary/neeto-form-frontend 4.4.6 → 4.4.7

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