@capillarytech/creatives-library 9.1.7 → 9.1.8-alpha.sprint-cap-214249.39

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 (41) 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 -33
  5. package/utils/tests/createMobilePushPayload.test.js +113 -8
  6. package/v2Components/CapMpushCTA/index.js +10 -9
  7. package/v2Components/CapMpushCTA/index.scss +29 -3
  8. package/v2Components/CapMpushCTA/tests/index.test.js +89 -0
  9. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +20 -12
  10. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
  11. package/v2Components/CommonTestAndPreview/constants.js +2 -0
  12. package/v2Components/CommonTestAndPreview/index.js +48 -10
  13. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +81 -5
  14. package/v2Components/CommonTestAndPreview/tests/index.test.js +86 -0
  15. package/v2Components/TemplatePreview/_templatePreview.scss +12 -2
  16. package/v2Components/TemplatePreview/index.js +24 -16
  17. package/v2Components/TemplatePreview/tests/index.test.js +68 -0
  18. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -6
  19. package/v2Containers/CreativesContainer/index.js +2 -1
  20. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +43 -0
  21. package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
  22. package/v2Containers/MobilePushNew/components/MediaUploaders.js +297 -216
  23. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +158 -125
  24. package/v2Containers/MobilePushNew/components/TapLinkActions.js +76 -0
  25. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
  26. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +464 -108
  27. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +106 -35
  28. package/v2Containers/MobilePushNew/constants.js +5 -0
  29. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  30. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +52 -0
  31. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
  32. package/v2Containers/MobilePushNew/hooks/useUpload.js +29 -39
  33. package/v2Containers/MobilePushNew/index.js +487 -235
  34. package/v2Containers/MobilePushNew/index.scss +205 -4
  35. package/v2Containers/MobilePushNew/messages.js +106 -6
  36. package/v2Containers/MobilePushNew/tests/index.test.js +469 -1
  37. package/v2Containers/MobilePushNew/tests/utils.test.js +70 -0
  38. package/v2Containers/MobilePushNew/utils.js +56 -0
  39. package/v2Containers/Templates/_templates.scss +10 -2
  40. package/v2Containers/Templates/index.js +83 -81
  41. package/v2Containers/Templates/tests/index.test.js +68 -0
@@ -15,11 +15,11 @@ import CapIcon from "@capillarytech/cap-ui-library/CapIcon";
15
15
  import CapRadioGroup from "@capillarytech/cap-ui-library/CapRadioGroup";
16
16
  import CapRow from "@capillarytech/cap-ui-library/CapRow";
17
17
  import CapTab from "@capillarytech/cap-ui-library/CapTab";
18
- import CapCheckbox from "@capillarytech/cap-ui-library/CapCheckbox";
19
18
  import CapLabel from "@capillarytech/cap-ui-library/CapLabel";
20
19
  import CapSelect from "@capillarytech/cap-ui-library/CapSelect";
21
20
  import CapInput from "@capillarytech/cap-ui-library/CapInput";
22
21
  import CapError from "@capillarytech/cap-ui-library/CapError";
22
+ import CapTooltip from "@capillarytech/cap-ui-library/CapTooltip";
23
23
  import CapImageUpload from "../../../v2Components/CapImageUpload";
24
24
  import CapVideoUpload from "../../../v2Components/CapVideoUpload";
25
25
  import {
@@ -36,14 +36,21 @@ import {
36
36
  GIF,
37
37
  IMAGE,
38
38
  VIDEO,
39
- LINK_TYPE_OPTIONS,
40
39
  DEEP_LINK,
41
40
  EXTERNAL_LINK,
42
41
  CAROUSEL,
42
+ TAP_ACTION_APP,
43
43
  } from "../constants";
44
44
  import messages from "../messages";
45
- import { validateExternalLink, validateDeepLink } from "../utils";
45
+ import {
46
+ validateExternalLink,
47
+ validateDeepLink,
48
+ findSelectedDeepLink,
49
+ getCarouselCardIssue,
50
+ CAROUSEL_CARD_ISSUE,
51
+ } from "../utils";
46
52
  import TagList from "../../TagList";
53
+ import { SavedTapLink, TapLinkSaveDelete } from "./TapLinkActions";
47
54
 
48
55
  // Initial carousel data structure
49
56
  const CAROUSEL_INITIAL_DATA = {
@@ -62,22 +69,6 @@ const CAROUSEL_INITIAL_DATA = {
62
69
  // Maximum number of carousel cards allowed
63
70
  const MAX_CAROUSEL_ALLOWED = 10;
64
71
 
65
- // Helper function to find selected deep link with fallback to base URL
66
- const findSelectedDeepLink = (links, value) => {
67
- if (!links || !value) return undefined;
68
-
69
- // Try to find exact match first
70
- let selectedDeepLink = links.find((link) => link?.value === value);
71
-
72
- // If no exact match and value contains query parameters, try base URL match
73
- if (!selectedDeepLink && value?.includes('?')) {
74
- const baseDeepLinkValue = value.split('?')[0];
75
- selectedDeepLink = links.find((link) => link?.value === baseDeepLinkValue);
76
- }
77
-
78
- return selectedDeepLink;
79
- };
80
-
81
72
  const MediaUploaders = ({
82
73
  mediaType,
83
74
  activeTab,
@@ -121,6 +112,8 @@ const MediaUploaders = ({
121
112
  // Track upload ID to prevent processing stale Redux data
122
113
  const [currentUploadId, setCurrentUploadId] = useState(null);
123
114
  const uploadIdRef = useRef(0); // Counter for generating unique upload IDs
115
+ // Card whose video Re upload was clicked (its file input may belong to another card)
116
+ const reuploadCardRef = useRef(null);
124
117
 
125
118
  // Track previous upload data to detect when a new upload completes
126
119
  const previousUploadDataRef = useRef(null);
@@ -165,8 +158,12 @@ const MediaUploaders = ({
165
158
  };
166
159
  }, [getCurrentCarouselData, updateCarouselCard]);
167
160
 
168
- // Clear previous media data when switching media types
161
+ // Clear previous media data when this pane's media type changes.
162
+ // Skip re-runs from a tab switch: both panes stay mounted, and the
163
+ // hidden one must not wipe the visible tab's media.
169
164
  useEffect(() => {
165
+ if (previousMediaTypeRef.current === mediaType) return;
166
+
170
167
  // Clear carousel data when switching to non-carousel media types
171
168
  if (mediaType !== CAROUSEL) {
172
169
  setCurrentCarouselData([]);
@@ -178,15 +175,15 @@ const MediaUploaders = ({
178
175
  previousUploadDataRef.current = null;
179
176
  }
180
177
 
181
- // Clear image data when switching away from IMAGE media type
178
+ // Clear image data when switching away from IMAGE media type (this pane's platform only)
182
179
  if (mediaType !== IMAGE) {
183
- clearImageDataByMediaType(IMAGE);
180
+ clearImageDataByMediaType(IMAGE, activeTab);
184
181
  }
185
182
 
186
183
  // Clear image data when switching FROM CAROUSEL TO IMAGE
187
184
  // This prevents carousel images from appearing in IMAGE media type
188
185
  if (previousMediaTypeRef.current === CAROUSEL && mediaType === IMAGE) {
189
- clearImageDataByMediaType(IMAGE);
186
+ clearImageDataByMediaType(IMAGE, activeTab);
190
187
  }
191
188
 
192
189
  // Reset re-upload mode when switching media types
@@ -194,7 +191,7 @@ const MediaUploaders = ({
194
191
 
195
192
  // Update the previous media type ref
196
193
  previousMediaTypeRef.current = mediaType;
197
- }, [mediaType, clearImageDataByMediaType, setCurrentCarouselData]);
194
+ }, [mediaType, activeTab, clearImageDataByMediaType, setCurrentCarouselData]);
198
195
 
199
196
  // Handle platform tab changes for carousel data
200
197
  useEffect(() => {
@@ -369,6 +366,7 @@ const MediaUploaders = ({
369
366
  mediaType: value,
370
367
  imageUrl: value === IMAGE.toLowerCase() ? card.imageUrl : '',
371
368
  videoSrc: value === VIDEO.toLowerCase() ? card.videoSrc : '',
369
+ videoPreviewImg: value === VIDEO.toLowerCase() ? card.videoPreviewImg : '',
372
370
  buttons: card.buttons || [{
373
371
  actionOnClick: false,
374
372
  linkType: DEEP_LINK,
@@ -382,13 +380,18 @@ const MediaUploaders = ({
382
380
  setCarouselActiveTabIndex(Number(key));
383
381
  };
384
382
 
383
+ // A card is done once its media is uploaded and its tap link (if any) is filled
384
+ const hasIncompleteCard = getCurrentCarouselData()?.some((card) => getCarouselCardIssue(card, deepLink));
385
+
385
386
  const addCarouselCard = () => {
386
387
  const currentData = getCurrentCarouselData();
387
- if (currentData?.length < MAX_CAROUSEL_ALLOWED) {
388
+ if (currentData?.length < MAX_CAROUSEL_ALLOWED && !hasIncompleteCard) {
388
389
  setCurrentCarouselData([
389
390
  ...currentData,
390
391
  { ...CAROUSEL_INITIAL_DATA, mediaType: carouselMediaType },
391
392
  ]);
393
+ // Open the new card so its upload box is in view
394
+ setCarouselActiveTabIndex(currentData.length);
392
395
  }
393
396
  };
394
397
 
@@ -438,33 +441,44 @@ const MediaUploaders = ({
438
441
  }, 100);
439
442
  };
440
443
 
441
- // Action link handlers for carousel cards
442
- const handleCarouselActionOnClickChange = (cardIndex, checked) => {
443
- const currentData = getCurrentCarouselData();
444
- const card = currentData[cardIndex];
445
- const updatedButtons = [...card?.buttons];
446
- updatedButtons[0] = { ...updatedButtons[0], actionOnClick: checked };
447
- updateCarouselCard(cardIndex, { buttons: updatedButtons });
448
- };
444
+ const tapActionOptions = [
445
+ { label: formatMessage(messages.tapActionApp), value: TAP_ACTION_APP },
446
+ { label: formatMessage(messages.tapActionDeepLink), value: DEEP_LINK },
447
+ { label: formatMessage(messages.tapActionExternalLink), value: EXTERNAL_LINK },
448
+ ];
449
449
 
450
- const handleCarouselLinkTypeChange = (cardIndex, value) => {
450
+ // "When tapped, open" for a card: App turns the card action off, a link type turns it on
451
+ const handleCarouselTapActionChange = (cardIndex, value) => {
451
452
  const currentData = getCurrentCarouselData();
452
453
  const card = currentData[cardIndex];
454
+ const button = card?.buttons?.[0];
455
+ const currentValue = button?.actionOnClick ? (button?.linkType || DEEP_LINK) : TAP_ACTION_APP;
456
+ if (value === currentValue) return;
457
+ const isApp = value === TAP_ACTION_APP;
453
458
  const updatedButtons = [...card?.buttons];
454
- updatedButtons[0] = {
455
- ...updatedButtons[0],
456
- linkType: value,
459
+ updatedButtons[0] = {
460
+ ...button,
461
+ actionOnClick: !isApp,
462
+ linkType: isApp ? DEEP_LINK : value,
457
463
  deepLinkValue: '',
458
464
  externalLinkValue: '',
459
- deepLinkKeys: []
465
+ deepLinkKeys: [],
466
+ // A new link stays open until its Save is clicked
467
+ isSaved: isApp ? undefined : false,
460
468
  };
461
469
  updateCarouselCard(cardIndex, { buttons: updatedButtons });
462
- // Clear errors when link type changes
463
470
  updateCarouselLinkError(cardIndex, 'deepLink', null);
464
471
  updateCarouselLinkError(cardIndex, 'externalLink', null);
465
472
  updateCarouselLinkError(cardIndex, 'deepLinkKeys', null);
466
473
  };
467
474
 
475
+ const setCarouselTapLinkSaved = (cardIndex, isSaved) => {
476
+ const card = getCurrentCarouselData()[cardIndex];
477
+ const updatedButtons = [...card?.buttons];
478
+ updatedButtons[0] = { ...updatedButtons[0], isSaved };
479
+ updateCarouselCard(cardIndex, { buttons: updatedButtons });
480
+ };
481
+
468
482
  const handleCarouselDeepLinkChange = (cardIndex, value) => {
469
483
  const currentData = getCurrentCarouselData();
470
484
  const card = currentData[cardIndex];
@@ -554,25 +568,50 @@ const MediaUploaders = ({
554
568
  );
555
569
  };
556
570
 
557
- const renderCarouselVideoComponent = (cardIndex) => (
558
- <CapVideoUpload
559
- index={activeTab === ANDROID ? 0 : 1}
560
- allowedExtensionsRegex={ALLOWED_EXTENSIONS_VIDEO_REGEX}
561
- videoSize={MPUSH_VIDEO_SIZE}
562
- isFullMode={isFullMode}
563
- uploadAsset={uploadMpushAsset}
564
- uploadedAssetList={videoAssetList}
565
- onVideoUploadUpdateAssestList={(src) => updateCarouselCard(cardIndex, { videoSrc: src })}
566
- videoData={videoDataForVideo}
567
- className="cap-custom-video-upload"
568
- formClassName="mpush-video-upload"
569
- channel={MOBILE_PUSH_CHANNEL}
570
- errorMessage={formatMessage(messages.videoErrorMessage)}
571
- showVideoNameAndDuration={false}
572
- showReUploadButton
573
- mediaType="video"
574
- />
575
- );
571
+ // Called by the box as (index, data): Re upload passes an empty videoSrc
572
+ const handleCarouselVideoChange = (cardIndex, data = {}) => {
573
+ const { videoSrc = '', previewUrl = '' } = data;
574
+ if (!videoSrc) {
575
+ // Re upload clicks the page's first "videoFileName" input, which may be another card's
576
+ reuploadCardRef.current = cardIndex;
577
+ }
578
+ updateCarouselCard(cardIndex, { videoSrc, videoPreviewImg: videoSrc ? previewUrl : '' });
579
+ };
580
+
581
+ const renderCarouselVideoComponent = (cardIndex) => {
582
+ const card = getCurrentCarouselData()?.[cardIndex];
583
+
584
+ // Track the uploading card; the completion effect below writes the result into it
585
+ const handleCarouselVideoUpload = (file, assetType, fileParams, index) => {
586
+ const targetCard = reuploadCardRef.current ?? cardIndex;
587
+ reuploadCardRef.current = null;
588
+ uploadIdRef.current += 1;
589
+ setUploadingCardIndex(targetCard);
590
+ setCurrentUploadId(uploadIdRef.current);
591
+ return uploadMpushAsset(file, assetType, fileParams, index);
592
+ };
593
+
594
+ return (
595
+ <CapVideoUpload
596
+ key={`carousel-video-${activeTab}-${cardIndex}`}
597
+ index={activeTab === ANDROID ? 0 : 1}
598
+ allowedExtensionsRegex={ALLOWED_EXTENSIONS_VIDEO_REGEX}
599
+ videoSize={MPUSH_VIDEO_SIZE}
600
+ isFullMode={isFullMode}
601
+ uploadAsset={handleCarouselVideoUpload}
602
+ uploadedAssetList={card?.videoSrc ? { videoSrc: card.videoSrc, previewUrl: card.videoPreviewImg || '' } : {}}
603
+ onVideoUploadUpdateAssestList={(_index, data) => handleCarouselVideoChange(cardIndex, data)}
604
+ videoData={{}}
605
+ className="cap-custom-video-upload"
606
+ formClassName="mpush-video-upload"
607
+ channel={MOBILE_PUSH_CHANNEL}
608
+ errorMessage={formatMessage(messages.videoErrorMessage)}
609
+ showVideoNameAndDuration={false}
610
+ showReUploadButton
611
+ mediaType="video"
612
+ />
613
+ );
614
+ };
576
615
 
577
616
  const renderCarouselActionLinks = (cardIndex) => {
578
617
  const currentData = getCurrentCarouselData();
@@ -584,178 +623,191 @@ const MediaUploaders = ({
584
623
  }
585
624
 
586
625
  const button = card?.buttons[0]; // We're handling only one button for now
626
+ const tapAction = button?.actionOnClick ? (button?.linkType || DEEP_LINK) : TAP_ACTION_APP;
587
627
 
588
628
  // Use the callback creator instead of useCallback inside render function
589
629
  const onButtonTagSelect = createCarouselButtonTagSelectCallback(cardIndex);
590
630
 
631
+ const toArray = (value) => {
632
+ if (Array.isArray(value)) return value;
633
+ return value ? [value] : [];
634
+ };
635
+ const keysFromSelection = toArray(findSelectedDeepLink(deepLink, button?.deepLinkValue)?.keys);
636
+ const savedKeys = toArray(button?.deepLinkKeys);
637
+ const showDeepLinkKeys = tapAction === DEEP_LINK && button?.deepLinkValue && keysFromSelection.length > 0;
638
+
639
+ // Only errors from typed values show inline (as in Notification tap); an empty link just keeps Save off
640
+ const deepLinkError = carouselLinkErrors[`${cardIndex}-deepLink`];
641
+ const externalLinkError = carouselLinkErrors[`${cardIndex}-externalLink`];
642
+ const deepLinkKeysError = carouselLinkErrors[`${cardIndex}-deepLinkKeys`];
643
+ const cardIssue = getCarouselCardIssue(card, deepLink);
644
+ const isLinkIncomplete = [
645
+ CAROUSEL_CARD_ISSUE.DEEP_LINK,
646
+ CAROUSEL_CARD_ISSUE.DEEP_LINK_KEYS,
647
+ CAROUSEL_CARD_ISSUE.EXTERNAL_LINK,
648
+ ].includes(cardIssue);
649
+
650
+ // Link chosen and saved: collapsed row, as for a saved button
651
+ const isLinkSaved = tapAction !== TAP_ACTION_APP && button?.isSaved !== false;
652
+ const isLinkSaveDisabled = isLinkIncomplete || !!(deepLinkError || externalLinkError || deepLinkKeysError);
653
+ const savedLinkText = tapAction === DEEP_LINK
654
+ ? (findSelectedDeepLink(deepLink, button?.deepLinkValue)?.label || button?.deepLinkValue)
655
+ : button?.externalLinkValue;
656
+ const removeCardTapLink = () => handleCarouselTapActionChange(cardIndex, TAP_ACTION_APP);
657
+
658
+ if (isLinkSaved) {
659
+ return (
660
+ <>
661
+ <CapDivider />
662
+ <CapRow useLegacy className="creatives-mpush-actions">
663
+ <CapRow type="flex" align="middle" noWrap className="mpush-section-heading">
664
+ <CapHeading type="h4" className="mpush-actions">
665
+ <FormattedMessage {...messages.cardTap} />
666
+ </CapHeading>
667
+ <CapLabel className="optional-text">
668
+ <FormattedMessage {...messages.optionalText} />
669
+ </CapLabel>
670
+ </CapRow>
671
+ <CapLabel className="mpush-tap-description">
672
+ <FormattedMessage {...messages.cardTapDescription} />
673
+ </CapLabel>
674
+ <SavedTapLink
675
+ linkType={tapAction}
676
+ linkText={savedLinkText}
677
+ onEdit={() => setCarouselTapLinkSaved(cardIndex, false)}
678
+ onDelete={removeCardTapLink}
679
+ formatMessage={formatMessage}
680
+ />
681
+ </CapRow>
682
+ </>
683
+ );
684
+ }
685
+
591
686
  return (
592
687
  <>
593
688
  <CapDivider />
594
689
  <CapRow useLegacy className="creatives-mpush-actions">
595
- <CapRow useLegacy className="mpush-actions-main">
690
+ <CapRow type="flex" align="middle" noWrap className="mpush-section-heading">
596
691
  <CapHeading type="h4" className="mpush-actions">
597
- <FormattedMessage {...messages.buttonsAndLinks} />
692
+ <FormattedMessage {...messages.cardTap} />
598
693
  </CapHeading>
599
694
  <CapLabel className="optional-text">
600
695
  <FormattedMessage {...messages.optionalText} />
601
696
  </CapLabel>
602
697
  </CapRow>
603
- <CapCheckbox
604
- checked={button.actionOnClick}
605
- onChange={(e) => handleCarouselActionOnClickChange(cardIndex, e.target.checked)}
606
- className="action-on-click-checkbox"
607
- >
608
- <FormattedMessage {...messages.actionOnClickBody} />
609
- </CapCheckbox>
610
- <CapRow useLegacy>
611
- <CapLabel className="action-description">
612
- <FormattedMessage {...messages.actionDescription} />
613
- </CapLabel>
614
- </CapRow>
615
- {button?.actionOnClick && (
616
- <CapRow style={{ display: "flex", justifyContent: "space-around" }}>
617
- <CapColumn span={6}>
618
- <CapHeading type="h4" className="buttons-heading">
619
- <FormattedMessage {...messages.linkType} />
698
+ <CapLabel className="mpush-tap-description">
699
+ <FormattedMessage {...messages.cardTapDescription} />
700
+ </CapLabel>
701
+ <CapRow type="flex" noWrap gap={16} className="mpush-tap-row">
702
+ <CapColumn flex="0 0 30%" className="mpush-tap-action">
703
+ <CapHeading type="h4" className="mpush-tap-label">
704
+ <FormattedMessage {...messages.whenTappedOpen} />
705
+ </CapHeading>
706
+ <CapSelect.CapCustomSelect
707
+ id={`mobile-push-carousel-tap-action-${activeTab}-${cardIndex}`}
708
+ width="100%"
709
+ options={tapActionOptions}
710
+ value={tapAction}
711
+ onChange={(value) => handleCarouselTapActionChange(cardIndex, value)}
712
+ />
713
+ </CapColumn>
714
+ {tapAction === DEEP_LINK && (
715
+ <CapColumn flex="1 1 0" className="mpush-tap-link">
716
+ <CapHeading type="h4" className="mpush-tap-label">
717
+ <FormattedMessage {...messages.tapActionDeepLink} />
620
718
  </CapHeading>
621
719
  <CapSelect.CapCustomSelect
622
- options={LINK_TYPE_OPTIONS}
623
- value={button.linkType}
624
- onChange={(value) => handleCarouselLinkTypeChange(cardIndex, value)}
625
- key={`mobile-push-link-type-${activeTab}-${cardIndex}`}
720
+ width="100%"
721
+ options={(() => {
722
+ const options = [...(deepLink || [])];
723
+ // If the current value is not in the options, add it
724
+ if (button?.deepLinkValue && !options.find((opt) => opt.value === button?.deepLinkValue)) {
725
+ options.push({
726
+ value: button?.deepLinkValue,
727
+ label: button?.deepLinkValue,
728
+ });
729
+ }
730
+ return options;
731
+ })()}
732
+ value={button?.deepLinkValue}
733
+ onChange={(value) => handleCarouselDeepLinkChange(cardIndex, value)}
734
+ key={`mobile-push-deep-link-type-${activeTab}-${cardIndex}`}
626
735
  selectPlaceholder={formatMessage(messages.selectDeepLink)}
627
736
  />
628
- </CapColumn>
629
- {button?.linkType === DEEP_LINK && (
630
- <CapColumn span={14}>
631
- <CapHeading type="h4" className="buttons-heading">
632
- {formatMessage(messages.deepLink)}
633
- </CapHeading>
634
- <CapSelect.CapCustomSelect
635
- options={(() => {
636
- const options = [...(deepLink || [])];
637
- // If the current value is not in the options, add it
638
- if (button?.deepLinkValue && !options.find(opt => opt.value === button?.deepLinkValue)) {
639
- options.push({
640
- value: button?.deepLinkValue,
641
- label: button?.deepLinkValue,
642
- });
643
- }
644
- return options;
645
- })()}
646
- value={button?.deepLinkValue}
647
- onChange={(value) => handleCarouselDeepLinkChange(cardIndex, value)}
648
- key={`mobile-push-deep-link-type-${activeTab}-${cardIndex}`}
649
- placeholder={formatMessage(messages.selectDeepLink)}
650
- style={{ marginTop: "10px" }}
651
- />
652
- {carouselLinkErrors[`${cardIndex}-deepLink`] && (
653
- <CapError className="mobile-push-carousel-deep-link-error">
654
- {carouselLinkErrors[`${cardIndex}-deepLink`]}
655
- </CapError>
656
- )}
657
- </CapColumn>
658
- )}
659
- {button?.linkType === EXTERNAL_LINK && (
660
- <CapColumn span={14}>
661
- <CapRow className="buttons-heading-container">
662
- <CapHeading type="h4" className="buttons-heading">
663
- {formatMessage(messages.externalLink)}
737
+ {deepLinkError && (
738
+ <CapError className="mobile-push-carousel-deep-link-error">
739
+ {deepLinkError}
740
+ </CapError>
741
+ )}
742
+ {showDeepLinkKeys && (
743
+ <CapRow className="mpush-tap-deep-link-keys">
744
+ <CapHeading type="h4" className="deep-link-keys-heading">
745
+ {formatMessage(messages.deepLinkKeys)}
664
746
  </CapHeading>
665
- <TagList
666
- moduleFilterEnabled={
667
- location?.query?.type !== "embedded"
668
- }
669
- label={formatMessage(messages.addLabels)}
670
- onTagSelect={onButtonTagSelect}
671
- onContextChange={handleOnTagsContextChange}
672
- location={location}
673
- tags={tags}
674
- injectedTags={injectedTags}
675
- selectedOfferDetails={selectedOfferDetails}
747
+ <CapLabel type="label2" className="deep-link-keys-value">
748
+ {(keysFromSelection.length > 0 ? keysFromSelection : savedKeys).join(', ')}
749
+ </CapLabel>
750
+ <CapInput
751
+ id={`mobile-push-carousel-deep-link-keys-input-${activeTab}-${cardIndex}`}
752
+ onChange={(e) => handleCarouselDeepLinkKeysChange(cardIndex, e.target.value)}
753
+ placeholder={formatMessage(messages.deepLinkKeysPlaceholder, {
754
+ key: keysFromSelection.join(', ') || 'deep link keys',
755
+ })}
756
+ value={savedKeys.join(', ')}
757
+ size="default"
758
+ style={{ marginTop: "10px" }}
759
+ error={deepLinkKeysError}
676
760
  />
677
761
  </CapRow>
678
- <CapInput
679
- id={`mobile-push-external-link-input-${activeTab}-${cardIndex}`}
680
- onChange={(e) => handleCarouselExternalLinkChange(cardIndex, e.target.value)}
681
- placeholder={formatMessage(messages.enterExternalLink)}
682
- value={button?.externalLinkValue}
683
- size="default"
684
- isRequired
685
- />
686
- {carouselLinkErrors[`${cardIndex}-externalLink`] && (
687
- <CapError className="mobile-push-carousel-external-link-error">
688
- {carouselLinkErrors[`${cardIndex}-externalLink`]}
689
- </CapError>
690
- )}
691
- </CapColumn>
692
- )}
693
- </CapRow>
694
- )}
695
- {button?.linkType === DEEP_LINK && button?.deepLinkValue && button?.actionOnClick && (() => {
696
- const selectedDeepLink = findSelectedDeepLink(deepLink, button?.deepLinkValue);
697
- const deepLinkKeysFromSelection = selectedDeepLink?.keys;
698
- let deepLinkKeysFromSelectionArray = [];
699
- if (Array.isArray(deepLinkKeysFromSelection)) {
700
- deepLinkKeysFromSelectionArray = deepLinkKeysFromSelection;
701
- } else if (deepLinkKeysFromSelection) {
702
- deepLinkKeysFromSelectionArray = [deepLinkKeysFromSelection];
703
- }
704
- return deepLinkKeysFromSelectionArray?.length > 0;
705
- })() && (
706
- <CapRow style={{ marginTop: "10px", left: "6%", width: '115%'}}>
707
- <CapColumn span={14}>
708
- <CapHeading type="h4" className="deep-link-keys-heading">
709
- {formatMessage(messages.deepLinkKeys)}
710
- </CapHeading>
711
- <CapLabel type="label2" className="deep-link-keys-value">
712
- {(() => {
713
- const selectedDeepLink = findSelectedDeepLink(deepLink, button?.deepLinkValue);
714
- const deepLinkKeysFromSelection = selectedDeepLink?.keys;
715
- let deepLinkKeysArray = [];
716
- if (Array.isArray(button?.deepLinkKeys)) {
717
- deepLinkKeysArray = button?.deepLinkKeys;
718
- } else if (button?.deepLinkKeys) {
719
- deepLinkKeysArray = [button?.deepLinkKeys];
720
- }
721
- let deepLinkKeysFromSelectionArray = [];
722
- if (Array.isArray(deepLinkKeysFromSelection)) {
723
- deepLinkKeysFromSelectionArray = deepLinkKeysFromSelection;
724
- } else if (deepLinkKeysFromSelection) {
725
- deepLinkKeysFromSelectionArray = [deepLinkKeysFromSelection];
726
- }
727
-
728
- if (deepLinkKeysFromSelectionArray?.length > 0) {
729
- return deepLinkKeysFromSelectionArray.join(', ');
730
- }
731
- if (deepLinkKeysArray?.length > 0) {
732
- return deepLinkKeysArray.join(', ');
762
+ )}
763
+ </CapColumn>
764
+ )}
765
+ {tapAction === EXTERNAL_LINK && (
766
+ <CapColumn flex="1 1 0" className="mpush-tap-link">
767
+ <CapRow type="flex" align="middle" justify="space-between" noWrap className="mpush-tap-link-header">
768
+ <CapHeading type="h4" className="mpush-tap-label">
769
+ <FormattedMessage {...messages.url} />
770
+ </CapHeading>
771
+ <TagList
772
+ moduleFilterEnabled={
773
+ location?.query?.type !== "embedded"
733
774
  }
734
- })()}
735
- </CapLabel>
775
+ label={formatMessage(messages.addLabels)}
776
+ onTagSelect={onButtonTagSelect}
777
+ onContextChange={handleOnTagsContextChange}
778
+ location={location}
779
+ tags={tags}
780
+ injectedTags={injectedTags}
781
+ selectedOfferDetails={selectedOfferDetails}
782
+ />
783
+ </CapRow>
736
784
  <CapInput
737
- id={`mobile-push-carousel-deep-link-keys-input-${activeTab}-${cardIndex}`}
738
- onChange={(e) => handleCarouselDeepLinkKeysChange(cardIndex, e.target.value)}
739
- placeholder={formatMessage(messages.deepLinkKeysPlaceholder, {
740
- key: (() => {
741
- const selectedDeepLink = findSelectedDeepLink(deepLink, button?.deepLinkValue);
742
- const deepLinkKeysFromSelection = selectedDeepLink?.keys;
743
- let deepLinkKeysFromSelectionArray = [];
744
- if (Array.isArray(deepLinkKeysFromSelection)) {
745
- deepLinkKeysFromSelectionArray = deepLinkKeysFromSelection;
746
- } else if (deepLinkKeysFromSelection) {
747
- deepLinkKeysFromSelectionArray = [deepLinkKeysFromSelection];
748
- }
749
- return deepLinkKeysFromSelectionArray.join(', ') || 'deep link keys';
750
- })(),
751
- })}
752
- value={Array.isArray(button?.deepLinkKeys) ? button?.deepLinkKeys?.join(', ') : (button?.deepLinkKeys || "")}
785
+ id={`mobile-push-external-link-input-${activeTab}-${cardIndex}`}
786
+ onChange={(e) => handleCarouselExternalLinkChange(cardIndex, e.target.value)}
787
+ placeholder={formatMessage(messages.enterUrl)}
788
+ value={button?.externalLinkValue}
753
789
  size="default"
754
- style={{ marginTop: "10px" }}
755
- error={carouselLinkErrors[`${cardIndex}-deepLinkKeys`]}
790
+ isRequired
756
791
  />
792
+ {externalLinkError && (
793
+ <CapError className="mobile-push-carousel-external-link-error">
794
+ {externalLinkError}
795
+ </CapError>
796
+ )}
757
797
  </CapColumn>
758
- </CapRow>
798
+ )}
799
+ </CapRow>
800
+ {tapAction === TAP_ACTION_APP ? (
801
+ <CapLabel className="mpush-tap-description mpush-tap-help">
802
+ <FormattedMessage {...messages.cardTapAppHelp} />
803
+ </CapLabel>
804
+ ) : (
805
+ <TapLinkSaveDelete
806
+ isSaveDisabled={isLinkSaveDisabled}
807
+ onSave={() => setCarouselTapLinkSaved(cardIndex, true)}
808
+ onDelete={removeCardTapLink}
809
+ formatMessage={formatMessage}
810
+ />
759
811
  )}
760
812
  </CapRow>
761
813
  </>
@@ -804,17 +856,30 @@ const MediaUploaders = ({
804
856
  }));
805
857
  };
806
858
 
859
+ const isMaxCarouselCardsReached = getCurrentCarouselData()?.length >= MAX_CAROUSEL_ALLOWED;
860
+ let addCardTooltipTitle = "";
861
+ if (isMaxCarouselCardsReached) {
862
+ addCardTooltipTitle = formatMessage(messages.carouselMaxCardTooltip, { max: MAX_CAROUSEL_ALLOWED });
863
+ } else if (hasIncompleteCard) {
864
+ addCardTooltipTitle = formatMessage(messages.completeCardToAdd);
865
+ }
866
+
807
867
  const operations = (
808
868
  <>
809
869
  <CapDivider type="vertical" />
810
- <CapButton
811
- onClick={addCarouselCard}
812
- type="link"
813
- className="add-carousel-content-button"
814
- disabled={getCurrentCarouselData()?.length >= MAX_CAROUSEL_ALLOWED}
815
- >
816
- <CapIcon type="plus" />
817
- </CapButton>
870
+ <CapTooltip title={addCardTooltipTitle}>
871
+ {/* Disabled buttons fire no hover events; the wrapper lets the tooltip show */}
872
+ <span className="button-disabled-tooltip-wrapper">
873
+ <CapButton
874
+ onClick={addCarouselCard}
875
+ type="link"
876
+ className="add-carousel-content-button"
877
+ disabled={isMaxCarouselCardsReached || hasIncompleteCard}
878
+ >
879
+ <CapIcon type="plus" />
880
+ </CapButton>
881
+ </span>
882
+ </CapTooltip>
818
883
  </>
819
884
  );
820
885
 
@@ -839,7 +904,6 @@ const MediaUploaders = ({
839
904
  {
840
905
  value: VIDEO.toLowerCase(),
841
906
  label: formatMessage(messages.mediaVideo),
842
- disabled: true,
843
907
  },
844
908
  ]}
845
909
  value={carouselMediaType}
@@ -893,8 +957,16 @@ const MediaUploaders = ({
893
957
  const previousDataKey = previousUploadDataRef.current;
894
958
 
895
959
  if (currentDataKey !== previousDataKey) {
896
- // Update the specific card that was uploading
897
- updateCarouselCard(uploadingCardIndex, { imageUrl: uploadedData?.metaInfo?.secure_file_path });
960
+ const {
961
+ secure_file_path: filePath,
962
+ video_file_path_preview: videoPreview = '',
963
+ preview_image_url: previewImage = '',
964
+ } = uploadedData.metaInfo;
965
+ const isVideoCard = getCurrentCarouselData()?.[uploadingCardIndex]?.mediaType === VIDEO.toLowerCase();
966
+ // Update the specific card that was uploading (videoPreviewImg is what the phone preview shows)
967
+ updateCarouselCard(uploadingCardIndex, isVideoCard
968
+ ? { videoSrc: filePath, videoPreviewImg: videoPreview || previewImage }
969
+ : { imageUrl: filePath });
898
970
 
899
971
  // Store this upload data as "processed" to avoid reprocessing
900
972
  previousUploadDataRef.current = currentDataKey;
@@ -905,7 +977,16 @@ const MediaUploaders = ({
905
977
  }
906
978
  }
907
979
  }
908
- }, [mediaType, imageData, uploadingCardIndex, currentUploadId, activeTab, updateCarouselCard]);
980
+ }, [mediaType, imageData, uploadingCardIndex, currentUploadId, activeTab, updateCarouselCard, getCurrentCarouselData]);
981
+
982
+ // Editing a saved video carousel: show video boxes, not the default image ones
983
+ useEffect(() => {
984
+ const savedCardType = carouselData?.[0]?.mediaType;
985
+ if (mediaType === CAROUSEL && savedCardType && savedCardType !== carouselMediaType) {
986
+ setCarouselMediaType(savedCardType);
987
+ }
988
+ // eslint-disable-next-line react-hooks/exhaustive-deps
989
+ }, [mediaType, carouselData]);
909
990
 
910
991
  if (mediaType === IMAGE) return renderImageComponent();
911
992
  if (mediaType === VIDEO) return renderVideoComponent();