@bigbinary/neeto-thank-you-frontend 1.1.4 → 1.2.0-beta1

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.
package/README.md CHANGED
@@ -115,6 +115,9 @@ application.
115
115
  `Customize thank you page` & `Redirect to external link` [default: false]
116
116
  - `blockNavigation` - Boolean to show the block navigation alert in the thank
117
117
  you configuration page when there are unsaved changes [default: false]
118
+ - `editorProps` - Accepts props that needs to be passed to the editor component.
119
+ - `preview` - An optional React component to render a custom preview instead of the default one.
120
+ - `allowEmptyCustomMessage` - A boolean flag that, when set to true, skips the frontend validation for submitting an empty message. [default: false]
118
121
  - `onConfigUpdateSuccess`: The callback function to be triggered when the
119
122
  configuration is updated. The function's first argument corresponds to the
120
123
  parameters passed to the `onSuccess` callback of React Query mutations, while
package/dist/index.cjs.js CHANGED
@@ -6,8 +6,6 @@ var React = require('react');
6
6
  var neetoCist = require('@bigbinary/neeto-cist');
7
7
  var Scrollable = require('@bigbinary/neeto-molecules/Scrollable');
8
8
  var i18next = require('i18next');
9
- var neetoEditor = require('@bigbinary/neeto-editor');
10
- var yup = require('yup');
11
9
  var classNames = require('classnames');
12
10
  var PageLoader = require('@bigbinary/neeto-molecules/PageLoader');
13
11
  var ActionBlock = require('@bigbinary/neetoui/formik/ActionBlock');
@@ -15,10 +13,11 @@ var BlockNavigation = require('@bigbinary/neetoui/formik/BlockNavigation');
15
13
  var NeetoUIForm = require('@bigbinary/neetoui/formik/Form');
16
14
  var Radio = require('@bigbinary/neetoui/formik/Radio');
17
15
  var ramda = require('ramda');
16
+ var reactQuery = require('@tanstack/react-query');
18
17
  var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
19
- var reactQuery = require('react-query');
20
18
  var axios = require('axios');
21
19
  var formik = require('formik');
20
+ var neetoEditor = require('@bigbinary/neeto-editor');
22
21
  var Label$1 = require('@bigbinary/neetoui/Label');
23
22
  var Input = require('@bigbinary/neetoui/formik/Input');
24
23
  var Switch = require('@bigbinary/neetoui/formik/Switch');
@@ -31,6 +30,7 @@ var Modal = require('@bigbinary/neetoui/Modal');
31
30
  var utils = require('@bigbinary/neeto-commons-frontend/utils');
32
31
  var initializers = require('@bigbinary/neeto-commons-frontend/initializers');
33
32
  var neetoIcons = require('@bigbinary/neeto-icons');
33
+ var yup = require('yup');
34
34
  var NeetoUIHeader = require('@bigbinary/neeto-molecules/Header');
35
35
 
36
36
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -56,7 +56,6 @@ function _interopNamespace(e) {
56
56
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
57
57
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
58
58
  var Scrollable__default = /*#__PURE__*/_interopDefaultLegacy(Scrollable);
59
- var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
60
59
  var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
61
60
  var PageLoader__default = /*#__PURE__*/_interopDefaultLegacy(PageLoader);
62
61
  var ActionBlock__default = /*#__PURE__*/_interopDefaultLegacy(ActionBlock);
@@ -70,6 +69,7 @@ var Switch__default = /*#__PURE__*/_interopDefaultLegacy(Switch);
70
69
  var Button__default = /*#__PURE__*/_interopDefaultLegacy(Button);
71
70
  var Typography__default = /*#__PURE__*/_interopDefaultLegacy(Typography);
72
71
  var Modal__default = /*#__PURE__*/_interopDefaultLegacy(Modal);
72
+ var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
73
73
  var NeetoUIHeader__default = /*#__PURE__*/_interopDefaultLegacy(NeetoUIHeader);
74
74
 
75
75
  var FORM_OPTIONS = {
@@ -88,25 +88,6 @@ var DEFAULT_IMAGE_PROPERTIES = {
88
88
  imageSignedId: null,
89
89
  imageUrl: ""
90
90
  };
91
- var VALIDATION_SCHEMA = yup__namespace.object().shape({
92
- kind: yup__namespace.string().required(),
93
- message: yup__namespace.string().test("message", i18next.t("neetoThankYou.thankYou.validations.messageRequired"), function (value) {
94
- return !neetoEditor.isEditorEmpty(value);
95
- }),
96
- socialSharingEnabled: yup__namespace.bool(),
97
- showResubmitLink: yup__namespace.bool(),
98
- resubmitLinkText: yup__namespace.string().when("showResubmitLink", {
99
- is: true,
100
- then: yup__namespace.string().required(i18next.t("neetoThankYou.thankYou.validations.resubmitLinkTextIsRequired"))
101
- }),
102
- redirectUrl: yup__namespace.string().when("kind", {
103
- is: FORM_OPTIONS.externalLink.kind,
104
- then: yup__namespace.string().url(i18next.t("neetoThankYou.thankYou.validations.invalidLink")).required(i18next.t("neetoThankYou.thankYou.validations.invalidLink")).when("kind", {
105
- is: FORM_OPTIONS.customize.kind,
106
- then: yup__namespace.string()
107
- })
108
- })
109
- });
110
91
  var EXTERNAL_URL_PREFIX = "https://";
111
92
  var THANK_YOU_TEXT_ALIGNMENTS = {
112
93
  left: "left",
@@ -182,12 +163,15 @@ var QUERY_KEYS = {
182
163
  THANK_YOU_PAGE: "thank-you-page"
183
164
  };
184
165
 
185
- 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; }
186
- 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), !0).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; }
166
+ 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; }
167
+ 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), !0).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; }
187
168
  var useShowThankYouConfiguration = function useShowThankYouConfiguration(_ref) {
188
169
  var entityId = _ref.entityId;
189
- return reactQuery.useQuery([QUERY_KEYS.THANK_YOU_CONFIGURATION, entityId], function () {
190
- return thankYouConfigurationApi.show(entityId);
170
+ return reactQuery.useQuery({
171
+ queryKey: [QUERY_KEYS.THANK_YOU_CONFIGURATION, entityId],
172
+ queryFn: function queryFn() {
173
+ return thankYouConfigurationApi.show(entityId);
174
+ }
191
175
  });
192
176
  };
193
177
  var useUpdateThankYouConfiguration = function useUpdateThankYouConfiguration(options) {
@@ -198,7 +182,7 @@ var useUpdateThankYouConfiguration = function useUpdateThankYouConfiguration(opt
198
182
  entityId: entityId,
199
183
  payload: payload
200
184
  });
201
- }, _objectSpread$2({
185
+ }, _objectSpread$3({
202
186
  keysToInvalidate: [QUERY_KEYS.THANK_YOU_CONFIGURATION]
203
187
  }, options));
204
188
  };
@@ -284,12 +268,11 @@ var Image = function Image() {
284
268
  }, values.imageUrl);
285
269
  };
286
270
 
287
- var ResubmissionWarningModal = function ResubmissionWarningModal(_ref) {
288
- var isOpen = _ref.isOpen,
271
+ var ResubmissionWarningModal = reactUtils.withT(function (_ref) {
272
+ var t = _ref.t,
273
+ isOpen = _ref.isOpen,
289
274
  setIsOpen = _ref.setIsOpen,
290
275
  uniqueSubmissionLink = _ref.uniqueSubmissionLink;
291
- var _useTranslation = reactI18next.useTranslation(),
292
- t = _useTranslation.t;
293
276
  return /*#__PURE__*/jsxRuntime.jsxs(Modal__default["default"], {
294
277
  isOpen: isOpen,
295
278
  onClose: function onClose() {
@@ -306,19 +289,21 @@ var ResubmissionWarningModal = function ResubmissionWarningModal(_ref) {
306
289
  }), /*#__PURE__*/jsxRuntime.jsxs(Modal__default["default"].Footer, {
307
290
  className: "space-x-2",
308
291
  children: [/*#__PURE__*/jsxRuntime.jsx(Button__default["default"], {
309
- label: t("neetoThankYou.thankYou.uniqueSubmissionLinkText"),
310
- to: uniqueSubmissionLink
311
- }), /*#__PURE__*/jsxRuntime.jsx(Button__default["default"], {
312
292
  label: t("neetoThankYou.common.ok"),
313
- style: "text",
293
+ style: "tertiary",
314
294
  onClick: function onClick() {
315
295
  return setIsOpen(false);
316
296
  }
297
+ }), /*#__PURE__*/jsxRuntime.jsx(Button__default["default"], {
298
+ label: t("neetoThankYou.thankYou.uniqueSubmissionLinkText"),
299
+ to: uniqueSubmissionLink
317
300
  })]
318
301
  })]
319
302
  });
320
- };
303
+ });
321
304
 
305
+ 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; }
306
+ 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), !0).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; }
322
307
  var Customize = function Customize(_ref) {
323
308
  var editorRef = _ref.editorRef,
324
309
  uniqueSubmissionEnabled = _ref.uniqueSubmissionEnabled,
@@ -326,7 +311,8 @@ var Customize = function Customize(_ref) {
326
311
  uniqueSubmissionLink = _ref.uniqueSubmissionLink,
327
312
  entityId = _ref.entityId,
328
313
  disableSocialShare = _ref.disableSocialShare,
329
- disableSubmitAnotherResponse = _ref.disableSubmitAnotherResponse;
314
+ disableSubmitAnotherResponse = _ref.disableSubmitAnotherResponse,
315
+ editorProps = _ref.editorProps;
330
316
  var _useState = React.useState(false),
331
317
  _useState2 = _slicedToArray(_useState, 2),
332
318
  isUniqueSubmissionWarningModalOpen = _useState2[0],
@@ -361,13 +347,13 @@ var Customize = function Customize(_ref) {
361
347
  }), /*#__PURE__*/jsxRuntime.jsx(Image, {})]
362
348
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
363
349
  className: "flex flex-col gap-2",
364
- children: /*#__PURE__*/jsxRuntime.jsx(neetoEditor.FormikEditor, {
350
+ children: /*#__PURE__*/jsxRuntime.jsx(neetoEditor.FormikEditor, _objectSpread$2({
365
351
  required: true,
366
352
  "data-cy": "thank-you-message-editor",
367
353
  label: t("neetoThankYou.thankYou.messageLabel"),
368
354
  name: "message",
369
355
  ref: editorRef
370
- })
356
+ }, editorProps))
371
357
  }), !disableSocialShare && /*#__PURE__*/jsxRuntime.jsx(Switch__default["default"], {
372
358
  label: t("neetoThankYou.thankYou.socialShareIcons"),
373
359
  name: "socialSharingEnabled"
@@ -595,6 +581,29 @@ var Label = function Label(_ref) {
595
581
  });
596
582
  };
597
583
 
584
+ var buildValidationSchema = function buildValidationSchema() {
585
+ var allowEmptyCustomMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
586
+ return yup__namespace.object().shape({
587
+ kind: yup__namespace.string().required(),
588
+ message: yup__namespace.string().test("message", i18next.t("neetoThankYou.thankYou.validations.messageRequired"), function (value) {
589
+ return allowEmptyCustomMessage || !neetoEditor.isEditorEmpty(value);
590
+ }),
591
+ socialSharingEnabled: yup__namespace.bool(),
592
+ showResubmitLink: yup__namespace.bool(),
593
+ resubmitLinkText: yup__namespace.string().when("showResubmitLink", {
594
+ is: true,
595
+ then: yup__namespace.string().required(i18next.t("neetoThankYou.thankYou.validations.resubmitLinkTextIsRequired"))
596
+ }),
597
+ redirectUrl: yup__namespace.string().when("kind", {
598
+ is: FORM_OPTIONS.externalLink.kind,
599
+ then: yup__namespace.string().url(i18next.t("neetoThankYou.thankYou.validations.invalidLink")).required(i18next.t("neetoThankYou.thankYou.validations.invalidLink")).when("kind", {
600
+ is: FORM_OPTIONS.customize.kind,
601
+ then: yup__namespace.string()
602
+ })
603
+ })
604
+ });
605
+ };
606
+
598
607
  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; }
599
608
  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; }
600
609
  var Form = function Form(_ref) {
@@ -613,7 +622,10 @@ var Form = function Form(_ref) {
613
622
  appName = _ref.appName,
614
623
  blockNavigation = _ref.blockNavigation,
615
624
  onConfigUpdateSuccess = _ref.onConfigUpdateSuccess,
616
- brandingInfo = _ref.brandingInfo;
625
+ brandingInfo = _ref.brandingInfo,
626
+ editorProps = _ref.editorProps,
627
+ CustomPreview = _ref.preview,
628
+ allowEmptyCustomMessage = _ref.allowEmptyCustomMessage;
617
629
  var _useShowThankYouConfi = useShowThankYouConfiguration({
618
630
  entityId: entityId
619
631
  }),
@@ -623,7 +635,7 @@ var Form = function Form(_ref) {
623
635
  isLoading = _useShowThankYouConfi.isLoading;
624
636
  var _useUpdateThankYouCon = useUpdateThankYouConfiguration(),
625
637
  updateThankYouConfiguration = _useUpdateThankYouCon.mutate,
626
- isUpdatingForm = _useUpdateThankYouCon.isLoading;
638
+ isUpdatingForm = _useUpdateThankYouCon.isPending;
627
639
  var editorRef = React.useRef({
628
640
  editor: {}
629
641
  });
@@ -641,7 +653,7 @@ var Form = function Form(_ref) {
641
653
  formikProps: {
642
654
  enableReinitialize: true,
643
655
  initialValues: _objectSpread(_objectSpread({}, DEFAULT_IMAGE_PROPERTIES), thankYouConfiguration),
644
- validationSchema: VALIDATION_SCHEMA,
656
+ validationSchema: buildValidationSchema(allowEmptyCustomMessage),
645
657
  onSubmit: function onSubmit(values) {
646
658
  return updateThankYouConfiguration({
647
659
  entityId: entityId,
@@ -682,6 +694,7 @@ var Form = function Form(_ref) {
682
694
  })
683
695
  }), values.kind === FORM_OPTIONS.customize.kind ? /*#__PURE__*/jsxRuntime.jsx(Customize, {
684
696
  disableSubmitAnotherResponse: disableSubmitAnotherResponse,
697
+ editorProps: editorProps,
685
698
  editorRef: editorRef,
686
699
  entityId: entityId,
687
700
  hasImageUploader: hasImageUploader,
@@ -704,7 +717,9 @@ var Form = function Form(_ref) {
704
717
  "data-cy": "neeto-thank-you-configuration-save-button"
705
718
  }
706
719
  })]
707
- }), values.kind === FORM_OPTIONS.customize.kind && /*#__PURE__*/jsxRuntime.jsx(Preview, {
720
+ }), values.kind === FORM_OPTIONS.customize.kind && (CustomPreview ? /*#__PURE__*/jsxRuntime.jsx(CustomPreview, {
721
+ values: values
722
+ }) : /*#__PURE__*/jsxRuntime.jsx(Preview, {
708
723
  appName: appName,
709
724
  brandingInfo: brandingInfo,
710
725
  isPublished: isPublished,
@@ -712,7 +727,7 @@ var Form = function Form(_ref) {
712
727
  resubmitLink: resubmitLink,
713
728
  socialHandles: socialHandles,
714
729
  thankYouTextAlignment: thankYouTextAlignment
715
- })]
730
+ }))]
716
731
  });
717
732
  }
718
733
  });
@@ -759,7 +774,12 @@ var ConfigureThankYou = function ConfigureThankYou(_ref) {
759
774
  blockNavigation = _ref$blockNavigation === void 0 ? false : _ref$blockNavigation,
760
775
  _ref$onConfigUpdateSu = _ref.onConfigUpdateSuccess,
761
776
  onConfigUpdateSuccess = _ref$onConfigUpdateSu === void 0 ? neetoCist.noop : _ref$onConfigUpdateSu,
762
- brandingInfo = _ref.brandingInfo;
777
+ brandingInfo = _ref.brandingInfo,
778
+ _ref$editorProps = _ref.editorProps,
779
+ editorProps = _ref$editorProps === void 0 ? {} : _ref$editorProps,
780
+ preview = _ref.preview,
781
+ _ref$allowEmptyCustom = _ref.allowEmptyCustomMessage,
782
+ allowEmptyCustomMessage = _ref$allowEmptyCustom === void 0 ? false : _ref$allowEmptyCustom;
763
783
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
764
784
  children: [customHeader || /*#__PURE__*/jsxRuntime.jsx(Header, {
765
785
  breadcrumbs: breadcrumbs
@@ -768,15 +788,18 @@ var ConfigureThankYou = function ConfigureThankYou(_ref) {
768
788
  children: /*#__PURE__*/jsxRuntime.jsx("div", {
769
789
  className: "mx-auto h-full max-w-7xl",
770
790
  children: /*#__PURE__*/jsxRuntime.jsx(Form, {
791
+ allowEmptyCustomMessage: allowEmptyCustomMessage,
771
792
  appName: appName,
772
793
  blockNavigation: blockNavigation,
773
794
  brandingInfo: brandingInfo,
774
795
  disableRadioSelection: disableRadioSelection,
775
796
  disableSubmitAnotherResponse: disableSubmitAnotherResponse,
797
+ editorProps: editorProps,
776
798
  entityId: entityId,
777
799
  hasImageUploader: hasImageUploader,
778
800
  isPublished: isPublished,
779
801
  onConfigUpdateSuccess: onConfigUpdateSuccess,
802
+ preview: preview,
780
803
  publicLinkId: publicLinkId,
781
804
  redirectToOnCancel: redirectToOnCancel,
782
805
  resubmitLink: resubmitLink,
@@ -808,11 +831,14 @@ var thankYouPageApi = {
808
831
  var useShowThankYouPage = function useShowThankYouPage(_ref) {
809
832
  var entityId = _ref.entityId,
810
833
  isTemplateView = _ref.isTemplateView;
811
- return reactQuery.useQuery([QUERY_KEYS.THANK_YOU_PAGE, entityId], function () {
812
- return thankYouPageApi.show({
813
- entityId: entityId,
814
- isTemplateView: isTemplateView
815
- });
834
+ return reactQuery.useQuery({
835
+ queryKey: [QUERY_KEYS.THANK_YOU_PAGE, entityId],
836
+ queryFn: function queryFn() {
837
+ return thankYouPageApi.show({
838
+ entityId: entityId,
839
+ isTemplateView: isTemplateView
840
+ });
841
+ }
816
842
  });
817
843
  };
818
844