@bigbinary/neeto-form-frontend 4.4.25 → 4.4.27

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.
@@ -25,8 +25,8 @@ import { a as isBlank, g as getComponentDisplayName, p as parseServerError } fro
25
25
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
26
26
  import Check from '@bigbinary/neeto-icons/Check';
27
27
  import { jsx, jsxs } from 'react/jsx-runtime';
28
- import { C as CALLOUT_POSITIONS, b as CALLOUT_STYLES, L as LAST_ELEMENTS_THRESHOLD, Q as QUESTION_KIND } from './yup-DIWktb9n.js';
29
- import { c as clientI18nInstance, d as getWithExpiry, e as clearEmailVerificationDetails, F as FormikWrap, g as getFieldComponent, b as buildAutoCompleteAttribute, r as renderButtonsInOrder, m as mergeRefs, a as generateInitValues, f as generateFormResponse, h as clearLocalStorageValues } from './utils-B9rxoGaX.js';
28
+ import { C as CALLOUT_POSITIONS, b as CALLOUT_STYLES, L as LAST_ELEMENTS_THRESHOLD, Q as QUESTION_KIND } from './yup-DfQmQc3v.js';
29
+ import { c as clientI18nInstance, d as getWithExpiry, e as clearEmailVerificationDetails, F as FormikWrap, g as getFieldComponent, b as buildAutoCompleteAttribute, r as renderButtonsInOrder, m as mergeRefs, a as generateInitValues, f as generateFormResponse, h as clearLocalStorageValues } from './utils-BPAW-N7-.js';
30
30
  import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
31
31
  import '@babel/runtime/helpers/toConsumableArray';
32
32
  import '@bigbinary/neeto-commons-frontend/constants';
@@ -10,10 +10,10 @@ import Button from '@bigbinary/neetoui/Button';
10
10
  import NoData from '@bigbinary/neetoui/NoData';
11
11
  import { mergeLeft, map, filter, pluck, isEmpty } from 'ramda';
12
12
  import { useTranslation } from 'react-i18next';
13
- import { F as FormikWrap, g as getFieldComponent, b as buildAutoCompleteAttribute, m as mergeRefs, a as generateInitValues } from './utils-B9rxoGaX.js';
13
+ import { F as FormikWrap, g as getFieldComponent, b as buildAutoCompleteAttribute, m as mergeRefs, a as generateInitValues } from './utils-BPAW-N7-.js';
14
14
  import { d as usePublicForm } from './constants-Cj0XxE8a.js';
15
15
  import { parsePhoneNumber } from 'libphonenumber-js';
16
- import { Q as QUESTION_KIND, a as QUESTIONS_WITHOUT_FIELD_CODE } from './yup-DIWktb9n.js';
16
+ import { Q as QUESTION_KIND, a as QUESTIONS_WITHOUT_FIELD_CODE } from './yup-DfQmQc3v.js';
17
17
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
18
18
  import './index-DhtQJpD_.js';
19
19
  import '@babel/runtime/helpers/typeof';
@@ -6,7 +6,7 @@ var neetoCist = require('@bigbinary/neeto-cist');
6
6
  var Spinner = require('@bigbinary/neetoui/Spinner');
7
7
  var ramda = require('ramda');
8
8
  var constants = require('../constants-D5JlvWws.js');
9
- var yup = require('../yup-BRXHsDoc.js');
9
+ var yup = require('../yup-DoKhabp1.js');
10
10
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
11
11
  var React = require('react');
12
12
  var dnd = require('@hello-pangea/dnd');
@@ -403,8 +403,8 @@ var Card = function Card(_ref) {
403
403
  });
404
404
  };
405
405
 
406
- function ownKeys$j(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; }
407
- function _objectSpread$j(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$j(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$j(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
406
+ function ownKeys$k(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; }
407
+ function _objectSpread$k(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$k(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$k(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
408
408
  var Questions = function Questions(_ref) {
409
409
  var questions = _ref.questions,
410
410
  isDeletable = _ref.isDeletable,
@@ -424,7 +424,7 @@ var Questions = function Questions(_ref) {
424
424
  var droppableProps = _ref2.droppableProps,
425
425
  placeholder = _ref2.placeholder,
426
426
  innerRef = _ref2.innerRef;
427
- return /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread$j(_objectSpread$j({}, droppableProps), {}, {
427
+ return /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread$k(_objectSpread$k({}, droppableProps), {}, {
428
428
  className: "space-y-2",
429
429
  ref: innerRef,
430
430
  children: [questions.map(function (question, index) {
@@ -439,10 +439,10 @@ var Questions = function Questions(_ref) {
439
439
  var draggableProps = _ref3.draggableProps,
440
440
  dragHandleProps = _ref3.dragHandleProps,
441
441
  innerRef = _ref3.innerRef;
442
- return /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread$j(_objectSpread$j({}, draggableProps), {}, {
442
+ return /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread$k(_objectSpread$k({}, draggableProps), {}, {
443
443
  className: "flex items-center gap-1",
444
444
  ref: innerRef,
445
- children: [canManageQuestions && /*#__PURE__*/jsxRuntime.jsx("span", _objectSpread$j(_objectSpread$j({}, dragHandleProps), {}, {
445
+ children: [canManageQuestions && /*#__PURE__*/jsxRuntime.jsx("span", _objectSpread$k(_objectSpread$k({}, dragHandleProps), {}, {
446
446
  className: "neeto-ui-text-gray-400 hover:neeto-ui-text-gray-500 shrink-0 cursor-grab transition-all duration-300 ease-in-out",
447
447
  "data-testid": "question-card-drag-handle",
448
448
  children: /*#__PURE__*/jsxRuntime.jsx(Equals, {
@@ -483,6 +483,85 @@ var arrayHelpers = {
483
483
  moveItem: moveItem
484
484
  };
485
485
 
486
+ var _excluded$c = ["labelKey"];
487
+ function ownKeys$j(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; }
488
+ function _objectSpread$j(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$j(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$j(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
489
+ var TERMS_AND_CONDITION = constants.QUESTION_TYPES.TERMS_AND_CONDITION,
490
+ CONDITION = constants.QUESTION_TYPES.CONDITION,
491
+ CAPTCHA$2 = constants.QUESTION_TYPES.CAPTCHA,
492
+ OPINION_SCALE$2 = constants.QUESTION_TYPES.OPINION_SCALE,
493
+ ADDRESS$2 = constants.QUESTION_TYPES.ADDRESS;
494
+
495
+ // i18n keys for the prefilled default values that must follow the builder's
496
+ // selected language and be persisted into every available language. Address
497
+ // field defaults are keyed per-field via `labelKey` on the field object.
498
+ var LOCALIZED_DEFAULT_LABEL_KEYS = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, TERMS_AND_CONDITION, {
499
+ label: "neetoForm.common.agreeTermsAndConditions"
500
+ }), CONDITION, {
501
+ label: "neetoForm.common.agreeCondition"
502
+ }), CAPTCHA$2, {
503
+ label: "neetoForm.questions.common.questionFields.field.verifyHuman"
504
+ }), OPINION_SCALE$2, {
505
+ leftOpinionLabel: "neetoForm.questions.opinionScale.worst",
506
+ rightOpinionLabel: "neetoForm.questions.opinionScale.best"
507
+ });
508
+ var translateInLanguage = function translateInLanguage(key, language) {
509
+ return i18next.t(key, {
510
+ lng: language
511
+ });
512
+ };
513
+
514
+ // Re-translate a freshly added question's prefilled defaults into the selected
515
+ // language so the builder shows them in that language (not English).
516
+ var localizeDefaultValues = function localizeDefaultValues(_ref) {
517
+ var values = _ref.values,
518
+ kind = _ref.kind,
519
+ language = _ref.language;
520
+ var labelKeys = LOCALIZED_DEFAULT_LABEL_KEYS[kind];
521
+ var localized = labelKeys ? Object.entries(labelKeys).reduce(function (acc, _ref2) {
522
+ var _ref3 = _slicedToArray(_ref2, 2),
523
+ field = _ref3[0],
524
+ key = _ref3[1];
525
+ return _objectSpread$j(_objectSpread$j({}, acc), {}, _defineProperty({}, field, translateInLanguage(key, language)));
526
+ }, _objectSpread$j({}, values)) : values;
527
+ if (kind === ADDRESS$2 && Array.isArray(values.fields)) {
528
+ localized = _objectSpread$j(_objectSpread$j({}, localized), {}, {
529
+ fields: values.fields.map(function (field) {
530
+ return field.labelKey ? _objectSpread$j(_objectSpread$j({}, field), {}, {
531
+ label: translateInLanguage(field.labelKey, language)
532
+ }) : field;
533
+ })
534
+ });
535
+ }
536
+ return localized;
537
+ };
538
+
539
+ // On submit, tag every default-valued top-level label with its i18n key. The
540
+ // backend fans the default out into all languages and keeps the host's value
541
+ // only in the selected language, so unedited languages fall back to the proper
542
+ // default. Address field keys travel on the field objects themselves.
543
+ var withDefaultLabelKeys = function withDefaultLabelKeys(values) {
544
+ var labelKeys = LOCALIZED_DEFAULT_LABEL_KEYS[values.kind];
545
+ if (!labelKeys) return values;
546
+ return Object.entries(labelKeys).reduce(function (acc, _ref4) {
547
+ var _ref5 = _slicedToArray(_ref4, 2),
548
+ field = _ref5[0],
549
+ key = _ref5[1];
550
+ return _objectSpread$j(_objectSpread$j({}, acc), {}, _defineProperty({}, "".concat(field, "Key"), key));
551
+ }, values);
552
+ };
553
+ var dropLabelKey = function dropLabelKey(_ref6) {
554
+ _ref6.labelKey;
555
+ var field = _objectWithoutProperties(_ref6, _excluded$c);
556
+ return field;
557
+ };
558
+
559
+ // Address default fields carry `labelKey`; keep it on create so the backend can
560
+ // localize them, and drop it otherwise (e.g. on edit, where it is meaningless).
561
+ var withAddressFieldKeys = function withAddressFieldKeys(fields, includeKeys) {
562
+ return includeKeys ? fields : fields.map(dropLabelKey);
563
+ };
564
+
486
565
  var _excluded$b = ["fields"];
487
566
  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; }
488
567
  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; }
@@ -592,7 +671,12 @@ var createFieldData = function createFieldData(_ref5) {
592
671
  selectedLanguage: selectedLanguage,
593
672
  isUsingDefaultQuestionKinds: isUsingDefaultQuestionKinds
594
673
  });
595
- return _objectSpread$i(_objectSpread$i(_objectSpread$i({}, modifiedDefaultValues), {}, {
674
+ var localizedDefaultValues = localizeDefaultValues({
675
+ values: modifiedDefaultValues,
676
+ kind: type,
677
+ language: selectedLanguage
678
+ });
679
+ return _objectSpread$i(_objectSpread$i(_objectSpread$i({}, localizedDefaultValues), {}, {
596
680
  metadata: metadata
597
681
  }, typeof isRequired === "boolean" && {
598
682
  isRequired: isRequired
@@ -1401,7 +1485,9 @@ var Add = function Add(_ref) {
1401
1485
  language: language,
1402
1486
  neetoFormQuestion: ramda.mergeLeft({
1403
1487
  displayOrder: displayOrder
1404
- }, transformValues(values))
1488
+ }, transformValues(values, {
1489
+ includeDefaultKeys: true
1490
+ }))
1405
1491
  }, {
1406
1492
  onSuccess: function onSuccess(_ref2) {
1407
1493
  var questions = _ref2.questions;
@@ -1431,10 +1517,14 @@ var Add = function Add(_ref) {
1431
1517
  questions: questions
1432
1518
  }))), /*#__PURE__*/jsxRuntime.jsx(Pane.Footer, {
1433
1519
  children: /*#__PURE__*/jsxRuntime.jsx(ActionBlock, {
1520
+ isSubmitting: isCreating,
1521
+ submitButtonProps: {
1522
+ label: t("neetoForm.common.saveChanges")
1523
+ },
1434
1524
  cancelButtonProps: {
1525
+ label: t("neetoForm.common.cancel"),
1435
1526
  onClick: onClose
1436
- },
1437
- isSubmitting: isCreating
1527
+ }
1438
1528
  })
1439
1529
  })]
1440
1530
  })
@@ -1511,10 +1601,14 @@ var Edit = function Edit(_ref) {
1511
1601
  isEdit: true
1512
1602
  })), /*#__PURE__*/jsxRuntime.jsx(Pane.Footer, {
1513
1603
  children: /*#__PURE__*/jsxRuntime.jsx(ActionBlock, {
1604
+ isSubmitting: isUpdating,
1605
+ submitButtonProps: {
1606
+ label: t("neetoForm.common.saveChanges")
1607
+ },
1514
1608
  cancelButtonProps: {
1609
+ label: t("neetoForm.common.cancel"),
1515
1610
  onClick: onClose
1516
- },
1517
- isSubmitting: isUpdating
1611
+ }
1518
1612
  })
1519
1613
  })]
1520
1614
  })
@@ -1776,6 +1870,7 @@ var ManagePane = function ManagePane(_ref) {
1776
1870
  children: /*#__PURE__*/jsxRuntime.jsx(ActionBlock, {
1777
1871
  className: "flex gap-x-2",
1778
1872
  cancelButtonProps: {
1873
+ label: t("neetoForm.common.cancel"),
1779
1874
  type: "reset",
1780
1875
  onClick: onClose,
1781
1876
  disabled: false
@@ -2805,6 +2900,9 @@ var readOnlySwitchLabelProps = function readOnlySwitchLabelProps(helpUrl) {
2805
2900
  var transformValues = function transformValues(_ref4) {
2806
2901
  var minWords = _ref4.minWords,
2807
2902
  values = _objectWithoutProperties(_ref4, _excluded$1);
2903
+ var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2904
+ _ref5$includeDefaultK = _ref5.includeDefaultKeys,
2905
+ includeDefaultKeys = _ref5$includeDefaultK === void 0 ? false : _ref5$includeDefaultK;
2808
2906
  var rest = ramda.omit(["isMinWordsEnabled"], values);
2809
2907
  switch (rest.kind) {
2810
2908
  case constants.QUESTION_TYPES.TEXTAREA:
@@ -2816,12 +2914,13 @@ var transformValues = function transformValues(_ref4) {
2816
2914
  var _rest$fields = rest.fields,
2817
2915
  fields = _rest$fields === void 0 ? [] : _rest$fields,
2818
2916
  addressRest = _objectWithoutProperties(rest, _excluded2);
2917
+ var preparedFields = ramda.map(yup.renameKey("deleted", "_destroy"), omitDraftId(fields));
2819
2918
  return _objectSpread$2(_objectSpread$2({}, addressRest), {}, {
2820
- fieldsAttributes: ramda.map(yup.renameKey("deleted", "_destroy"), omitDraftId(fields))
2919
+ fieldsAttributes: withAddressFieldKeys(preparedFields, includeDefaultKeys)
2821
2920
  });
2822
2921
  }
2823
2922
  default:
2824
- return rest;
2923
+ return includeDefaultKeys ? withDefaultLabelKeys(rest) : rest;
2825
2924
  }
2826
2925
  };
2827
2926