@bigbinary/neeto-form-frontend 4.4.9 → 4.4.11

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