@bigbinary/neeto-thank-you-frontend 1.1.4 → 1.1.5

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');
@@ -19,6 +17,7 @@ var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
19
17
  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,8 +163,8 @@ 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
170
  return reactQuery.useQuery([QUERY_KEYS.THANK_YOU_CONFIGURATION, entityId], function () {
@@ -198,7 +179,7 @@ var useUpdateThankYouConfiguration = function useUpdateThankYouConfiguration(opt
198
179
  entityId: entityId,
199
180
  payload: payload
200
181
  });
201
- }, _objectSpread$2({
182
+ }, _objectSpread$3({
202
183
  keysToInvalidate: [QUERY_KEYS.THANK_YOU_CONFIGURATION]
203
184
  }, options));
204
185
  };
@@ -284,12 +265,11 @@ var Image = function Image() {
284
265
  }, values.imageUrl);
285
266
  };
286
267
 
287
- var ResubmissionWarningModal = function ResubmissionWarningModal(_ref) {
288
- var isOpen = _ref.isOpen,
268
+ var ResubmissionWarningModal = reactUtils.withT(function (_ref) {
269
+ var t = _ref.t,
270
+ isOpen = _ref.isOpen,
289
271
  setIsOpen = _ref.setIsOpen,
290
272
  uniqueSubmissionLink = _ref.uniqueSubmissionLink;
291
- var _useTranslation = reactI18next.useTranslation(),
292
- t = _useTranslation.t;
293
273
  return /*#__PURE__*/jsxRuntime.jsxs(Modal__default["default"], {
294
274
  isOpen: isOpen,
295
275
  onClose: function onClose() {
@@ -306,19 +286,21 @@ var ResubmissionWarningModal = function ResubmissionWarningModal(_ref) {
306
286
  }), /*#__PURE__*/jsxRuntime.jsxs(Modal__default["default"].Footer, {
307
287
  className: "space-x-2",
308
288
  children: [/*#__PURE__*/jsxRuntime.jsx(Button__default["default"], {
309
- label: t("neetoThankYou.thankYou.uniqueSubmissionLinkText"),
310
- to: uniqueSubmissionLink
311
- }), /*#__PURE__*/jsxRuntime.jsx(Button__default["default"], {
312
289
  label: t("neetoThankYou.common.ok"),
313
- style: "text",
290
+ style: "tertiary",
314
291
  onClick: function onClick() {
315
292
  return setIsOpen(false);
316
293
  }
294
+ }), /*#__PURE__*/jsxRuntime.jsx(Button__default["default"], {
295
+ label: t("neetoThankYou.thankYou.uniqueSubmissionLinkText"),
296
+ to: uniqueSubmissionLink
317
297
  })]
318
298
  })]
319
299
  });
320
- };
300
+ });
321
301
 
302
+ 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; }
303
+ 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
304
  var Customize = function Customize(_ref) {
323
305
  var editorRef = _ref.editorRef,
324
306
  uniqueSubmissionEnabled = _ref.uniqueSubmissionEnabled,
@@ -326,7 +308,8 @@ var Customize = function Customize(_ref) {
326
308
  uniqueSubmissionLink = _ref.uniqueSubmissionLink,
327
309
  entityId = _ref.entityId,
328
310
  disableSocialShare = _ref.disableSocialShare,
329
- disableSubmitAnotherResponse = _ref.disableSubmitAnotherResponse;
311
+ disableSubmitAnotherResponse = _ref.disableSubmitAnotherResponse,
312
+ editorProps = _ref.editorProps;
330
313
  var _useState = React.useState(false),
331
314
  _useState2 = _slicedToArray(_useState, 2),
332
315
  isUniqueSubmissionWarningModalOpen = _useState2[0],
@@ -361,13 +344,13 @@ var Customize = function Customize(_ref) {
361
344
  }), /*#__PURE__*/jsxRuntime.jsx(Image, {})]
362
345
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
363
346
  className: "flex flex-col gap-2",
364
- children: /*#__PURE__*/jsxRuntime.jsx(neetoEditor.FormikEditor, {
347
+ children: /*#__PURE__*/jsxRuntime.jsx(neetoEditor.FormikEditor, _objectSpread$2({
365
348
  required: true,
366
349
  "data-cy": "thank-you-message-editor",
367
350
  label: t("neetoThankYou.thankYou.messageLabel"),
368
351
  name: "message",
369
352
  ref: editorRef
370
- })
353
+ }, editorProps))
371
354
  }), !disableSocialShare && /*#__PURE__*/jsxRuntime.jsx(Switch__default["default"], {
372
355
  label: t("neetoThankYou.thankYou.socialShareIcons"),
373
356
  name: "socialSharingEnabled"
@@ -595,6 +578,29 @@ var Label = function Label(_ref) {
595
578
  });
596
579
  };
597
580
 
581
+ var buildValidationSchema = function buildValidationSchema() {
582
+ var allowEmptyCustomMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
583
+ return yup__namespace.object().shape({
584
+ kind: yup__namespace.string().required(),
585
+ message: yup__namespace.string().test("message", i18next.t("neetoThankYou.thankYou.validations.messageRequired"), function (value) {
586
+ return allowEmptyCustomMessage || !neetoEditor.isEditorEmpty(value);
587
+ }),
588
+ socialSharingEnabled: yup__namespace.bool(),
589
+ showResubmitLink: yup__namespace.bool(),
590
+ resubmitLinkText: yup__namespace.string().when("showResubmitLink", {
591
+ is: true,
592
+ then: yup__namespace.string().required(i18next.t("neetoThankYou.thankYou.validations.resubmitLinkTextIsRequired"))
593
+ }),
594
+ redirectUrl: yup__namespace.string().when("kind", {
595
+ is: FORM_OPTIONS.externalLink.kind,
596
+ then: yup__namespace.string().url(i18next.t("neetoThankYou.thankYou.validations.invalidLink")).required(i18next.t("neetoThankYou.thankYou.validations.invalidLink")).when("kind", {
597
+ is: FORM_OPTIONS.customize.kind,
598
+ then: yup__namespace.string()
599
+ })
600
+ })
601
+ });
602
+ };
603
+
598
604
  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
605
  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
606
  var Form = function Form(_ref) {
@@ -613,7 +619,10 @@ var Form = function Form(_ref) {
613
619
  appName = _ref.appName,
614
620
  blockNavigation = _ref.blockNavigation,
615
621
  onConfigUpdateSuccess = _ref.onConfigUpdateSuccess,
616
- brandingInfo = _ref.brandingInfo;
622
+ brandingInfo = _ref.brandingInfo,
623
+ editorProps = _ref.editorProps,
624
+ CustomPreview = _ref.preview,
625
+ allowEmptyCustomMessage = _ref.allowEmptyCustomMessage;
617
626
  var _useShowThankYouConfi = useShowThankYouConfiguration({
618
627
  entityId: entityId
619
628
  }),
@@ -641,7 +650,7 @@ var Form = function Form(_ref) {
641
650
  formikProps: {
642
651
  enableReinitialize: true,
643
652
  initialValues: _objectSpread(_objectSpread({}, DEFAULT_IMAGE_PROPERTIES), thankYouConfiguration),
644
- validationSchema: VALIDATION_SCHEMA,
653
+ validationSchema: buildValidationSchema(allowEmptyCustomMessage),
645
654
  onSubmit: function onSubmit(values) {
646
655
  return updateThankYouConfiguration({
647
656
  entityId: entityId,
@@ -682,6 +691,7 @@ var Form = function Form(_ref) {
682
691
  })
683
692
  }), values.kind === FORM_OPTIONS.customize.kind ? /*#__PURE__*/jsxRuntime.jsx(Customize, {
684
693
  disableSubmitAnotherResponse: disableSubmitAnotherResponse,
694
+ editorProps: editorProps,
685
695
  editorRef: editorRef,
686
696
  entityId: entityId,
687
697
  hasImageUploader: hasImageUploader,
@@ -704,7 +714,9 @@ var Form = function Form(_ref) {
704
714
  "data-cy": "neeto-thank-you-configuration-save-button"
705
715
  }
706
716
  })]
707
- }), values.kind === FORM_OPTIONS.customize.kind && /*#__PURE__*/jsxRuntime.jsx(Preview, {
717
+ }), values.kind === FORM_OPTIONS.customize.kind && (CustomPreview ? /*#__PURE__*/jsxRuntime.jsx(CustomPreview, {
718
+ values: values
719
+ }) : /*#__PURE__*/jsxRuntime.jsx(Preview, {
708
720
  appName: appName,
709
721
  brandingInfo: brandingInfo,
710
722
  isPublished: isPublished,
@@ -712,7 +724,7 @@ var Form = function Form(_ref) {
712
724
  resubmitLink: resubmitLink,
713
725
  socialHandles: socialHandles,
714
726
  thankYouTextAlignment: thankYouTextAlignment
715
- })]
727
+ }))]
716
728
  });
717
729
  }
718
730
  });
@@ -759,7 +771,12 @@ var ConfigureThankYou = function ConfigureThankYou(_ref) {
759
771
  blockNavigation = _ref$blockNavigation === void 0 ? false : _ref$blockNavigation,
760
772
  _ref$onConfigUpdateSu = _ref.onConfigUpdateSuccess,
761
773
  onConfigUpdateSuccess = _ref$onConfigUpdateSu === void 0 ? neetoCist.noop : _ref$onConfigUpdateSu,
762
- brandingInfo = _ref.brandingInfo;
774
+ brandingInfo = _ref.brandingInfo,
775
+ _ref$editorProps = _ref.editorProps,
776
+ editorProps = _ref$editorProps === void 0 ? {} : _ref$editorProps,
777
+ preview = _ref.preview,
778
+ _ref$allowEmptyCustom = _ref.allowEmptyCustomMessage,
779
+ allowEmptyCustomMessage = _ref$allowEmptyCustom === void 0 ? false : _ref$allowEmptyCustom;
763
780
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
764
781
  children: [customHeader || /*#__PURE__*/jsxRuntime.jsx(Header, {
765
782
  breadcrumbs: breadcrumbs
@@ -768,15 +785,18 @@ var ConfigureThankYou = function ConfigureThankYou(_ref) {
768
785
  children: /*#__PURE__*/jsxRuntime.jsx("div", {
769
786
  className: "mx-auto h-full max-w-7xl",
770
787
  children: /*#__PURE__*/jsxRuntime.jsx(Form, {
788
+ allowEmptyCustomMessage: allowEmptyCustomMessage,
771
789
  appName: appName,
772
790
  blockNavigation: blockNavigation,
773
791
  brandingInfo: brandingInfo,
774
792
  disableRadioSelection: disableRadioSelection,
775
793
  disableSubmitAnotherResponse: disableSubmitAnotherResponse,
794
+ editorProps: editorProps,
776
795
  entityId: entityId,
777
796
  hasImageUploader: hasImageUploader,
778
797
  isPublished: isPublished,
779
798
  onConfigUpdateSuccess: onConfigUpdateSuccess,
799
+ preview: preview,
780
800
  publicLinkId: publicLinkId,
781
801
  redirectToOnCancel: redirectToOnCancel,
782
802
  resubmitLink: resubmitLink,