@capillarytech/creatives-library 9.2.2 → 9.2.3

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 (47) 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 +51 -12
  13. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +83 -5
  14. package/v2Components/CommonTestAndPreview/tests/index.test.js +100 -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/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/Tests/extractContentForPreview.test.js +45 -0
  23. package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/extractContentForPreview.js +12 -2
  24. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -6
  25. package/v2Containers/CreativesContainer/index.js +2 -1
  26. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +43 -0
  27. package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
  28. package/v2Containers/MobilePushNew/components/MediaUploaders.js +105 -345
  29. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +127 -105
  30. package/v2Containers/MobilePushNew/components/TapLinkActions.js +76 -0
  31. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
  32. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +305 -1482
  33. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +165 -59
  34. package/v2Containers/MobilePushNew/constants.js +12 -0
  35. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  36. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +78 -0
  37. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
  38. package/v2Containers/MobilePushNew/hooks/useUpload.js +42 -46
  39. package/v2Containers/MobilePushNew/index.js +498 -289
  40. package/v2Containers/MobilePushNew/index.scss +151 -4
  41. package/v2Containers/MobilePushNew/messages.js +106 -6
  42. package/v2Containers/MobilePushNew/tests/index.test.js +483 -1
  43. package/v2Containers/MobilePushNew/tests/utils.test.js +110 -0
  44. package/v2Containers/MobilePushNew/utils.js +83 -0
  45. package/v2Containers/Templates/_templates.scss +10 -2
  46. package/v2Containers/Templates/index.js +86 -81
  47. package/v2Containers/Templates/tests/index.test.js +81 -0
@@ -1,7 +1,7 @@
1
1
  // eslint-disable-next-line jsx-a11y/href-no-hash
2
2
  import { useCallback, useEffect, useRef } from 'react';
3
3
  import {
4
- ANDROID, DEEP_LINK, GIF, IMAGE, IOS, VIDEO,
4
+ ANDROID, DEEP_LINK, GIF, IMAGE, IOS, VIDEO, TAP_ACTION_APP,
5
5
  } from '../constants';
6
6
  import { NONE } from '../../Whatsapp/constants';
7
7
 
@@ -353,6 +353,44 @@ const usePlatformSync = ({
353
353
  }
354
354
  }, [androidContent, iosContent, setAndroidContent, setIosContent, sameContent, deepSyncContent]);
355
355
 
356
+ // "When tapped, open" dropdown: TAP_ACTION_APP turns the tap action off, DEEP_LINK / EXTERNAL_LINK
357
+ // turn it on with that link type. One update, so actionOnClick and linkType can't overwrite each other.
358
+ const handleTapActionChange = useCallback((platform, value) => {
359
+ const {
360
+ setContent,
361
+ otherSetContent,
362
+ otherContent,
363
+ currentContent,
364
+ targetPlatform,
365
+ } = getPlatformContent(platform, {
366
+ androidContent,
367
+ iosContent,
368
+ setAndroidContent,
369
+ setIosContent,
370
+ });
371
+
372
+ const isApp = value === TAP_ACTION_APP;
373
+ const currentValue = currentContent?.actionOnClick ? (currentContent?.linkType || DEEP_LINK) : TAP_ACTION_APP;
374
+ if (value === currentValue) return;
375
+
376
+ const newContent = {
377
+ ...currentContent,
378
+ actionOnClick: !isApp,
379
+ linkType: isApp ? DEEP_LINK : value,
380
+ deepLinkValue: "",
381
+ deepLinkKeysValue: [],
382
+ externalLinkValue: "",
383
+ // A new link stays open until its Save is clicked
384
+ tapLinkSaved: isApp ? undefined : false,
385
+ };
386
+ setContent(newContent);
387
+
388
+ if (sameContent) {
389
+ const synced = deepSyncContent(newContent, otherContent, targetPlatform);
390
+ otherSetContent(synced);
391
+ }
392
+ }, [androidContent, iosContent, setAndroidContent, setIosContent, sameContent, deepSyncContent]);
393
+
356
394
  return {
357
395
  handleTitleChange,
358
396
  handleMessageChange,
@@ -361,6 +399,7 @@ const usePlatformSync = ({
361
399
  handleButtonChange,
362
400
  handleActionOnClickChange,
363
401
  handleLinkTypeChange,
402
+ handleTapActionChange,
364
403
  };
365
404
  };
366
405
 
@@ -1,4 +1,4 @@
1
- import { useState, useCallback, useEffect } from 'react';
1
+ import { useState, useCallback, useEffect, useRef } from 'react';
2
2
  import { getCdnUrl } from '../../../utils/cdnTransformation';
3
3
  import {
4
4
  MOBILE_PUSH_CHANNEL,
@@ -51,6 +51,10 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
51
51
 
52
52
  const [uploadErrors, setUploadErrors] = useState({});
53
53
 
54
+ // Latest tick/tab: the uploader's Re-upload button keeps its first-render handlers
55
+ const syncStateRef = useRef({ sameContent, activeTab });
56
+ syncStateRef.current = { sameContent, activeTab };
57
+
54
58
  // Add assetList state for test assertions
55
59
  const [assetList, setAssetList] = useState([]);
56
60
 
@@ -148,8 +152,9 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
148
152
  mobilePushActions.uploadAsset(file, assetType, fileParams, activeTab === ANDROID ? 0 : 1, mobilePushParams);
149
153
  }, [mobilePushActions, validateImageFile, validateVideoFile, validateGifFile, activeTab]);
150
154
 
151
- // Clear media data when switching media types
152
- const clearImageDataByMediaType = useCallback((mediaType) => {
155
+ // Clear media data when switching media types.
156
+ // platform: the tab whose media changed (defaults to the visible tab).
157
+ const clearImageDataByMediaType = useCallback((mediaType, platform = activeTab) => {
153
158
  if (mediaType === IMAGE) {
154
159
  if (sameContent) {
155
160
  // When sync is enabled, clear both platforms
@@ -158,11 +163,11 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
158
163
  iosImageSrc: "",
159
164
  });
160
165
  } else {
161
- // When sync is disabled, only clear the current platform
162
- const platform = activeTab === ANDROID ? 'androidImageSrc' : 'iosImageSrc';
166
+ // When sync is disabled, only clear that platform
167
+ const platformKey = platform === ANDROID ? 'androidImageSrc' : 'iosImageSrc';
163
168
  setImageSrc((prevState) => ({
164
169
  ...prevState,
165
- [platform]: "",
170
+ [platformKey]: "",
166
171
  }));
167
172
  }
168
173
  } else if (mediaType === VIDEO || mediaType === GIF) {
@@ -196,9 +201,9 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
196
201
  mobilePushActions.clearAsset(0);
197
202
  mobilePushActions.clearAsset(1);
198
203
  } else {
199
- // When sync is disabled, only clear the current platform
200
- const platformIndex = activeTab === ANDROID ? 0 : 1;
201
- const isAndroid = activeTab === ANDROID;
204
+ // When sync is disabled, only clear that platform
205
+ const platformIndex = platform === ANDROID ? 0 : 1;
206
+ const isAndroid = platform === ANDROID;
202
207
  const videoProps = getVideoProperties(isAndroid);
203
208
 
204
209
  setVideoState((prevState) => ({
@@ -293,17 +298,11 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
293
298
  }
294
299
  }, [videoState?.androidVideoSrc, videoState?.iosVideoSrc, videoState?.androidVideoPreview, videoState?.iosVideoPreview, videoState?.androidVideoDuration, videoState?.iosVideoDuration, sameContent]);
295
300
 
296
- // Sync imageSrc state for both platforms when sameContent is toggled ON
301
+ // On tick, copy the active tab's image to both tabs, even when it has none
297
302
  useEffect(() => {
298
303
  if (sameContent) {
299
- // Determine which image to use (prefer activeTab, fallback to either)
300
- let currentImageSrc = '';
301
- if (activeTab === ANDROID) {
302
- currentImageSrc = imageSrc?.androidImageSrc || imageSrc?.iosImageSrc;
303
- } else {
304
- currentImageSrc = imageSrc?.iosImageSrc || imageSrc?.androidImageSrc;
305
- }
306
- if (currentImageSrc && (imageSrc?.androidImageSrc !== currentImageSrc || imageSrc?.iosImageSrc !== currentImageSrc)) {
304
+ const currentImageSrc = (activeTab === ANDROID ? imageSrc?.androidImageSrc : imageSrc?.iosImageSrc) || '';
305
+ if (imageSrc?.androidImageSrc !== currentImageSrc || imageSrc?.iosImageSrc !== currentImageSrc) {
307
306
  setImageSrc({
308
307
  androidImageSrc: currentImageSrc,
309
308
  iosImageSrc: currentImageSrc,
@@ -314,31 +313,20 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
314
313
  // eslint-disable-next-line react-hooks/exhaustive-deps
315
314
  }, [sameContent, activeTab]);
316
315
 
317
- // Sync videoState for both platforms when sameContent is toggled ON
316
+ // On tick, copy the active tab's video to both tabs, even when it has none
318
317
  useEffect(() => {
319
318
  if (sameContent) {
320
- // Determine which video to use (prefer activeTab, fallback to either)
321
- let currentVideoSrc = '';
322
- let currentVideoPreview = '';
323
- let currentVideoDuration = 0;
324
- if (activeTab === ANDROID) {
325
- currentVideoSrc = videoState?.androidVideoSrc || videoState?.iosVideoSrc;
326
- currentVideoPreview = videoState?.androidVideoPreview || videoState?.iosVideoPreview;
327
- currentVideoDuration = videoState?.androidVideoDuration || videoState?.iosVideoDuration;
328
- } else {
329
- currentVideoSrc = videoState?.iosVideoSrc || videoState?.androidVideoSrc;
330
- currentVideoPreview = videoState?.iosVideoPreview || videoState?.androidVideoPreview;
331
- currentVideoDuration = videoState?.iosVideoDuration || videoState?.androidVideoDuration;
332
- }
319
+ const isAndroid = activeTab === ANDROID;
320
+ const currentVideoSrc = (isAndroid ? videoState?.androidVideoSrc : videoState?.iosVideoSrc) || '';
321
+ const currentVideoPreview = (isAndroid ? videoState?.androidVideoPreview : videoState?.iosVideoPreview) || '';
322
+ const currentVideoDuration = (isAndroid ? videoState?.androidVideoDuration : videoState?.iosVideoDuration) || 0;
333
323
  if (
334
- currentVideoSrc && (
335
- videoState?.androidVideoSrc !== currentVideoSrc
336
- || videoState?.iosVideoSrc !== currentVideoSrc
337
- || videoState?.androidVideoPreview !== currentVideoPreview
338
- || videoState?.iosVideoPreview !== currentVideoPreview
339
- || videoState?.androidVideoDuration !== currentVideoDuration
340
- || videoState?.iosVideoDuration !== currentVideoDuration
341
- )
324
+ videoState?.androidVideoSrc !== currentVideoSrc
325
+ || videoState?.iosVideoSrc !== currentVideoSrc
326
+ || videoState?.androidVideoPreview !== currentVideoPreview
327
+ || videoState?.iosVideoPreview !== currentVideoPreview
328
+ || videoState?.androidVideoDuration !== currentVideoDuration
329
+ || videoState?.iosVideoDuration !== currentVideoDuration
342
330
  ) {
343
331
  setVideoState({
344
332
  androidVideoSrc: currentVideoSrc,
@@ -349,6 +337,12 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
349
337
  iosVideoDuration: currentVideoDuration,
350
338
  });
351
339
  }
340
+ // The upload box also reads the uploaded-file list
341
+ const sourceAssetList = isAndroid ? androidAssetList : iosAssetList;
342
+ const targetAssetList = isAndroid ? iosAssetList : androidAssetList;
343
+ if (JSON.stringify(sourceAssetList) !== JSON.stringify(targetAssetList)) {
344
+ (isAndroid ? updateIosAssetList : updateAndroidAssetList)(sourceAssetList);
345
+ }
352
346
  }
353
347
  // Only run when sameContent or activeTab changes
354
348
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -356,27 +350,29 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
356
350
 
357
351
  // Image upload handlers
358
352
  const updateOnMpushImageReUpload = useCallback(() => {
359
- if (sameContent) {
353
+ const { sameContent: isSynced, activeTab: currentTab } = syncStateRef.current;
354
+ if (isSynced) {
360
355
  // When sync is enabled, set image for both platforms
361
356
  setImageSrc({
362
357
  androidImageSrc: "",
363
358
  iosImageSrc: "",
364
359
  });
365
360
  } else {
366
- const platform = activeTab === ANDROID ? 'androidImageSrc' : 'iosImageSrc';
361
+ const platform = currentTab === ANDROID ? 'androidImageSrc' : 'iosImageSrc';
367
362
  setImageSrc((prevState) => ({
368
363
  ...prevState,
369
364
  [platform]: "",
370
365
  }));
371
366
  }
372
- }, [sameContent, activeTab]);
367
+ }, []);
373
368
 
374
369
  const setUpdateMpushImageSrc = useCallback((filePath, index, mediaType = IMAGE) => {
370
+ const { sameContent: isSynced } = syncStateRef.current;
375
371
  // Handle both non-carousel and carousel media types
376
372
  if (mediaType === CAROUSEL) {
377
373
  // For carousel images, we need to set them in the Redux state for the uploader to recognize
378
374
  // This is needed when initializing carousel images from template data
379
- if (sameContent) {
375
+ if (isSynced) {
380
376
  // When sync is enabled, set image for both platforms
381
377
  setImageSrc({
382
378
  androidImageSrc: filePath,
@@ -394,7 +390,7 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
394
390
  return;
395
391
  }
396
392
 
397
- if (sameContent) {
393
+ if (isSynced) {
398
394
  // When sync is enabled, set image for both platforms
399
395
  setImageSrc({
400
396
  androidImageSrc: filePath,
@@ -410,7 +406,7 @@ const useUpload = (mobilePushActions, editData = {}, _uploadedAssetData0 = {}, _
410
406
  }
411
407
 
412
408
  mobilePushActions.clearAsset(index);
413
- }, [mobilePushActions, sameContent, setImageSrc]);
409
+ }, [mobilePushActions, setImageSrc]);
414
410
 
415
411
  // Video re-upload handler - clear video data based on platform and sync settings
416
412
  const updateOnMpushVideoReUpload = useCallback(() => {