@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 +3 -0
- package/dist/index.cjs.js +77 -51
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +77 -51
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/types.d.ts +4 -1
package/dist/index.js
CHANGED
|
@@ -3,8 +3,6 @@ import React__default, { useState, useEffect, useRef } from 'react';
|
|
|
3
3
|
import { hyphenate, noop } from '@bigbinary/neeto-cist';
|
|
4
4
|
import Scrollable from '@bigbinary/neeto-molecules/Scrollable';
|
|
5
5
|
import { t as t$1 } from 'i18next';
|
|
6
|
-
import { isEditorEmpty, FormikEditor, EditorContent } from '@bigbinary/neeto-editor';
|
|
7
|
-
import * as yup from 'yup';
|
|
8
6
|
import classNames from 'classnames';
|
|
9
7
|
import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
|
|
10
8
|
import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
|
|
@@ -12,10 +10,11 @@ import BlockNavigation from '@bigbinary/neetoui/formik/BlockNavigation';
|
|
|
12
10
|
import NeetoUIForm from '@bigbinary/neetoui/formik/Form';
|
|
13
11
|
import Radio from '@bigbinary/neetoui/formik/Radio';
|
|
14
12
|
import { isEmpty } from 'ramda';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
13
|
+
import { useQuery } from '@tanstack/react-query';
|
|
14
|
+
import { useMutationWithInvalidation, withT } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
17
15
|
import axios from 'axios';
|
|
18
16
|
import { useFormikContext } from 'formik';
|
|
17
|
+
import { FormikEditor, EditorContent, isEditorEmpty } from '@bigbinary/neeto-editor';
|
|
19
18
|
import Label$1 from '@bigbinary/neetoui/Label';
|
|
20
19
|
import Input from '@bigbinary/neetoui/formik/Input';
|
|
21
20
|
import Switch from '@bigbinary/neetoui/formik/Switch';
|
|
@@ -28,6 +27,7 @@ import Modal from '@bigbinary/neetoui/Modal';
|
|
|
28
27
|
import { buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
|
|
29
28
|
import { globalProps } from '@bigbinary/neeto-commons-frontend/initializers';
|
|
30
29
|
import { Link } from '@bigbinary/neeto-icons';
|
|
30
|
+
import * as yup from 'yup';
|
|
31
31
|
import NeetoUIHeader from '@bigbinary/neeto-molecules/Header';
|
|
32
32
|
|
|
33
33
|
var FORM_OPTIONS = {
|
|
@@ -46,25 +46,6 @@ var DEFAULT_IMAGE_PROPERTIES = {
|
|
|
46
46
|
imageSignedId: null,
|
|
47
47
|
imageUrl: ""
|
|
48
48
|
};
|
|
49
|
-
var VALIDATION_SCHEMA = yup.object().shape({
|
|
50
|
-
kind: yup.string().required(),
|
|
51
|
-
message: yup.string().test("message", t$1("neetoThankYou.thankYou.validations.messageRequired"), function (value) {
|
|
52
|
-
return !isEditorEmpty(value);
|
|
53
|
-
}),
|
|
54
|
-
socialSharingEnabled: yup.bool(),
|
|
55
|
-
showResubmitLink: yup.bool(),
|
|
56
|
-
resubmitLinkText: yup.string().when("showResubmitLink", {
|
|
57
|
-
is: true,
|
|
58
|
-
then: yup.string().required(t$1("neetoThankYou.thankYou.validations.resubmitLinkTextIsRequired"))
|
|
59
|
-
}),
|
|
60
|
-
redirectUrl: yup.string().when("kind", {
|
|
61
|
-
is: FORM_OPTIONS.externalLink.kind,
|
|
62
|
-
then: yup.string().url(t$1("neetoThankYou.thankYou.validations.invalidLink")).required(t$1("neetoThankYou.thankYou.validations.invalidLink")).when("kind", {
|
|
63
|
-
is: FORM_OPTIONS.customize.kind,
|
|
64
|
-
then: yup.string()
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
});
|
|
68
49
|
var EXTERNAL_URL_PREFIX = "https://";
|
|
69
50
|
var THANK_YOU_TEXT_ALIGNMENTS = {
|
|
70
51
|
left: "left",
|
|
@@ -140,12 +121,15 @@ var QUERY_KEYS = {
|
|
|
140
121
|
THANK_YOU_PAGE: "thank-you-page"
|
|
141
122
|
};
|
|
142
123
|
|
|
143
|
-
function ownKeys$
|
|
144
|
-
function _objectSpread$
|
|
124
|
+
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; }
|
|
125
|
+
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; }
|
|
145
126
|
var useShowThankYouConfiguration = function useShowThankYouConfiguration(_ref) {
|
|
146
127
|
var entityId = _ref.entityId;
|
|
147
|
-
return useQuery(
|
|
148
|
-
|
|
128
|
+
return useQuery({
|
|
129
|
+
queryKey: [QUERY_KEYS.THANK_YOU_CONFIGURATION, entityId],
|
|
130
|
+
queryFn: function queryFn() {
|
|
131
|
+
return thankYouConfigurationApi.show(entityId);
|
|
132
|
+
}
|
|
149
133
|
});
|
|
150
134
|
};
|
|
151
135
|
var useUpdateThankYouConfiguration = function useUpdateThankYouConfiguration(options) {
|
|
@@ -156,7 +140,7 @@ var useUpdateThankYouConfiguration = function useUpdateThankYouConfiguration(opt
|
|
|
156
140
|
entityId: entityId,
|
|
157
141
|
payload: payload
|
|
158
142
|
});
|
|
159
|
-
}, _objectSpread$
|
|
143
|
+
}, _objectSpread$3({
|
|
160
144
|
keysToInvalidate: [QUERY_KEYS.THANK_YOU_CONFIGURATION]
|
|
161
145
|
}, options));
|
|
162
146
|
};
|
|
@@ -242,12 +226,11 @@ var Image = function Image() {
|
|
|
242
226
|
}, values.imageUrl);
|
|
243
227
|
};
|
|
244
228
|
|
|
245
|
-
var ResubmissionWarningModal = function
|
|
246
|
-
var
|
|
229
|
+
var ResubmissionWarningModal = withT(function (_ref) {
|
|
230
|
+
var t = _ref.t,
|
|
231
|
+
isOpen = _ref.isOpen,
|
|
247
232
|
setIsOpen = _ref.setIsOpen,
|
|
248
233
|
uniqueSubmissionLink = _ref.uniqueSubmissionLink;
|
|
249
|
-
var _useTranslation = useTranslation(),
|
|
250
|
-
t = _useTranslation.t;
|
|
251
234
|
return /*#__PURE__*/jsxs(Modal, {
|
|
252
235
|
isOpen: isOpen,
|
|
253
236
|
onClose: function onClose() {
|
|
@@ -264,19 +247,21 @@ var ResubmissionWarningModal = function ResubmissionWarningModal(_ref) {
|
|
|
264
247
|
}), /*#__PURE__*/jsxs(Modal.Footer, {
|
|
265
248
|
className: "space-x-2",
|
|
266
249
|
children: [/*#__PURE__*/jsx(Button, {
|
|
267
|
-
label: t("neetoThankYou.thankYou.uniqueSubmissionLinkText"),
|
|
268
|
-
to: uniqueSubmissionLink
|
|
269
|
-
}), /*#__PURE__*/jsx(Button, {
|
|
270
250
|
label: t("neetoThankYou.common.ok"),
|
|
271
|
-
style: "
|
|
251
|
+
style: "tertiary",
|
|
272
252
|
onClick: function onClick() {
|
|
273
253
|
return setIsOpen(false);
|
|
274
254
|
}
|
|
255
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
256
|
+
label: t("neetoThankYou.thankYou.uniqueSubmissionLinkText"),
|
|
257
|
+
to: uniqueSubmissionLink
|
|
275
258
|
})]
|
|
276
259
|
})]
|
|
277
260
|
});
|
|
278
|
-
};
|
|
261
|
+
});
|
|
279
262
|
|
|
263
|
+
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; }
|
|
264
|
+
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; }
|
|
280
265
|
var Customize = function Customize(_ref) {
|
|
281
266
|
var editorRef = _ref.editorRef,
|
|
282
267
|
uniqueSubmissionEnabled = _ref.uniqueSubmissionEnabled,
|
|
@@ -284,7 +269,8 @@ var Customize = function Customize(_ref) {
|
|
|
284
269
|
uniqueSubmissionLink = _ref.uniqueSubmissionLink,
|
|
285
270
|
entityId = _ref.entityId,
|
|
286
271
|
disableSocialShare = _ref.disableSocialShare,
|
|
287
|
-
disableSubmitAnotherResponse = _ref.disableSubmitAnotherResponse
|
|
272
|
+
disableSubmitAnotherResponse = _ref.disableSubmitAnotherResponse,
|
|
273
|
+
editorProps = _ref.editorProps;
|
|
288
274
|
var _useState = useState(false),
|
|
289
275
|
_useState2 = _slicedToArray(_useState, 2),
|
|
290
276
|
isUniqueSubmissionWarningModalOpen = _useState2[0],
|
|
@@ -319,13 +305,13 @@ var Customize = function Customize(_ref) {
|
|
|
319
305
|
}), /*#__PURE__*/jsx(Image, {})]
|
|
320
306
|
}), /*#__PURE__*/jsx("div", {
|
|
321
307
|
className: "flex flex-col gap-2",
|
|
322
|
-
children: /*#__PURE__*/jsx(FormikEditor, {
|
|
308
|
+
children: /*#__PURE__*/jsx(FormikEditor, _objectSpread$2({
|
|
323
309
|
required: true,
|
|
324
310
|
"data-cy": "thank-you-message-editor",
|
|
325
311
|
label: t("neetoThankYou.thankYou.messageLabel"),
|
|
326
312
|
name: "message",
|
|
327
313
|
ref: editorRef
|
|
328
|
-
})
|
|
314
|
+
}, editorProps))
|
|
329
315
|
}), !disableSocialShare && /*#__PURE__*/jsx(Switch, {
|
|
330
316
|
label: t("neetoThankYou.thankYou.socialShareIcons"),
|
|
331
317
|
name: "socialSharingEnabled"
|
|
@@ -553,6 +539,29 @@ var Label = function Label(_ref) {
|
|
|
553
539
|
});
|
|
554
540
|
};
|
|
555
541
|
|
|
542
|
+
var buildValidationSchema = function buildValidationSchema() {
|
|
543
|
+
var allowEmptyCustomMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
544
|
+
return yup.object().shape({
|
|
545
|
+
kind: yup.string().required(),
|
|
546
|
+
message: yup.string().test("message", t$1("neetoThankYou.thankYou.validations.messageRequired"), function (value) {
|
|
547
|
+
return allowEmptyCustomMessage || !isEditorEmpty(value);
|
|
548
|
+
}),
|
|
549
|
+
socialSharingEnabled: yup.bool(),
|
|
550
|
+
showResubmitLink: yup.bool(),
|
|
551
|
+
resubmitLinkText: yup.string().when("showResubmitLink", {
|
|
552
|
+
is: true,
|
|
553
|
+
then: yup.string().required(t$1("neetoThankYou.thankYou.validations.resubmitLinkTextIsRequired"))
|
|
554
|
+
}),
|
|
555
|
+
redirectUrl: yup.string().when("kind", {
|
|
556
|
+
is: FORM_OPTIONS.externalLink.kind,
|
|
557
|
+
then: yup.string().url(t$1("neetoThankYou.thankYou.validations.invalidLink")).required(t$1("neetoThankYou.thankYou.validations.invalidLink")).when("kind", {
|
|
558
|
+
is: FORM_OPTIONS.customize.kind,
|
|
559
|
+
then: yup.string()
|
|
560
|
+
})
|
|
561
|
+
})
|
|
562
|
+
});
|
|
563
|
+
};
|
|
564
|
+
|
|
556
565
|
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; }
|
|
557
566
|
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; }
|
|
558
567
|
var Form = function Form(_ref) {
|
|
@@ -571,7 +580,10 @@ var Form = function Form(_ref) {
|
|
|
571
580
|
appName = _ref.appName,
|
|
572
581
|
blockNavigation = _ref.blockNavigation,
|
|
573
582
|
onConfigUpdateSuccess = _ref.onConfigUpdateSuccess,
|
|
574
|
-
brandingInfo = _ref.brandingInfo
|
|
583
|
+
brandingInfo = _ref.brandingInfo,
|
|
584
|
+
editorProps = _ref.editorProps,
|
|
585
|
+
CustomPreview = _ref.preview,
|
|
586
|
+
allowEmptyCustomMessage = _ref.allowEmptyCustomMessage;
|
|
575
587
|
var _useShowThankYouConfi = useShowThankYouConfiguration({
|
|
576
588
|
entityId: entityId
|
|
577
589
|
}),
|
|
@@ -581,7 +593,7 @@ var Form = function Form(_ref) {
|
|
|
581
593
|
isLoading = _useShowThankYouConfi.isLoading;
|
|
582
594
|
var _useUpdateThankYouCon = useUpdateThankYouConfiguration(),
|
|
583
595
|
updateThankYouConfiguration = _useUpdateThankYouCon.mutate,
|
|
584
|
-
isUpdatingForm = _useUpdateThankYouCon.
|
|
596
|
+
isUpdatingForm = _useUpdateThankYouCon.isPending;
|
|
585
597
|
var editorRef = useRef({
|
|
586
598
|
editor: {}
|
|
587
599
|
});
|
|
@@ -599,7 +611,7 @@ var Form = function Form(_ref) {
|
|
|
599
611
|
formikProps: {
|
|
600
612
|
enableReinitialize: true,
|
|
601
613
|
initialValues: _objectSpread(_objectSpread({}, DEFAULT_IMAGE_PROPERTIES), thankYouConfiguration),
|
|
602
|
-
validationSchema:
|
|
614
|
+
validationSchema: buildValidationSchema(allowEmptyCustomMessage),
|
|
603
615
|
onSubmit: function onSubmit(values) {
|
|
604
616
|
return updateThankYouConfiguration({
|
|
605
617
|
entityId: entityId,
|
|
@@ -640,6 +652,7 @@ var Form = function Form(_ref) {
|
|
|
640
652
|
})
|
|
641
653
|
}), values.kind === FORM_OPTIONS.customize.kind ? /*#__PURE__*/jsx(Customize, {
|
|
642
654
|
disableSubmitAnotherResponse: disableSubmitAnotherResponse,
|
|
655
|
+
editorProps: editorProps,
|
|
643
656
|
editorRef: editorRef,
|
|
644
657
|
entityId: entityId,
|
|
645
658
|
hasImageUploader: hasImageUploader,
|
|
@@ -662,7 +675,9 @@ var Form = function Form(_ref) {
|
|
|
662
675
|
"data-cy": "neeto-thank-you-configuration-save-button"
|
|
663
676
|
}
|
|
664
677
|
})]
|
|
665
|
-
}), values.kind === FORM_OPTIONS.customize.kind && /*#__PURE__*/jsx(
|
|
678
|
+
}), values.kind === FORM_OPTIONS.customize.kind && (CustomPreview ? /*#__PURE__*/jsx(CustomPreview, {
|
|
679
|
+
values: values
|
|
680
|
+
}) : /*#__PURE__*/jsx(Preview, {
|
|
666
681
|
appName: appName,
|
|
667
682
|
brandingInfo: brandingInfo,
|
|
668
683
|
isPublished: isPublished,
|
|
@@ -670,7 +685,7 @@ var Form = function Form(_ref) {
|
|
|
670
685
|
resubmitLink: resubmitLink,
|
|
671
686
|
socialHandles: socialHandles,
|
|
672
687
|
thankYouTextAlignment: thankYouTextAlignment
|
|
673
|
-
})]
|
|
688
|
+
}))]
|
|
674
689
|
});
|
|
675
690
|
}
|
|
676
691
|
});
|
|
@@ -717,7 +732,12 @@ var ConfigureThankYou = function ConfigureThankYou(_ref) {
|
|
|
717
732
|
blockNavigation = _ref$blockNavigation === void 0 ? false : _ref$blockNavigation,
|
|
718
733
|
_ref$onConfigUpdateSu = _ref.onConfigUpdateSuccess,
|
|
719
734
|
onConfigUpdateSuccess = _ref$onConfigUpdateSu === void 0 ? noop : _ref$onConfigUpdateSu,
|
|
720
|
-
brandingInfo = _ref.brandingInfo
|
|
735
|
+
brandingInfo = _ref.brandingInfo,
|
|
736
|
+
_ref$editorProps = _ref.editorProps,
|
|
737
|
+
editorProps = _ref$editorProps === void 0 ? {} : _ref$editorProps,
|
|
738
|
+
preview = _ref.preview,
|
|
739
|
+
_ref$allowEmptyCustom = _ref.allowEmptyCustomMessage,
|
|
740
|
+
allowEmptyCustomMessage = _ref$allowEmptyCustom === void 0 ? false : _ref$allowEmptyCustom;
|
|
721
741
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
722
742
|
children: [customHeader || /*#__PURE__*/jsx(Header, {
|
|
723
743
|
breadcrumbs: breadcrumbs
|
|
@@ -726,15 +746,18 @@ var ConfigureThankYou = function ConfigureThankYou(_ref) {
|
|
|
726
746
|
children: /*#__PURE__*/jsx("div", {
|
|
727
747
|
className: "mx-auto h-full max-w-7xl",
|
|
728
748
|
children: /*#__PURE__*/jsx(Form, {
|
|
749
|
+
allowEmptyCustomMessage: allowEmptyCustomMessage,
|
|
729
750
|
appName: appName,
|
|
730
751
|
blockNavigation: blockNavigation,
|
|
731
752
|
brandingInfo: brandingInfo,
|
|
732
753
|
disableRadioSelection: disableRadioSelection,
|
|
733
754
|
disableSubmitAnotherResponse: disableSubmitAnotherResponse,
|
|
755
|
+
editorProps: editorProps,
|
|
734
756
|
entityId: entityId,
|
|
735
757
|
hasImageUploader: hasImageUploader,
|
|
736
758
|
isPublished: isPublished,
|
|
737
759
|
onConfigUpdateSuccess: onConfigUpdateSuccess,
|
|
760
|
+
preview: preview,
|
|
738
761
|
publicLinkId: publicLinkId,
|
|
739
762
|
redirectToOnCancel: redirectToOnCancel,
|
|
740
763
|
resubmitLink: resubmitLink,
|
|
@@ -766,11 +789,14 @@ var thankYouPageApi = {
|
|
|
766
789
|
var useShowThankYouPage = function useShowThankYouPage(_ref) {
|
|
767
790
|
var entityId = _ref.entityId,
|
|
768
791
|
isTemplateView = _ref.isTemplateView;
|
|
769
|
-
return useQuery(
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
792
|
+
return useQuery({
|
|
793
|
+
queryKey: [QUERY_KEYS.THANK_YOU_PAGE, entityId],
|
|
794
|
+
queryFn: function queryFn() {
|
|
795
|
+
return thankYouPageApi.show({
|
|
796
|
+
entityId: entityId,
|
|
797
|
+
isTemplateView: isTemplateView
|
|
798
|
+
});
|
|
799
|
+
}
|
|
774
800
|
});
|
|
775
801
|
};
|
|
776
802
|
|