@capillarytech/creatives-library 9.2.2 → 9.2.4-alpha.feature-rcs-multi-account.51

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 (60) hide show
  1. package/constants/unified.js +0 -1
  2. package/package.json +1 -1
  3. package/utils/common.js +0 -6
  4. package/utils/createMobilePushPayload.js +50 -56
  5. package/utils/tests/createMobilePushPayload.test.js +177 -168
  6. package/v2Components/CapMpushCTA/index.js +47 -57
  7. package/v2Components/CapMpushCTA/index.scss +43 -5
  8. package/v2Components/CapMpushCTA/tests/index.test.js +150 -0
  9. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +11 -8
  10. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
  11. package/v2Components/CommonTestAndPreview/constants.js +2 -0
  12. package/v2Components/CommonTestAndPreview/index.js +59 -14
  13. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +83 -5
  14. package/v2Components/CommonTestAndPreview/tests/index.test.js +158 -0
  15. package/v2Components/MobilePushPreviewV2/_mobilePushPreviewV2.scss +7 -0
  16. package/v2Components/MobilePushPreviewV2/index.js +22 -9
  17. package/v2Components/MobilePushPreviewV2/tests/index.test.js +55 -0
  18. package/v2Components/TemplatePreview/_mobilePushPhone.scss +72 -0
  19. package/v2Components/TemplatePreview/_templatePreview.scss +18 -2
  20. package/v2Components/TemplatePreview/index.js +20 -18
  21. package/v2Components/TemplatePreview/tests/index.test.js +69 -0
  22. package/v2Components/TestAndPreviewSlidebox/index.js +2 -0
  23. package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/Tests/extractContentForPreview.test.js +45 -0
  24. package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/extractContentForPreview.js +12 -2
  25. package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/DeliverySettingsSection.js +16 -3
  26. package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/SenderDetails.js +7 -2
  27. package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/deliverySettingsConfig.test.js +44 -0
  28. package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/deliverySettingsConfig.js +21 -8
  29. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -6
  30. package/v2Containers/CreativesContainer/index.js +18 -1
  31. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +43 -0
  32. package/v2Containers/CreativesContainer/tests/index.test.js +66 -0
  33. package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
  34. package/v2Containers/MobilePushNew/components/MediaUploaders.js +105 -345
  35. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +127 -105
  36. package/v2Containers/MobilePushNew/components/TapLinkActions.js +76 -0
  37. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
  38. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +305 -1482
  39. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +165 -59
  40. package/v2Containers/MobilePushNew/constants.js +12 -0
  41. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  42. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +78 -0
  43. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
  44. package/v2Containers/MobilePushNew/hooks/useUpload.js +42 -46
  45. package/v2Containers/MobilePushNew/index.js +498 -289
  46. package/v2Containers/MobilePushNew/index.scss +151 -4
  47. package/v2Containers/MobilePushNew/messages.js +106 -6
  48. package/v2Containers/MobilePushNew/tests/index.test.js +483 -1
  49. package/v2Containers/MobilePushNew/tests/utils.test.js +110 -0
  50. package/v2Containers/MobilePushNew/utils.js +83 -0
  51. package/v2Containers/Rcs/accountUtils.js +20 -0
  52. package/v2Containers/Rcs/index.js +18 -1
  53. package/v2Containers/Rcs/tests/accountUtils.test.js +24 -0
  54. package/v2Containers/Rcs/tests/index.test.js +23 -0
  55. package/v2Containers/Templates/ChannelTypeIllustration.js +12 -0
  56. package/v2Containers/Templates/_templates.scss +10 -2
  57. package/v2Containers/Templates/index.js +94 -85
  58. package/v2Containers/Templates/messages.js +4 -0
  59. package/v2Containers/Templates/tests/ChannelTypeIllustration.test.js +14 -2
  60. package/v2Containers/Templates/tests/index.test.js +182 -0
@@ -92,6 +92,7 @@ import { IMAGE, VIDEO } from '../Facebook/Advertisement/constant';
92
92
  import { RCS_STATUSES, contentType as RCS_CONTENT_TYPE, EMBEDDED } from '../Rcs/constants';
93
93
  import { pickRcsCardVarMappedEntries } from '../Rcs/rcsLibraryHydrationUtils';
94
94
  import { mapRcsCardContentForConsumerWithResolvedTags } from '../Rcs/utils';
95
+ import { isRcsAccountForAccountId } from '../Rcs/accountUtils';
95
96
  import { RCS_SMS_FALLBACK_VAR_MAPPED_PROP } from '../../v2Components/CommonTestAndPreview/constants';
96
97
  import { CREATIVE } from '../Facebook/constants';
97
98
  import { LOYALTY } from '../App/constants';
@@ -1042,7 +1043,8 @@ export class Creatives extends React.Component {
1042
1043
  newExpandableDetails.message = expandableDetails.message || '';
1043
1044
  newExpandableDetails.ctas = expandableDetails.ctas || [];
1044
1045
  newExpandableDetails.media = expandableDetails.carouselData.map((carousel) => ({
1045
- url: carousel.imageUrl,
1046
+ // Video cards keep their url in videoSrc
1047
+ url: carousel?.mediaType?.toUpperCase() === VIDEO ? carousel.videoSrc : carousel.imageUrl,
1046
1048
  type: carousel?.mediaType?.toUpperCase(),
1047
1049
  text: '',
1048
1050
  }));
@@ -1479,11 +1481,26 @@ export class Creatives extends React.Component {
1479
1481
  cardVarMappedFromFirstRcsCard
1480
1482
  && Object.keys(cardVarMappedFromFirstRcsCard).length > 0
1481
1483
  && isFullModeForRcsConsumerPayload === true;
1484
+ // Multi-account (same contract as WhatsApp): tell the consumer which RCS account the template
1485
+ // belongs to. Use the selected account only when it is the one the template was saved with;
1486
+ // otherwise keep what the consumer passed in, so a stale selection never re-tags a template.
1487
+ const { Templates: templatesForRcsAccount, templateData: rcsTemplateDataProps } = this.props;
1488
+ const selectedRcsAccount = templatesForRcsAccount?.selectedRcsAccount;
1489
+ const isSelectedRcsAccountForTemplate = !isEmpty(selectedRcsAccount)
1490
+ && (!accountId || isRcsAccountForAccountId(selectedRcsAccount, accountId));
1491
+ const rcsSourceAccountIdentifier = isSelectedRcsAccountForTemplate
1492
+ ? (selectedRcsAccount?.sourceAccountIdentifier || '')
1493
+ : (rcsTemplateDataProps?.sourceAccountIdentifier || rcsTemplateDataProps?.accountDetails?.sourceAccountIdentifier || '');
1494
+ const rcsAccountName = isSelectedRcsAccountForTemplate
1495
+ ? (selectedRcsAccount?.name || '')
1496
+ : (rcsTemplateDataProps?.accountName || rcsTemplateDataProps?.accountDetails?.name || '');
1482
1497
  templateData = {
1483
1498
  channel,
1484
1499
  creativeName: name,
1485
1500
  rcsContent,
1486
1501
  accountId,
1502
+ ...(rcsSourceAccountIdentifier && { sourceAccountIdentifier: rcsSourceAccountIdentifier }),
1503
+ ...(rcsAccountName && { accountName: rcsAccountName }),
1487
1504
  ...(vfTemplateId && { templateId: vfTemplateId }),
1488
1505
  ...(includeRootRcsCardVarMappedOnConsumerPayload
1489
1506
  ? { rcsCardVarMapped: cardVarMappedFromFirstRcsCard }
@@ -4,6 +4,9 @@ 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';
7
10
 
8
11
  const {
9
12
  whatsappEditTemplateData,
@@ -1015,4 +1018,44 @@ describe('Test SlideBoxContent container', () => {
1015
1018
  });
1016
1019
 
1017
1020
  });
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
+ });
1018
1061
  });
@@ -250,6 +250,72 @@ describe('Test SlideBoxContent container', () => {
250
250
  expect(instance.state.templateData.smsFallBackContent).toEqual({ message: 'fallback-body' });
251
251
  });
252
252
 
253
+ describe('RCS multi-account fields on consumer templateData', () => {
254
+ const rcsAccountA = { id: 101, name: 'Brand A', sourceAccountIdentifier: 'acc-A' };
255
+ const buildRcsFormValue = (accountId) => ({
256
+ validity: true,
257
+ value: {
258
+ name: 'rcs_creative_name',
259
+ type: 'RCS',
260
+ versions: {
261
+ base: {
262
+ content: {
263
+ RCS: {
264
+ rcsContent: {
265
+ contentType: 'RICHCARD', cardType: 'STANDALONE', cardSettings: {}, cardContent: [{}], accountId,
266
+ },
267
+ },
268
+ },
269
+ },
270
+ },
271
+ },
272
+ });
273
+ const renderRcsEdit = ({ selectedRcsAccount, templateData = rcsEditTemplateData }) => shallowWithIntl(
274
+ <Creatives
275
+ loyaltyMetaData={loyaltyMetaData}
276
+ Templates={{ ...rcsTemplates, selectedRcsAccount }}
277
+ channel="RCS"
278
+ slidBoxContent="editTemplate"
279
+ templateData={templateData}
280
+ handleCloseCreatives={handleCloseCreatives}
281
+ getCreativesData={getCreativesData}
282
+ isFullMode={false}
283
+ templateActions={{
284
+ getCdnTransformationConfig,
285
+ }}
286
+ />,
287
+ );
288
+
289
+ it('adds the selected account when it is the account the template was saved with', async () => {
290
+ const wrapper = renderRcsEdit({ selectedRcsAccount: rcsAccountA });
291
+ const formValue = buildRcsFormValue('101');
292
+ const templateData = await wrapper.instance().getCreativesData('RCS', formValue, formValue);
293
+ expect(templateData.accountId).toBe('101');
294
+ expect(templateData.sourceAccountIdentifier).toBe('acc-A');
295
+ expect(templateData.accountName).toBe('Brand A');
296
+ });
297
+
298
+ it('keeps the consumer-provided account when the selected account belongs to another account', async () => {
299
+ const wrapper = renderRcsEdit({
300
+ selectedRcsAccount: rcsAccountA,
301
+ templateData: { ...rcsEditTemplateData, sourceAccountIdentifier: 'acc-B', accountName: 'Brand B' },
302
+ });
303
+ const formValue = buildRcsFormValue('202');
304
+ const templateData = await wrapper.instance().getCreativesData('RCS', formValue, formValue);
305
+ expect(templateData.accountId).toBe('202');
306
+ expect(templateData.sourceAccountIdentifier).toBe('acc-B');
307
+ expect(templateData.accountName).toBe('Brand B');
308
+ });
309
+
310
+ it('omits the account fields when no account is known', async () => {
311
+ const wrapper = renderRcsEdit({ selectedRcsAccount: undefined });
312
+ const formValue = buildRcsFormValue('');
313
+ const templateData = await wrapper.instance().getCreativesData('RCS', formValue, formValue);
314
+ expect(templateData).not.toHaveProperty('sourceAccountIdentifier');
315
+ expect(templateData).not.toHaveProperty('accountName');
316
+ });
317
+ });
318
+
253
319
  it('RCS getFormData mirrors rcsCardVarMapped onto templateData for campaign reopen', async () => {
254
320
  renderedComponent = shallowWithIntl(
255
321
  <Creatives
@@ -5,16 +5,20 @@ 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 CapTooltip from "@capillarytech/cap-ui-library/CapTooltip";
8
+ import CapLabel from "@capillarytech/cap-ui-library/CapLabel";
9
+ // import CapTooltip from "@capillarytech/cap-ui-library/CapTooltip";
9
10
  import CapMpushCTA from "../../../v2Components/CapMpushCTA";
10
- import { PRIMARY, SECONDARY, DEEP_LINK } from "../constants";
11
+ import { PRIMARY, DEEP_LINK } from "../constants";
12
+ // import { SECONDARY } from "../constants";
11
13
  import messages from "../messages";
12
14
 
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.
13
17
  const CtaButtons = ({
14
18
  primaryButton,
15
- secondaryButton,
19
+ // secondaryButton,
16
20
  setPrimaryButton,
17
- setSecondaryButton,
21
+ // setSecondaryButton,
18
22
  ctaData,
19
23
  updateHandler,
20
24
  deleteHandler,
@@ -27,7 +31,7 @@ const CtaButtons = ({
27
31
  }) => {
28
32
  // Local state to control CTA form visibility
29
33
  const [showPrimaryCTA, setShowPrimaryCTA] = useState(false);
30
- const [showSecondaryCTA, setShowSecondaryCTA] = useState(false);
34
+ // const [showSecondaryCTA, setShowSecondaryCTA] = useState(false);
31
35
 
32
36
  const handleAddPrimary = () => {
33
37
  // Prevent multiple clicks if primary button is already being added or form is already showing
@@ -53,68 +57,67 @@ const CtaButtons = ({
53
57
  setShowPrimaryCTA(true);
54
58
  };
55
59
 
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
- };
60
+ // Secondary button: needs backend support, revamped
61
+ // const handleAddSecondary = () => {
62
+ // if (secondaryButton && showSecondaryCTA) {
63
+ // return;
64
+ // }
65
+ // if (ctaData?.length < 2 || !ctaData?.find((cta) => cta?.index === 1)) {
66
+ // const newSecondaryButton = {
67
+ // index: 1,
68
+ // ctaType: SECONDARY,
69
+ // text: "",
70
+ // urlType: DEEP_LINK,
71
+ // url: "",
72
+ // deepLinkKeys: "",
73
+ // isSaved: false,
74
+ // };
75
+ // updateHandler(newSecondaryButton, 1);
76
+ // }
77
+ // setSecondaryButton(true);
78
+ // setShowSecondaryCTA(true);
79
+ // };
84
80
 
85
81
  // Check if primary button exists (saved or being edited)
86
82
  const primaryButtonExists = ctaData?.length > 0 && ctaData[0]?.text;
87
83
  const isPrimaryButtonSaved = primaryButtonExists && ctaData[0]?.isSaved;
88
84
 
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;
85
+ // Secondary button: needs backend support, revamped
86
+ // const secondaryButtonExists = ctaData?.length > 1 && ctaData[1]?.text;
87
+ // const isSecondaryButtonSaved = secondaryButtonExists && ctaData[1]?.isSaved;
92
88
 
93
89
  // Show primary CTA if button is active and (form is showing OR button exists)
94
90
  const shouldShowPrimaryCTA = primaryButton && (showPrimaryCTA || primaryButtonExists);
95
91
 
96
- // Show secondary CTA if button is active and (form is showing OR button exists)
97
- const shouldShowSecondaryCTA = secondaryButton && (showSecondaryCTA || secondaryButtonExists);
92
+ // Secondary button: needs backend support, revamped
93
+ // const shouldShowSecondaryCTA = secondaryButton && (showSecondaryCTA || secondaryButtonExists);
98
94
 
99
95
  // Enhanced delete handler to hide forms when buttons are deleted
100
96
  const handleDelete = (index) => {
101
97
  if (index === 0) {
102
98
  setShowPrimaryCTA(false);
103
99
  setPrimaryButton(false);
104
- } else if (index === 1) {
105
- //cooment until supported from BE & Hydra
106
- // setShowSecondaryCTA(false);
107
- // setSecondaryButton(false);
108
100
  }
101
+ // Secondary button: needs backend support, revamped
102
+ // else if (index === 1) {
103
+ // setShowSecondaryCTA(false);
104
+ // setSecondaryButton(false);
105
+ // }
109
106
  deleteHandler(index);
110
107
  };
111
108
 
112
109
  return (
113
110
  <>
114
111
  <CapRow className="mpush-cta-buttons">
115
- <CapHeading type="h3">
116
- <FormattedMessage {...messages.buttons} />
117
- </CapHeading>
112
+ {/* Heading with "(Optional)" on the same line */}
113
+ <CapRow type="flex" align="middle" noWrap className="mpush-section-heading">
114
+ <CapHeading type="h3">
115
+ <FormattedMessage {...messages.buttons} />
116
+ </CapHeading>
117
+ <CapLabel className="optional-text">
118
+ <FormattedMessage {...messages.optionalText} />
119
+ </CapLabel>
120
+ </CapRow>
118
121
  {!isPrimaryButtonSaved && !shouldShowPrimaryCTA && (
119
122
  <CapButton
120
123
  type="link"
@@ -142,6 +145,7 @@ const CtaButtons = ({
142
145
  handleOnTagsContextChange={handleOnTagsContextChange}
143
146
  />
144
147
  )}
148
+ {/* Secondary button: needs backend support, so it is being revamped. Hidden until then.
145
149
  {isPrimaryButtonSaved && !isSecondaryButtonSaved && !shouldShowSecondaryCTA && (
146
150
  <CapTooltip
147
151
  overlay={<FormattedMessage {...messages.secondaryButtonTooltip} />}
@@ -171,15 +175,16 @@ const CtaButtons = ({
171
175
  buttonType={SECONDARY}
172
176
  />
173
177
  )}
178
+ */}
174
179
  </>
175
180
  );
176
181
  };
177
182
 
178
183
  CtaButtons.propTypes = {
179
184
  primaryButton: PropTypes.bool.isRequired,
180
- secondaryButton: PropTypes.bool.isRequired,
185
+ // secondaryButton: PropTypes.bool.isRequired,
181
186
  setPrimaryButton: PropTypes.func.isRequired,
182
- setSecondaryButton: PropTypes.func.isRequired,
187
+ // setSecondaryButton: PropTypes.func.isRequired,
183
188
  ctaData: PropTypes.array.isRequired,
184
189
  updateHandler: PropTypes.func.isRequired,
185
190
  deleteHandler: PropTypes.func.isRequired,