@bigbinary/neeto-form-frontend 3.12.0 → 3.12.2

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 (38) hide show
  1. package/README.md +2 -0
  2. package/app/javascript/src/translations/en.json +2 -2
  3. package/dist/BuildForm.js +1 -2
  4. package/dist/BuildForm.js.map +1 -1
  5. package/dist/ExternalForm.js +2 -3
  6. package/dist/ExternalForm.js.map +1 -1
  7. package/dist/Submission.js +170 -155
  8. package/dist/Submission.js.map +1 -1
  9. package/dist/UrlBuilder.js +2 -3
  10. package/dist/UrlBuilder.js.map +1 -1
  11. package/dist/cjs/BuildForm.js +3 -4
  12. package/dist/cjs/BuildForm.js.map +1 -1
  13. package/dist/cjs/ExternalForm.js +2 -3
  14. package/dist/cjs/ExternalForm.js.map +1 -1
  15. package/dist/cjs/Submission.js +168 -153
  16. package/dist/cjs/Submission.js.map +1 -1
  17. package/dist/cjs/UrlBuilder.js +12 -13
  18. package/dist/cjs/UrlBuilder.js.map +1 -1
  19. package/dist/cjs/index.js +2 -4
  20. package/dist/cjs/index.js.map +1 -1
  21. package/dist/{constants-DdGn1rF4.js → constants-Cg0HQXNC.js} +335 -4
  22. package/dist/constants-Cg0HQXNC.js.map +1 -0
  23. package/dist/{constants-CIKOBOUZ.js → constants-DojODK3U.js} +363 -8
  24. package/dist/constants-DojODK3U.js.map +1 -0
  25. package/dist/index.js +2 -4
  26. package/dist/index.js.map +1 -1
  27. package/dist/{utils-DbT-aQHP.js → utils-CWpYc-_S.js} +2 -3
  28. package/dist/{utils-DbT-aQHP.js.map → utils-CWpYc-_S.js.map} +1 -1
  29. package/dist/{utils-F-H352VB.js → utils-DE2Rc41X.js} +6 -7
  30. package/dist/{utils-F-H352VB.js.map → utils-DE2Rc41X.js.map} +1 -1
  31. package/package.json +5 -5
  32. package/types.d.ts +1 -1
  33. package/dist/constants-Byuu9IoS.js +0 -339
  34. package/dist/constants-Byuu9IoS.js.map +0 -1
  35. package/dist/constants-CIKOBOUZ.js.map +0 -1
  36. package/dist/constants-CN0KQk0z.js +0 -369
  37. package/dist/constants-CN0KQk0z.js.map +0 -1
  38. package/dist/constants-DdGn1rF4.js.map +0 -1
@@ -1,21 +1,19 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import classnames from 'classnames';
3
+ import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
4
+ import Typography from '@bigbinary/neetoui/Typography';
5
+ import { Q as QUESTION_TYPES, e as useSubmission } from './constants-LQk7jxH9.js';
3
6
  import { t } from 'i18next';
4
- import { removeBy, isNotPresent, modifyBy, isPresent } from '@bigbinary/neeto-cist';
7
+ import { isNotPresent } from '@bigbinary/neeto-cist';
5
8
  import { dateFormat } from '@bigbinary/neeto-commons-frontend/utils';
6
9
  import EditorContent from '@bigbinary/neeto-editor/EditorContent';
7
10
  import CopyToClipboardButton from '@bigbinary/neeto-molecules/CopyToClipboardButton';
8
- import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
9
11
  import { PhoneNumber } from '@bigbinary/neeto-molecules/PhoneNumber';
10
- import Typography from '@bigbinary/neetoui/Typography';
11
- import { includes, __, mergeLeft, isEmpty } from 'ramda';
12
- import { renderToString } from 'react-dom/server';
12
+ import { isEmpty } from 'ramda';
13
13
  import React__default from 'react';
14
- import { Q as QUESTION_KIND } from './constants-Byuu9IoS.js';
15
- import { Q as QUESTION_TYPES, e as useSubmission } from './constants-LQk7jxH9.js';
16
14
  import { jsx, jsxs } from 'react/jsx-runtime';
17
- import '@babel/runtime/helpers/objectWithoutProperties';
18
15
  import '@babel/runtime/helpers/toConsumableArray';
16
+ import '@babel/runtime/helpers/objectWithoutProperties';
19
17
  import '@tanstack/react-query';
20
18
  import '@bigbinary/neeto-commons-frontend/constants';
21
19
  import '@bigbinary/neeto-commons-frontend/react-utils';
@@ -2546,57 +2544,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
2546
2544
 
2547
2545
  var _default = dist.default = _Linkify2.default;
2548
2546
 
2549
- var filterAdditionalGuestResponses = removeBy({
2550
- kind: QUESTION_KIND.ADDITIONAL_GUESTS.value,
2551
- value: isNotPresent
2552
- });
2553
- var transformNameResponses = function transformNameResponses(response, shouldSplitResponses) {
2554
- var isSplitMode = response.isSplitMode,
2555
- fullNameLabel = response.fullNameLabel,
2556
- firstNameLabel = response.firstNameLabel,
2557
- lastNameLabel = response.lastNameLabel,
2558
- _response$value = response.value,
2559
- _response$value2 = _response$value === void 0 ? {} : _response$value,
2560
- _response$value2$full = _response$value2.fullName,
2561
- fullName = _response$value2$full === void 0 ? "" : _response$value2$full,
2562
- _response$value2$firs = _response$value2.firstName,
2563
- firstName = _response$value2$firs === void 0 ? "" : _response$value2$firs,
2564
- _response$value2$last = _response$value2.lastName,
2565
- lastName = _response$value2$last === void 0 ? "" : _response$value2$last;
2566
- if (isSplitMode && shouldSplitResponses) {
2567
- return [mergeLeft({
2568
- value: firstName,
2569
- label: firstNameLabel
2570
- }, response), mergeLeft({
2571
- value: lastName,
2572
- label: lastNameLabel
2573
- }, response)];
2574
- }
2575
- return mergeLeft({
2576
- value: fullName,
2577
- label: fullNameLabel
2578
- }, response);
2579
- };
2580
- var linkifyDecorator = function linkifyDecorator(decoratedHref, decoratedText, key) {
2581
- return /*#__PURE__*/jsx("a", {
2582
- className: "neeto-ui-text-accent-800 hover:neeto-ui-text-accent-800",
2583
- href: decoratedHref,
2584
- rel: "noreferrer",
2585
- target: "_blank",
2586
- children: decoratedText
2587
- }, key);
2588
- };
2589
- var normalizeResponses = function normalizeResponses(responses, omitKinds, shouldSplitNameResponses) {
2590
- var filteredResponses = removeBy({
2591
- kind: includes(__, omitKinds)
2592
- }, responses);
2593
- return modifyBy({
2594
- kind: QUESTION_TYPES.NAME
2595
- }, function (response) {
2596
- return transformNameResponses(response, shouldSplitNameResponses);
2597
- }, filterAdditionalGuestResponses(filteredResponses));
2598
- };
2599
-
2600
2547
  var FileUpload = function FileUpload(_ref) {
2601
2548
  var files = _ref.files;
2602
2549
  return /*#__PURE__*/jsx("div", {
@@ -2618,103 +2565,84 @@ var FileUpload = function FileUpload(_ref) {
2618
2565
  });
2619
2566
  };
2620
2567
 
2621
- 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; }
2622
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).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; }
2623
- var getValue = function getValue(_ref) {
2568
+ 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; }
2569
+ 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), !0).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; }
2570
+ var LinkifiedText = function LinkifiedText(_ref) {
2624
2571
  var value = _ref.value,
2625
- kind = _ref.kind;
2626
- if (isEmpty(value)) return /*#__PURE__*/jsx("i", {
2627
- children: t("neetoForm.common.unanswered")
2628
- });
2629
- if (kind === QUESTION_KIND.DATE.value) {
2630
- return value && dateFormat.date(value);
2631
- }
2632
- if (kind === QUESTION_KIND.ADDITIONAL_GUESTS.value) {
2633
- return value === null || value === void 0 ? void 0 : value.join(", ");
2634
- }
2635
- if (kind === QUESTION_KIND.CONDITION.value) {
2636
- return (value === null || value === void 0 ? void 0 : value.toLowerCase()) === "true" ? t("neetoForm.common.yes") : t("neetoForm.common.no");
2637
- }
2638
- return value;
2639
- };
2640
- var getEditorContent = function getEditorContent(value) {
2641
- if (typeof value !== "string") {
2642
- return renderToString(value);
2643
- }
2644
- return value;
2645
- };
2646
- var LinkifiedText = function LinkifiedText(_ref2) {
2647
- var kind = _ref2.kind,
2648
- value = _ref2.value,
2649
- answerProps = _ref2.answerProps;
2650
- return /*#__PURE__*/jsx(Typography, _objectSpread(_objectSpread({
2572
+ answerProps = _ref.answerProps;
2573
+ return /*#__PURE__*/jsx(Typography, _objectSpread$1(_objectSpread$1({
2651
2574
  className: "whitespace-pre-line",
2652
2575
  weight: "semibold"
2653
2576
  }, answerProps), {}, {
2654
2577
  children: /*#__PURE__*/jsx(_default, {
2655
2578
  componentDecorator: linkifyDecorator,
2656
- children: getValue({
2657
- value: value,
2658
- kind: kind
2659
- })
2579
+ children: value
2660
2580
  })
2661
2581
  }));
2662
2582
  };
2663
- var Submission = function Submission(_ref3) {
2664
- var _ref3$formId = _ref3.formId,
2665
- formId = _ref3$formId === void 0 ? "" : _ref3$formId,
2666
- _ref3$submissionId = _ref3.submissionId,
2667
- submissionId = _ref3$submissionId === void 0 ? "" : _ref3$submissionId,
2668
- _ref3$className = _ref3.className,
2669
- className = _ref3$className === void 0 ? "" : _ref3$className,
2670
- _ref3$fetchPublicSubm = _ref3.fetchPublicSubmission,
2671
- fetchPublicSubmission = _ref3$fetchPublicSubm === void 0 ? true : _ref3$fetchPublicSubm,
2672
- _ref3$shouldSplitName = _ref3.shouldSplitNameResponses,
2673
- shouldSplitNameResponses = _ref3$shouldSplitName === void 0 ? false : _ref3$shouldSplitName,
2674
- _ref3$questionLabelPr = _ref3.questionLabelProps,
2675
- questionLabelProps = _ref3$questionLabelPr === void 0 ? {} : _ref3$questionLabelPr,
2676
- _ref3$answerProps = _ref3.answerProps,
2677
- answerProps = _ref3$answerProps === void 0 ? {} : _ref3$answerProps,
2678
- _ref3$omitKinds = _ref3.omitKinds,
2679
- omitKinds = _ref3$omitKinds === void 0 ? [] : _ref3$omitKinds;
2680
- var _useSubmission = useSubmission({
2681
- formId: formId,
2682
- submissionId: submissionId,
2683
- fetchPublicSubmission: fetchPublicSubmission,
2684
- enabled: !!(formId && submissionId)
2685
- }),
2686
- _useSubmission$data = _useSubmission.data,
2687
- submission = _useSubmission$data === void 0 ? {
2688
- responses: []
2689
- } : _useSubmission$data,
2690
- isLoading = _useSubmission.isLoading;
2691
- var responses = submission.responses;
2692
- var normalizedResponses = normalizeResponses(responses, omitKinds, shouldSplitNameResponses);
2693
- var renderSubmittedValue = function renderSubmittedValue(kind, value) {
2694
- switch (kind) {
2695
- case QUESTION_KIND.RICH_TEXT.value:
2696
- return /*#__PURE__*/jsx(EditorContent, {
2697
- content: getEditorContent(getValue({
2698
- value: value,
2699
- kind: kind
2700
- }))
2701
- });
2702
- case QUESTION_KIND.PHONE.value:
2703
- case QUESTION_KIND.SMS_REMINDER.value:
2704
- return isPresent(value) ? /*#__PURE__*/jsx(PhoneNumber, {
2705
- value: value,
2706
- showEmoji: true
2707
- }) : "-";
2708
- case QUESTION_KIND.FILE_UPLOAD.value:
2709
- return isPresent(value) ? /*#__PURE__*/jsx(FileUpload, {
2710
- files: value
2711
- }) : "-";
2712
- case QUESTION_KIND.EMAIL.value:
2713
- return /*#__PURE__*/jsxs("div", {
2583
+ var normalizeName = function normalizeName(normalizedResponses, response) {
2584
+ var isSplitMode = response.isSplitMode,
2585
+ fullNameLabel = response.fullNameLabel,
2586
+ firstNameLabel = response.firstNameLabel,
2587
+ lastNameLabel = response.lastNameLabel,
2588
+ _response$value = response.value,
2589
+ _response$value2 = _response$value === void 0 ? {
2590
+ fullName: "",
2591
+ firstName: "",
2592
+ lastName: ""
2593
+ } : _response$value,
2594
+ _response$value2$full = _response$value2.fullName,
2595
+ fullName = _response$value2$full === void 0 ? "" : _response$value2$full,
2596
+ _response$value2$firs = _response$value2.firstName,
2597
+ firstName = _response$value2$firs === void 0 ? "" : _response$value2$firs,
2598
+ _response$value2$last = _response$value2.lastName,
2599
+ lastName = _response$value2$last === void 0 ? "" : _response$value2$last;
2600
+ if (isSplitMode) {
2601
+ normalizedResponses.push({
2602
+ value: firstName,
2603
+ label: firstNameLabel
2604
+ });
2605
+ normalizedResponses.push({
2606
+ value: lastName,
2607
+ label: lastNameLabel
2608
+ });
2609
+ } else {
2610
+ normalizedResponses.push({
2611
+ value: fullName,
2612
+ label: fullNameLabel
2613
+ });
2614
+ }
2615
+ };
2616
+ var normalizeResponses = function normalizeResponses(_ref2) {
2617
+ var responses = _ref2.responses,
2618
+ omitKinds = _ref2.omitKinds,
2619
+ answerProps = _ref2.answerProps;
2620
+ var normalizedResponses = [];
2621
+ responses.forEach(function (response) {
2622
+ var kind = response.kind;
2623
+ var label = response.label;
2624
+ var value = response.value;
2625
+ if (omitKinds.includes(kind)) return;
2626
+
2627
+ // Name field doesn't have "label"
2628
+ if (kind !== QUESTION_TYPES.name && isEmpty(value)) {
2629
+ normalizedResponses.push({
2630
+ label: label,
2631
+ value: /*#__PURE__*/jsx("i", {
2632
+ children: t("neetoForm.common.unanswered")
2633
+ })
2634
+ });
2635
+ return;
2636
+ }
2637
+ if (kind === QUESTION_TYPES.NAME) {
2638
+ normalizeName(normalizedResponses, response);
2639
+ } else if (kind === QUESTION_TYPES.EMAIL) {
2640
+ normalizedResponses.push({
2641
+ label: label,
2642
+ value: /*#__PURE__*/jsxs("div", {
2714
2643
  className: "flex items-center gap-2",
2715
2644
  children: [/*#__PURE__*/jsx(LinkifiedText, {
2716
2645
  answerProps: answerProps,
2717
- kind: kind,
2718
2646
  value: value
2719
2647
  }), /*#__PURE__*/jsx(CopyToClipboardButton, {
2720
2648
  value: value,
@@ -2723,15 +2651,103 @@ var Submission = function Submission(_ref3) {
2723
2651
  size: "small",
2724
2652
  style: "text"
2725
2653
  })]
2726
- });
2727
- default:
2728
- return /*#__PURE__*/jsx(LinkifiedText, {
2654
+ })
2655
+ });
2656
+ } else if (kind === QUESTION_TYPES.ADDITIONAL_GUESTS) {
2657
+ if (isNotPresent(value)) return;
2658
+ normalizedResponses.push({
2659
+ label: label,
2660
+ value: value.join(", ")
2661
+ });
2662
+ } else if (kind === QUESTION_TYPES.FILE_UPLOAD) {
2663
+ normalizedResponses.push({
2664
+ label: label,
2665
+ value: /*#__PURE__*/jsx(FileUpload, {
2666
+ files: value
2667
+ })
2668
+ });
2669
+ } else if (kind === QUESTION_TYPES.DATE) {
2670
+ normalizedResponses.push({
2671
+ label: label,
2672
+ value: dateFormat.date(value)
2673
+ });
2674
+ } else if ([QUESTION_TYPES.PHONE, QUESTION_TYPES.SMS_REMINDER].includes(kind)) {
2675
+ normalizedResponses.push({
2676
+ label: label,
2677
+ value: /*#__PURE__*/jsx(PhoneNumber, {
2678
+ value: value,
2679
+ showEmoji: true
2680
+ })
2681
+ });
2682
+ } else if (kind === QUESTION_TYPES.RICH_TEXT) {
2683
+ // TODO test when rich text field is empty
2684
+ normalizedResponses.push({
2685
+ label: label,
2686
+ value: /*#__PURE__*/jsx(EditorContent, {
2687
+ content: value
2688
+ })
2689
+ });
2690
+ } else if (kind === QUESTION_TYPES.CONDITION) {
2691
+ normalizedResponses.push({
2692
+ label: label,
2693
+ value: value.toLowerCase() === "true" ? t("neetoForm.common.yes") : t("neetoForm.common.no")
2694
+ });
2695
+ } else {
2696
+ normalizedResponses.push({
2697
+ label: label,
2698
+ value: /*#__PURE__*/jsx(LinkifiedText, {
2729
2699
  answerProps: answerProps,
2730
- kind: kind,
2731
2700
  value: value
2732
- });
2701
+ })
2702
+ });
2733
2703
  }
2734
- };
2704
+ });
2705
+ return normalizedResponses;
2706
+ };
2707
+ var linkifyDecorator = function linkifyDecorator(decoratedHref, decoratedText, key) {
2708
+ return /*#__PURE__*/jsx("a", {
2709
+ className: "neeto-ui-text-accent-800 hover:neeto-ui-text-accent-800",
2710
+ href: decoratedHref,
2711
+ rel: "noreferrer",
2712
+ target: "_blank",
2713
+ children: decoratedText
2714
+ }, key);
2715
+ };
2716
+
2717
+ 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; }
2718
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).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; }
2719
+ var Submission = function Submission(_ref) {
2720
+ var _ref$formId = _ref.formId,
2721
+ formId = _ref$formId === void 0 ? "" : _ref$formId,
2722
+ _ref$submissionId = _ref.submissionId,
2723
+ submissionId = _ref$submissionId === void 0 ? "" : _ref$submissionId,
2724
+ _ref$className = _ref.className,
2725
+ className = _ref$className === void 0 ? "" : _ref$className,
2726
+ _ref$fetchPublicSubmi = _ref.fetchPublicSubmission,
2727
+ fetchPublicSubmission = _ref$fetchPublicSubmi === void 0 ? true : _ref$fetchPublicSubmi,
2728
+ _ref$questionLabelPro = _ref.questionLabelProps,
2729
+ questionLabelProps = _ref$questionLabelPro === void 0 ? {} : _ref$questionLabelPro,
2730
+ _ref$answerProps = _ref.answerProps,
2731
+ answerProps = _ref$answerProps === void 0 ? {} : _ref$answerProps,
2732
+ _ref$omitKinds = _ref.omitKinds,
2733
+ omitKinds = _ref$omitKinds === void 0 ? [] : _ref$omitKinds;
2734
+ var _useSubmission = useSubmission({
2735
+ formId: formId,
2736
+ submissionId: submissionId,
2737
+ fetchPublicSubmission: fetchPublicSubmission,
2738
+ enabled: !!(formId && submissionId)
2739
+ }),
2740
+ _useSubmission$data = _useSubmission.data,
2741
+ _useSubmission$data2 = _useSubmission$data === void 0 ? {
2742
+ responses: []
2743
+ } : _useSubmission$data,
2744
+ responses = _useSubmission$data2.responses,
2745
+ isLoading = _useSubmission.isLoading;
2746
+ var normalizedResponses = normalizeResponses({
2747
+ responses: responses,
2748
+ omitKinds: omitKinds,
2749
+ answerProps: answerProps
2750
+ });
2735
2751
  if (isLoading) {
2736
2752
  return /*#__PURE__*/jsx("div", {
2737
2753
  className: "flex h-full w-full items-center justify-center",
@@ -2740,10 +2756,9 @@ var Submission = function Submission(_ref3) {
2740
2756
  }
2741
2757
  return /*#__PURE__*/jsx("div", {
2742
2758
  className: classnames("mx-auto flex h-full w-full flex-col items-start", _defineProperty({}, className, className)),
2743
- children: normalizedResponses.flat().map(function (_ref4) {
2744
- var kind = _ref4.kind,
2745
- label = _ref4.label,
2746
- value = _ref4.value;
2759
+ children: normalizedResponses.map(function (_ref2) {
2760
+ var label = _ref2.label,
2761
+ value = _ref2.value;
2747
2762
  return /*#__PURE__*/jsxs("div", {
2748
2763
  className: "mb-4",
2749
2764
  children: [/*#__PURE__*/jsx(Typography, _objectSpread(_objectSpread({
@@ -2751,7 +2766,7 @@ var Submission = function Submission(_ref3) {
2751
2766
  weight: "light"
2752
2767
  }, questionLabelProps), {}, {
2753
2768
  children: label
2754
- })), renderSubmittedValue(kind, value)]
2769
+ })), value]
2755
2770
  }, label);
2756
2771
  })
2757
2772
  });