@capillarytech/creatives-library 9.2.1-alpha.sprint-cap-214249.42 → 9.2.1
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/AppRoot.js +4 -7
- package/constants/unified.js +1 -0
- package/package.json +1 -1
- package/utils/beePluginLoader.js +106 -0
- package/utils/common.js +6 -0
- package/utils/createMobilePushPayload.js +51 -56
- package/utils/tests/beePluginLoader.test.js +199 -0
- package/utils/tests/createMobilePushPayload.test.js +10 -162
- package/v2Components/CapMpushCTA/index.js +57 -47
- package/v2Components/CapMpushCTA/index.scss +5 -43
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +8 -11
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
- package/v2Components/CommonTestAndPreview/constants.js +0 -2
- package/v2Components/CommonTestAndPreview/index.js +10 -48
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -83
- package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -86
- package/v2Components/TemplatePreview/_templatePreview.scss +2 -12
- package/v2Components/TemplatePreview/index.js +12 -14
- package/v2Components/TemplatePreview/tests/index.test.js +0 -69
- package/v2Containers/BeeEditor/index.js +49 -22
- package/v2Containers/BeeEditor/index.scss +12 -0
- package/v2Containers/BeeEditor/messages.js +8 -0
- package/v2Containers/BeeEditor/test/index.test.js +78 -0
- package/v2Containers/BeePopupEditor/index.js +22 -11
- package/v2Containers/CreativesContainer/SlideBoxContent.js +9 -5
- package/v2Containers/CreativesContainer/index.js +1 -2
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -43
- package/v2Containers/Email/index.js +2 -2
- package/v2Containers/EmailWrapper/hooks/useEmailWrapper.js +25 -23
- package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +222 -314
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +130 -161
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +123 -484
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +46 -152
- package/v2Containers/MobilePushNew/constants.js +0 -12
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -78
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -40
- package/v2Containers/MobilePushNew/hooks/useUpload.js +46 -42
- package/v2Containers/MobilePushNew/index.js +273 -503
- package/v2Containers/MobilePushNew/index.scss +4 -215
- package/v2Containers/MobilePushNew/messages.js +6 -106
- package/v2Containers/MobilePushNew/tests/index.test.js +1 -482
- package/v2Containers/MobilePushNew/tests/utils.test.js +0 -122
- package/v2Containers/MobilePushNew/utils.js +0 -107
- package/v2Containers/Templates/_templates.scss +2 -10
- package/v2Containers/Templates/index.js +81 -83
- package/v2Containers/Templates/tests/index.test.js +0 -68
- package/v2Components/CapMpushCTA/tests/index.test.js +0 -150
- package/v2Containers/MobilePushNew/components/TapLinkActions.js +0 -76
|
@@ -64,4 +64,12 @@ export default defineMessages({
|
|
|
64
64
|
id: `${prefix}.rowCreationFailureMgs`,
|
|
65
65
|
defaultMessage: 'Error in row creation',
|
|
66
66
|
},
|
|
67
|
+
beePluginLoadError: {
|
|
68
|
+
id: `${prefix}.beePluginLoadError`,
|
|
69
|
+
defaultMessage: 'Unable to load the drag & drop editor. Check your network connection and try again.',
|
|
70
|
+
},
|
|
71
|
+
retry: {
|
|
72
|
+
id: `${prefix}.retry`,
|
|
73
|
+
defaultMessage: 'Retry',
|
|
74
|
+
},
|
|
67
75
|
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '@testing-library/jest-dom';
|
|
3
|
+
import { render, screen, fireEvent, waitFor } from '../../../utils/test-utils';
|
|
4
|
+
import { initBeeEditor } from '../../../utils/beePluginLoader';
|
|
5
|
+
import BeeEditor from '../index';
|
|
6
|
+
|
|
7
|
+
// initBeeEditor's own load/start/cancel behaviour is covered in utils/tests/beePluginLoader.test.js
|
|
8
|
+
jest.mock('../../../utils/beePluginLoader', () => ({
|
|
9
|
+
...jest.requireActual('../../../utils/beePluginLoader'),
|
|
10
|
+
initBeeEditor: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
jest.mock('../../TagList', () => () => null);
|
|
14
|
+
|
|
15
|
+
const mockBeePluginInstance = { start: jest.fn(), destroy: jest.fn() };
|
|
16
|
+
|
|
17
|
+
const defaultProps = {
|
|
18
|
+
uid: 'test-uid',
|
|
19
|
+
id: 'bee-editor',
|
|
20
|
+
beeJson: '{"page":{}}',
|
|
21
|
+
tokenData: { access_token: 'token' },
|
|
22
|
+
saveBeeInstance: jest.fn(),
|
|
23
|
+
saveBeeData: jest.fn(),
|
|
24
|
+
tags: [],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const getInitOptions = () => initBeeEditor.mock.calls[initBeeEditor.mock.calls.length - 1][0];
|
|
28
|
+
|
|
29
|
+
describe('BeeEditor BeePlugin loading', () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
console.error.mockRestore();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('starts the BEE editor with its template and saves the instance', async () => {
|
|
39
|
+
initBeeEditor.mockResolvedValue(mockBeePluginInstance);
|
|
40
|
+
const { container } = render(<BeeEditor {...defaultProps} />);
|
|
41
|
+
|
|
42
|
+
await waitFor(() => expect(defaultProps.saveBeeInstance).toHaveBeenCalledWith(mockBeePluginInstance));
|
|
43
|
+
const { tokenData, getBeeJson, isCancelled } = getInitOptions();
|
|
44
|
+
expect(tokenData).toEqual(defaultProps.tokenData);
|
|
45
|
+
expect(getBeeJson()).toBe(defaultProps.beeJson);
|
|
46
|
+
expect(isCancelled()).toBe(false);
|
|
47
|
+
expect(container.querySelector('#bee-plugin-container')).toBeInTheDocument();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('shows an error with retry when the plugin script fails, and recovers on retry', async () => {
|
|
51
|
+
initBeeEditor
|
|
52
|
+
.mockRejectedValueOnce(new Error('Failed to load'))
|
|
53
|
+
.mockResolvedValueOnce(mockBeePluginInstance);
|
|
54
|
+
const { container } = render(<BeeEditor {...defaultProps} />);
|
|
55
|
+
|
|
56
|
+
expect(await screen.findByText(/Unable to load the drag & drop editor/)).toBeInTheDocument();
|
|
57
|
+
expect(container.querySelector('#bee-plugin-container')).not.toBeInTheDocument();
|
|
58
|
+
|
|
59
|
+
fireEvent.click(screen.getByRole('button', { name: 'Retry' }));
|
|
60
|
+
|
|
61
|
+
await waitFor(() => expect(defaultProps.saveBeeInstance).toHaveBeenCalledWith(mockBeePluginInstance));
|
|
62
|
+
expect(initBeeEditor).toHaveBeenCalledTimes(2);
|
|
63
|
+
expect(screen.queryByText(/Unable to load the drag & drop editor/)).not.toBeInTheDocument();
|
|
64
|
+
expect(container.querySelector('#bee-plugin-container')).toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('reports cancellation after unmount and saves nothing when no editor is returned', async () => {
|
|
68
|
+
let resolveInit;
|
|
69
|
+
initBeeEditor.mockReturnValue(new Promise((resolve) => { resolveInit = resolve; }));
|
|
70
|
+
const { unmount } = render(<BeeEditor {...defaultProps} />);
|
|
71
|
+
unmount();
|
|
72
|
+
|
|
73
|
+
expect(getInitOptions().isCancelled()).toBe(true);
|
|
74
|
+
resolveInit(null);
|
|
75
|
+
await Promise.resolve();
|
|
76
|
+
expect(defaultProps.saveBeeInstance).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -6,6 +6,7 @@ import { connect } from 'react-redux';
|
|
|
6
6
|
import { createStructuredSelector } from 'reselect';
|
|
7
7
|
import CapRow from '@capillarytech/cap-ui-library/CapRow';
|
|
8
8
|
import { UserIsAuthenticated } from '../../utils/authWrapper';
|
|
9
|
+
import { initBeeEditor } from '../../utils/beePluginLoader';
|
|
9
10
|
import TagList from '../TagList';
|
|
10
11
|
import {
|
|
11
12
|
ANDROID, BEE_LAYOUT_OPTIONS, MOBILE, UNSUBSCRIBE,
|
|
@@ -113,18 +114,28 @@ function BeePopupEditor(props) {
|
|
|
113
114
|
saveBeeData(jsonFile, htmlFile, device);
|
|
114
115
|
},
|
|
115
116
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
117
|
+
let isEffectCancelled = false;
|
|
118
|
+
initBeeEditor({
|
|
119
|
+
tokenData,
|
|
120
|
+
beeConfig,
|
|
121
|
+
// Read the ref at create time: the effect closure may hold stale beeJson when template data loads async
|
|
122
|
+
getBeeJson: () => beeJsonRef.current,
|
|
123
|
+
isCancelled: () => isEffectCancelled,
|
|
124
|
+
})
|
|
125
|
+
.then((instance) => {
|
|
126
|
+
if (!instance) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
beePluginInstance = instance;
|
|
130
|
+
beeInstanceRef.current = instance;
|
|
131
|
+
saveBeeInstance(beePluginInstance, device);
|
|
132
|
+
isInitializedRef.current = true;
|
|
133
|
+
})
|
|
134
|
+
.catch((error) => {
|
|
135
|
+
console.error('[BeePopupEditor] Error creating BEE plugin:', error);
|
|
136
|
+
});
|
|
127
137
|
return () => {
|
|
138
|
+
isEffectCancelled = true;
|
|
128
139
|
clearInterval(intervalTimer);
|
|
129
140
|
// Reset initialization flag when component unmounts or layout changes
|
|
130
141
|
isInitializedRef.current = false;
|
|
@@ -756,6 +756,8 @@ export function SlideBoxContent(props) {
|
|
|
756
756
|
const isBEETemplate = templateData?.base?.is_drag_drop === true
|
|
757
757
|
|| templateData?.base?.is_drag_drop === 1;
|
|
758
758
|
if (supportCKEditor || isBEETemplate) {
|
|
759
|
+
// Host-supplied BEE content is the latest edit; fetching by _id would reload the original template over it
|
|
760
|
+
const hasHostBEEContent = isBEETemplate && !isEmpty(templateData?.base?.json_content);
|
|
759
761
|
return (
|
|
760
762
|
<Email
|
|
761
763
|
key="cretives-container-email-edit"
|
|
@@ -767,7 +769,7 @@ export function SlideBoxContent(props) {
|
|
|
767
769
|
route={{ name: 'email' }}
|
|
768
770
|
isGetFormData={isGetFormData}
|
|
769
771
|
getFormdata={getFormData}
|
|
770
|
-
params={{ id: templateData._id }}
|
|
772
|
+
params={{ id: hasHostBEEContent ? undefined : templateData._id }}
|
|
771
773
|
templateData={templateData}
|
|
772
774
|
getFormSubscriptionData={getFormData}
|
|
773
775
|
getDefaultTags={type}
|
|
@@ -846,7 +848,9 @@ export function SlideBoxContent(props) {
|
|
|
846
848
|
})()
|
|
847
849
|
)}
|
|
848
850
|
{isEditMPush && (
|
|
849
|
-
|
|
851
|
+
(isFullMode && !commonUtil.hasNewMobilePushFeatureEnabled()) ||
|
|
852
|
+
(!isFullMode && isLoyaltyModule) ||
|
|
853
|
+
(!isFullMode && !isLoyaltyModule && !commonUtil.hasNewMobilePushFeatureEnabled()) ? (
|
|
850
854
|
<MobliPushEdit
|
|
851
855
|
getFormLibraryData={getFormData}
|
|
852
856
|
setIsLoadingContent={setIsLoadingContent}
|
|
@@ -908,8 +912,6 @@ export function SlideBoxContent(props) {
|
|
|
908
912
|
waitEventContextTags={waitEventContextTags}
|
|
909
913
|
showLiquidErrorInFooter={showLiquidErrorInFooter}
|
|
910
914
|
handleClose={handleClose}
|
|
911
|
-
showTestAndPreviewSlidebox={showTestAndPreviewSlidebox}
|
|
912
|
-
handleCloseTestAndPreview={handleCloseTestAndPreview}
|
|
913
915
|
restrictPersonalization={restrictPersonalization}
|
|
914
916
|
isAnonymousType={isAnonymousType}
|
|
915
917
|
onPersonalizationTokensChange={onPersonalizationTokensChange}
|
|
@@ -918,7 +920,9 @@ export function SlideBoxContent(props) {
|
|
|
918
920
|
)
|
|
919
921
|
)}
|
|
920
922
|
{isCreateMPush && (
|
|
921
|
-
|
|
923
|
+
(isFullMode && !commonUtil.hasNewMobilePushFeatureEnabled()) ||
|
|
924
|
+
(!isFullMode && isLoyaltyModule) ||
|
|
925
|
+
(!isFullMode && !isLoyaltyModule && !commonUtil.hasNewMobilePushFeatureEnabled()) ? (
|
|
922
926
|
<MobilepushWrapper
|
|
923
927
|
key="creatives-mobilepush-wrapper"
|
|
924
928
|
date={new Date().getMilliseconds()}
|
|
@@ -1042,8 +1042,7 @@ export class Creatives extends React.Component {
|
|
|
1042
1042
|
newExpandableDetails.message = expandableDetails.message || '';
|
|
1043
1043
|
newExpandableDetails.ctas = expandableDetails.ctas || [];
|
|
1044
1044
|
newExpandableDetails.media = expandableDetails.carouselData.map((carousel) => ({
|
|
1045
|
-
|
|
1046
|
-
url: carousel?.mediaType?.toUpperCase() === VIDEO ? carousel.videoSrc : carousel.imageUrl,
|
|
1045
|
+
url: carousel.imageUrl,
|
|
1047
1046
|
type: carousel?.mediaType?.toUpperCase(),
|
|
1048
1047
|
text: '',
|
|
1049
1048
|
}));
|
|
@@ -4,9 +4,6 @@ import { SlideBoxContent } from '../SlideBoxContent';
|
|
|
4
4
|
import mockdata from '../../mockdata';
|
|
5
5
|
import { templateDetailsImage, templateDetailsVideo, templateDetailsText, templateDetails_ } from '../../Viber/tests/mockData';
|
|
6
6
|
import { CREATE, RICH_MEDIA } from '../../WeChat/Wrapper/constants';
|
|
7
|
-
import MobilePushNew from '../../MobilePushNew';
|
|
8
|
-
import MobilepushWrapper from '../../MobilepushWrapper';
|
|
9
|
-
import MobliPushEdit from '../../MobilePush/Edit';
|
|
10
7
|
|
|
11
8
|
const {
|
|
12
9
|
whatsappEditTemplateData,
|
|
@@ -1018,44 +1015,4 @@ describe('Test SlideBoxContent container', () => {
|
|
|
1018
1015
|
});
|
|
1019
1016
|
|
|
1020
1017
|
});
|
|
1021
|
-
|
|
1022
|
-
describe('Mobile push editor choice', () => {
|
|
1023
|
-
const editTemplateData = { _id: 'mp-1', type: 'MOBILEPUSH' };
|
|
1024
|
-
|
|
1025
|
-
it.each([
|
|
1026
|
-
['full mode', { isFullMode: true }],
|
|
1027
|
-
['embedded outside Loyalty', { isFullMode: false, isLoyaltyModule: false }],
|
|
1028
|
-
])('opens the new editor for create and edit in %s', (_, modeProps) => {
|
|
1029
|
-
renderFunction('MOBILEPUSH', 'createTemplate', { mode: 'create' }, modeProps);
|
|
1030
|
-
expect(renderedComponent.find(MobilePushNew).exists()).toBe(true);
|
|
1031
|
-
expect(renderedComponent.find(MobilepushWrapper).exists()).toBe(false);
|
|
1032
|
-
|
|
1033
|
-
renderFunction('MOBILEPUSH', 'editTemplate', editTemplateData, modeProps);
|
|
1034
|
-
expect(renderedComponent.find(MobilePushNew).exists()).toBe(true);
|
|
1035
|
-
expect(renderedComponent.find(MobliPushEdit).exists()).toBe(false);
|
|
1036
|
-
});
|
|
1037
|
-
|
|
1038
|
-
it('passes the footer Test & Preview state to the new editor in edit', () => {
|
|
1039
|
-
const handleCloseTestAndPreview = jest.fn();
|
|
1040
|
-
renderFunction('MOBILEPUSH', 'editTemplate', editTemplateData, {
|
|
1041
|
-
isFullMode: true,
|
|
1042
|
-
showTestAndPreviewSlidebox: true,
|
|
1043
|
-
handleCloseTestAndPreview,
|
|
1044
|
-
});
|
|
1045
|
-
const editor = renderedComponent.find(MobilePushNew);
|
|
1046
|
-
expect(editor.prop('showTestAndPreviewSlidebox')).toBe(true);
|
|
1047
|
-
expect(editor.prop('handleCloseTestAndPreview')).toBe(handleCloseTestAndPreview);
|
|
1048
|
-
});
|
|
1049
|
-
|
|
1050
|
-
it('keeps the old editor when embedded in Loyalty', () => {
|
|
1051
|
-
const loyaltyProps = { isFullMode: false, isLoyaltyModule: true };
|
|
1052
|
-
renderFunction('MOBILEPUSH', 'createTemplate', { mode: 'create' }, loyaltyProps);
|
|
1053
|
-
expect(renderedComponent.find(MobilepushWrapper).exists()).toBe(true);
|
|
1054
|
-
expect(renderedComponent.find(MobilePushNew).exists()).toBe(false);
|
|
1055
|
-
|
|
1056
|
-
renderFunction('MOBILEPUSH', 'editTemplate', editTemplateData, loyaltyProps);
|
|
1057
|
-
expect(renderedComponent.find(MobliPushEdit).exists()).toBe(true);
|
|
1058
|
-
expect(renderedComponent.find(MobilePushNew).exists()).toBe(false);
|
|
1059
|
-
});
|
|
1060
|
-
});
|
|
1061
1018
|
});
|
|
@@ -580,7 +580,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
580
580
|
const beeJson = `BEEeditor${currentTab > 1 ? currentTab : ''}json`;
|
|
581
581
|
const beeToken = `BEEeditor${currentTab > 1 ? currentTab : ''}token`;
|
|
582
582
|
let beeJsonValue = '';
|
|
583
|
-
const selectedId = _.get(
|
|
583
|
+
const selectedId = _.get(nextProps, 'Email.templateDetails._id', '') || '';
|
|
584
584
|
|
|
585
585
|
// Get beeJsonValue from template data - check multiple sources
|
|
586
586
|
// First check if it's already in formData (from setEditData)
|
|
@@ -637,7 +637,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
637
637
|
is_drag_drop: true,
|
|
638
638
|
[beeJson]: finalBeeJsonValue,
|
|
639
639
|
[beeToken]: nextProps.Email.CmsSettings.tokenData,
|
|
640
|
-
id: selectedId,
|
|
640
|
+
id: selectedId || existingFormData.id,
|
|
641
641
|
// Also store json-content for reference
|
|
642
642
|
'json-content': finalBeeJsonValue,
|
|
643
643
|
};
|
|
@@ -83,6 +83,8 @@ const useEmailWrapper = ({
|
|
|
83
83
|
pathname: `/email/create`,
|
|
84
84
|
query: { module: 'library', type: 'embedded' },
|
|
85
85
|
});
|
|
86
|
+
// On create, `location` is the host app's route (e.g. a promotion /edit/:id URL), so it must not mark the email as an edit
|
|
87
|
+
const routeLocation = isEditEmail ? location : undefined;
|
|
86
88
|
|
|
87
89
|
// Cleanup effect
|
|
88
90
|
useEffect(() => () => {
|
|
@@ -155,7 +157,7 @@ const useEmailWrapper = ({
|
|
|
155
157
|
}
|
|
156
158
|
|
|
157
159
|
// Check if we're in edit mode (need to check BEE status for editor selection)
|
|
158
|
-
const hasParamsId = params?.id ||
|
|
160
|
+
const hasParamsId = params?.id || routeLocation?.query?.id || routeLocation?.params?.id || routeLocation?.pathname?.includes('/edit/');
|
|
159
161
|
const isEditMode = hasParamsId;
|
|
160
162
|
|
|
161
163
|
// Only check BEE enabled status for new flow (when supportCKEditor is false)
|
|
@@ -173,7 +175,7 @@ const useEmailWrapper = ({
|
|
|
173
175
|
// Make API call to check BEE enabled status using new endpoint
|
|
174
176
|
emailActions.getCmsAccounts('BEE_PLUGIN');
|
|
175
177
|
}
|
|
176
|
-
}, [currentStep, emailActions, params?.id,
|
|
178
|
+
}, [currentStep, emailActions, params?.id, routeLocation?.query?.id, routeLocation?.params?.id, routeLocation?.pathname]);
|
|
177
179
|
|
|
178
180
|
// Effect to update isBeeEditorEnabled based on new API response
|
|
179
181
|
// This effect watches for isBeeEnabled from the new API response
|
|
@@ -205,23 +207,23 @@ const useEmailWrapper = ({
|
|
|
205
207
|
if (!isEditEmail) {
|
|
206
208
|
return;
|
|
207
209
|
}
|
|
208
|
-
const hasParamsId = params?.id ||
|
|
210
|
+
const hasParamsId = params?.id || routeLocation?.query?.id || routeLocation?.params?.id || routeLocation?.pathname?.includes('/edit/');
|
|
209
211
|
const hasTemplateDetails = Email?.templateDetails && !isEmpty(Email.templateDetails);
|
|
210
212
|
const hasTemplateDataProp = templateData && !isEmpty(templateData);
|
|
211
213
|
const isTemplateLoading = Email?.getTemplateDetailsInProgress;
|
|
212
214
|
|
|
213
215
|
// Only fetch if we have an ID, don't have template data yet, and not already loading
|
|
214
216
|
if (hasParamsId && !hasTemplateDetails && !hasTemplateDataProp && !isTemplateLoading && emailActions?.getTemplateDetails) {
|
|
215
|
-
let templateId = params?.id ||
|
|
216
|
-
if (!templateId &&
|
|
217
|
-
const [, extractedId] =
|
|
217
|
+
let templateId = params?.id || routeLocation?.query?.id || routeLocation?.params?.id;
|
|
218
|
+
if (!templateId && routeLocation?.pathname?.includes('/edit/')) {
|
|
219
|
+
const [, extractedId] = routeLocation.pathname.match(/\/edit\/([^/]+)/) || [];
|
|
218
220
|
if (extractedId) templateId = extractedId;
|
|
219
221
|
}
|
|
220
222
|
if (templateId) {
|
|
221
223
|
emailActions.getTemplateDetails(templateId, 'email');
|
|
222
224
|
}
|
|
223
225
|
}
|
|
224
|
-
}, [isEditEmail, params?.id,
|
|
226
|
+
}, [isEditEmail, params?.id, routeLocation?.query?.id, routeLocation?.params?.id, routeLocation?.pathname, Email?.templateDetails, Email?.getTemplateDetailsInProgress, templateData, emailActions]);
|
|
225
227
|
|
|
226
228
|
// Effect to set BEETemplate when template details are loaded for BEE templates
|
|
227
229
|
// This ensures Email component can properly initialize BEE editor
|
|
@@ -279,9 +281,9 @@ const useEmailWrapper = ({
|
|
|
279
281
|
const isBEEAppEnable = checkBeeEditorEnabled();
|
|
280
282
|
// Check if we're in edit mode - check multiple sources for id
|
|
281
283
|
const hasParamsId = params?.id
|
|
282
|
-
||
|
|
283
|
-
||
|
|
284
|
-
|| (
|
|
284
|
+
|| routeLocation?.query?.id
|
|
285
|
+
|| routeLocation?.params?.id
|
|
286
|
+
|| (routeLocation?.pathname && routeLocation.pathname.includes('/edit/'));
|
|
285
287
|
const cmsMode = hasParamsId ? 'open' : 'create';
|
|
286
288
|
// Extract langId from active tab
|
|
287
289
|
const activeTabForLang = get(editTemplateData, 'versions.base.activeTab', 'en');
|
|
@@ -546,9 +548,9 @@ const useEmailWrapper = ({
|
|
|
546
548
|
useEffect(() => {
|
|
547
549
|
// If templateData is cleared/null and we're not in edit mode, reset selectedCreateMode
|
|
548
550
|
const hasParamsId = params?.id
|
|
549
|
-
||
|
|
550
|
-
||
|
|
551
|
-
||
|
|
551
|
+
|| routeLocation?.query?.id
|
|
552
|
+
|| routeLocation?.params?.id
|
|
553
|
+
|| routeLocation?.pathname?.includes('/edit/');
|
|
552
554
|
const hasTemplateData = templateData && !isEmpty(templateData);
|
|
553
555
|
const isEditMode = hasParamsId || hasTemplateData;
|
|
554
556
|
|
|
@@ -561,7 +563,7 @@ const useEmailWrapper = ({
|
|
|
561
563
|
// This preserves user selection while in content creation
|
|
562
564
|
setSelectedCreateMode('');
|
|
563
565
|
}
|
|
564
|
-
}, [templateData, params?.id,
|
|
566
|
+
}, [templateData, params?.id, routeLocation?.query?.id, routeLocation?.params?.id, routeLocation?.pathname, selectedCreateMode, templateName, currentStep, emailCreateMode]);
|
|
565
567
|
|
|
566
568
|
// Derived state
|
|
567
569
|
const supportCKEditorFlag = hasSupportCKEditor();
|
|
@@ -589,7 +591,7 @@ const useEmailWrapper = ({
|
|
|
589
591
|
// Check if we're editing an existing template
|
|
590
592
|
// CRITICAL: Only treat as edit mode if we have params.id (actual edit URL) or templateData prop
|
|
591
593
|
// Don't use templateDetails existence alone, as it might persist from previous template
|
|
592
|
-
const hasParamsId = params?.id ||
|
|
594
|
+
const hasParamsId = params?.id || routeLocation?.query?.id || routeLocation?.params?.id || routeLocation?.pathname?.includes('/edit/');
|
|
593
595
|
const hasTemplateDataProp = templateData && !isEmpty(templateData);
|
|
594
596
|
// CRITICAL: Consider it edit mode if we have params.id OR templateData prop (library mode)
|
|
595
597
|
// This allows editor type determination even when template data is still loading
|
|
@@ -706,13 +708,13 @@ const useEmailWrapper = ({
|
|
|
706
708
|
const emailParams = {};
|
|
707
709
|
if (params?.id) {
|
|
708
710
|
emailParams.id = params.id;
|
|
709
|
-
} else if (
|
|
710
|
-
emailParams.id =
|
|
711
|
-
} else if (
|
|
712
|
-
emailParams.id =
|
|
713
|
-
} else if (
|
|
711
|
+
} else if (routeLocation?.query?.id) {
|
|
712
|
+
emailParams.id = routeLocation.query.id;
|
|
713
|
+
} else if (routeLocation?.params?.id) {
|
|
714
|
+
emailParams.id = routeLocation.params.id;
|
|
715
|
+
} else if (routeLocation?.pathname?.includes('/edit/')) {
|
|
714
716
|
// Extract id from pathname if it's in the format /edit/:id
|
|
715
|
-
const match =
|
|
717
|
+
const match = routeLocation.pathname.match(/\/edit\/([^/]+)/);
|
|
716
718
|
// Reject sentinel strings that come from unguarded template literals
|
|
717
719
|
// (e.g. `/edit/${maybeUndefined}` → "/edit/undefined"), so they don't
|
|
718
720
|
// get treated as real template ids downstream.
|
|
@@ -800,7 +802,7 @@ const useEmailWrapper = ({
|
|
|
800
802
|
// Check if we're in edit mode (templateDetails or BEETemplate exists, or params.id exists)
|
|
801
803
|
const hasTemplateDetails = Email?.templateDetails && !isEmpty(Email.templateDetails);
|
|
802
804
|
const hasBEETemplate = Email?.BEETemplate && !isEmpty(Email.BEETemplate);
|
|
803
|
-
const hasParamsId = params?.id ||
|
|
805
|
+
const hasParamsId = params?.id || routeLocation?.query?.id || routeLocation?.params?.id || routeLocation?.pathname?.includes('/edit/');
|
|
804
806
|
const isEditMode = hasTemplateDetails || hasBEETemplate || hasParamsId;
|
|
805
807
|
|
|
806
808
|
// In edit mode (when supportCKEditor is false), always show editor
|
|
@@ -842,7 +844,7 @@ const useEmailWrapper = ({
|
|
|
842
844
|
|
|
843
845
|
// For Editor: Show editor when template is selected
|
|
844
846
|
return !isEmpty(SelectedEdmDefaultTemplate);
|
|
845
|
-
}, [currentStep, selectedCreateMode, supportCKEditorFlag, emailCreateMode, EmailLayout, SelectedEdmDefaultTemplate, Email?.templateDetails, Email?.BEETemplate, params?.id,
|
|
847
|
+
}, [currentStep, selectedCreateMode, supportCKEditorFlag, emailCreateMode, EmailLayout, SelectedEdmDefaultTemplate, Email?.templateDetails, Email?.BEETemplate, params?.id, routeLocation?.query?.id, routeLocation?.params?.id, routeLocation?.pathname, emailProps?.editor, emailProps?.selectedEditorMode]);
|
|
846
848
|
|
|
847
849
|
// Memoize static data
|
|
848
850
|
const modes = useMemo(() => {
|
|
@@ -5,20 +5,16 @@ import CapRow from "@capillarytech/cap-ui-library/CapRow";
|
|
|
5
5
|
import CapButton from "@capillarytech/cap-ui-library/CapButton";
|
|
6
6
|
import CapIcon from "@capillarytech/cap-ui-library/CapIcon";
|
|
7
7
|
import CapHeading from "@capillarytech/cap-ui-library/CapHeading";
|
|
8
|
-
import
|
|
9
|
-
// import CapTooltip from "@capillarytech/cap-ui-library/CapTooltip";
|
|
8
|
+
import CapTooltip from "@capillarytech/cap-ui-library/CapTooltip";
|
|
10
9
|
import CapMpushCTA from "../../../v2Components/CapMpushCTA";
|
|
11
|
-
import { PRIMARY, DEEP_LINK } from "../constants";
|
|
12
|
-
// import { SECONDARY } from "../constants";
|
|
10
|
+
import { PRIMARY, SECONDARY, DEEP_LINK } from "../constants";
|
|
13
11
|
import messages from "../messages";
|
|
14
12
|
|
|
15
|
-
// Secondary button is commented out below: it needs backend support, so it is being revamped.
|
|
16
|
-
// Restore the commented secondaryButton / setSecondaryButton props, state, handler and JSX together.
|
|
17
13
|
const CtaButtons = ({
|
|
18
14
|
primaryButton,
|
|
19
|
-
|
|
15
|
+
secondaryButton,
|
|
20
16
|
setPrimaryButton,
|
|
21
|
-
|
|
17
|
+
setSecondaryButton,
|
|
22
18
|
ctaData,
|
|
23
19
|
updateHandler,
|
|
24
20
|
deleteHandler,
|
|
@@ -31,7 +27,7 @@ const CtaButtons = ({
|
|
|
31
27
|
}) => {
|
|
32
28
|
// Local state to control CTA form visibility
|
|
33
29
|
const [showPrimaryCTA, setShowPrimaryCTA] = useState(false);
|
|
34
|
-
|
|
30
|
+
const [showSecondaryCTA, setShowSecondaryCTA] = useState(false);
|
|
35
31
|
|
|
36
32
|
const handleAddPrimary = () => {
|
|
37
33
|
// Prevent multiple clicks if primary button is already being added or form is already showing
|
|
@@ -57,67 +53,68 @@ const CtaButtons = ({
|
|
|
57
53
|
setShowPrimaryCTA(true);
|
|
58
54
|
};
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
56
|
+
const handleAddSecondary = () => {
|
|
57
|
+
// Prevent multiple clicks if secondary button is already being added or form is already showing
|
|
58
|
+
//cooment until supported from BE & Hydra
|
|
59
|
+
// if (secondaryButton && showSecondaryCTA) {
|
|
60
|
+
// return;
|
|
61
|
+
// }
|
|
62
|
+
|
|
63
|
+
// if (shouldShowSecondaryCTA) {
|
|
64
|
+
// return;
|
|
65
|
+
// }
|
|
66
|
+
|
|
67
|
+
// If ctaData doesn't have a secondary button, initialize it
|
|
68
|
+
if (ctaData?.length < 2 || !ctaData?.find((cta) => cta?.index === 1)) {
|
|
69
|
+
const newSecondaryButton = {
|
|
70
|
+
index: 1,
|
|
71
|
+
ctaType: SECONDARY,
|
|
72
|
+
text: "",
|
|
73
|
+
urlType: DEEP_LINK,
|
|
74
|
+
url: "",
|
|
75
|
+
deepLinkKeys: "",
|
|
76
|
+
isSaved: false,
|
|
77
|
+
};
|
|
78
|
+
updateHandler(newSecondaryButton, 1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// setSecondaryButton(true);
|
|
82
|
+
// setShowSecondaryCTA(true);
|
|
83
|
+
};
|
|
80
84
|
|
|
81
85
|
// Check if primary button exists (saved or being edited)
|
|
82
86
|
const primaryButtonExists = ctaData?.length > 0 && ctaData[0]?.text;
|
|
83
87
|
const isPrimaryButtonSaved = primaryButtonExists && ctaData[0]?.isSaved;
|
|
84
88
|
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
// Check if secondary button exists (saved or being edited)
|
|
90
|
+
const secondaryButtonExists = ctaData?.length > 1 && ctaData[1]?.text;
|
|
91
|
+
const isSecondaryButtonSaved = secondaryButtonExists && ctaData[1]?.isSaved;
|
|
88
92
|
|
|
89
93
|
// Show primary CTA if button is active and (form is showing OR button exists)
|
|
90
94
|
const shouldShowPrimaryCTA = primaryButton && (showPrimaryCTA || primaryButtonExists);
|
|
91
95
|
|
|
92
|
-
//
|
|
93
|
-
|
|
96
|
+
// Show secondary CTA if button is active and (form is showing OR button exists)
|
|
97
|
+
const shouldShowSecondaryCTA = secondaryButton && (showSecondaryCTA || secondaryButtonExists);
|
|
94
98
|
|
|
95
99
|
// Enhanced delete handler to hide forms when buttons are deleted
|
|
96
100
|
const handleDelete = (index) => {
|
|
97
101
|
if (index === 0) {
|
|
98
102
|
setShowPrimaryCTA(false);
|
|
99
103
|
setPrimaryButton(false);
|
|
104
|
+
} else if (index === 1) {
|
|
105
|
+
//cooment until supported from BE & Hydra
|
|
106
|
+
// setShowSecondaryCTA(false);
|
|
107
|
+
// setSecondaryButton(false);
|
|
100
108
|
}
|
|
101
|
-
// Secondary button: needs backend support, revamped
|
|
102
|
-
// else if (index === 1) {
|
|
103
|
-
// setShowSecondaryCTA(false);
|
|
104
|
-
// setSecondaryButton(false);
|
|
105
|
-
// }
|
|
106
109
|
deleteHandler(index);
|
|
107
110
|
};
|
|
108
111
|
|
|
109
112
|
return (
|
|
110
113
|
<>
|
|
111
114
|
<CapRow className="mpush-cta-buttons">
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
<FormattedMessage {...messages.buttons} />
|
|
116
|
-
</CapHeading>
|
|
117
|
-
<CapLabel className="optional-text">
|
|
118
|
-
<FormattedMessage {...messages.optionalText} />
|
|
119
|
-
</CapLabel>
|
|
120
|
-
</CapRow>
|
|
115
|
+
<CapHeading type="h3">
|
|
116
|
+
<FormattedMessage {...messages.buttons} />
|
|
117
|
+
</CapHeading>
|
|
121
118
|
{!isPrimaryButtonSaved && !shouldShowPrimaryCTA && (
|
|
122
119
|
<CapButton
|
|
123
120
|
type="link"
|
|
@@ -145,7 +142,6 @@ const CtaButtons = ({
|
|
|
145
142
|
handleOnTagsContextChange={handleOnTagsContextChange}
|
|
146
143
|
/>
|
|
147
144
|
)}
|
|
148
|
-
{/* Secondary button: needs backend support, so it is being revamped. Hidden until then.
|
|
149
145
|
{isPrimaryButtonSaved && !isSecondaryButtonSaved && !shouldShowSecondaryCTA && (
|
|
150
146
|
<CapTooltip
|
|
151
147
|
overlay={<FormattedMessage {...messages.secondaryButtonTooltip} />}
|
|
@@ -175,16 +171,15 @@ const CtaButtons = ({
|
|
|
175
171
|
buttonType={SECONDARY}
|
|
176
172
|
/>
|
|
177
173
|
)}
|
|
178
|
-
*/}
|
|
179
174
|
</>
|
|
180
175
|
);
|
|
181
176
|
};
|
|
182
177
|
|
|
183
178
|
CtaButtons.propTypes = {
|
|
184
179
|
primaryButton: PropTypes.bool.isRequired,
|
|
185
|
-
|
|
180
|
+
secondaryButton: PropTypes.bool.isRequired,
|
|
186
181
|
setPrimaryButton: PropTypes.func.isRequired,
|
|
187
|
-
|
|
182
|
+
setSecondaryButton: PropTypes.func.isRequired,
|
|
188
183
|
ctaData: PropTypes.array.isRequired,
|
|
189
184
|
updateHandler: PropTypes.func.isRequired,
|
|
190
185
|
deleteHandler: PropTypes.func.isRequired,
|