@capillarytech/creatives-library 9.2.0 → 9.2.1-alpha.sprint-cap-214249.42

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 +56 -51
  5. package/utils/tests/createMobilePushPayload.test.js +162 -10
  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 +48 -10
  13. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +83 -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 +14 -12
  17. package/v2Components/TemplatePreview/tests/index.test.js +69 -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 +314 -222
  23. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +161 -130
  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 +484 -123
  27. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +152 -46
  28. package/v2Containers/MobilePushNew/constants.js +12 -0
  29. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  30. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +78 -0
  31. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +40 -1
  32. package/v2Containers/MobilePushNew/hooks/useUpload.js +42 -46
  33. package/v2Containers/MobilePushNew/index.js +503 -273
  34. package/v2Containers/MobilePushNew/index.scss +215 -4
  35. package/v2Containers/MobilePushNew/messages.js +106 -6
  36. package/v2Containers/MobilePushNew/tests/index.test.js +482 -1
  37. package/v2Containers/MobilePushNew/tests/utils.test.js +122 -0
  38. package/v2Containers/MobilePushNew/utils.js +107 -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,25 @@ 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
+ TAP_ACTION_OPTIONS,
43
44
  } from "../constants";
44
45
  import messages from "../messages";
45
- import { validateExternalLink, validateDeepLink } from "../utils";
46
+ import {
47
+ validateExternalLink,
48
+ validateDeepLink,
49
+ findSelectedDeepLink,
50
+ getCarouselCardIssue,
51
+ CAROUSEL_CARD_ISSUE,
52
+ getDeepLinkParamValue,
53
+ setDeepLinkParamValue,
54
+ hasAllDeepLinkParams,
55
+ } from "../utils";
46
56
  import TagList from "../../TagList";
57
+ import { SavedTapLink, TapLinkSaveDelete } from "./TapLinkActions";
47
58
 
48
59
  // Initial carousel data structure
49
60
  const CAROUSEL_INITIAL_DATA = {
@@ -62,22 +73,6 @@ const CAROUSEL_INITIAL_DATA = {
62
73
  // Maximum number of carousel cards allowed
63
74
  const MAX_CAROUSEL_ALLOWED = 10;
64
75
 
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
76
  const MediaUploaders = ({
82
77
  mediaType,
83
78
  activeTab,
@@ -121,12 +116,16 @@ const MediaUploaders = ({
121
116
  // Track upload ID to prevent processing stale Redux data
122
117
  const [currentUploadId, setCurrentUploadId] = useState(null);
123
118
  const uploadIdRef = useRef(0); // Counter for generating unique upload IDs
119
+ // Card whose video Re upload was clicked (its file input may belong to another card)
120
+ const reuploadCardRef = useRef(null);
124
121
 
125
122
  // Track previous upload data to detect when a new upload completes
126
123
  const previousUploadDataRef = useRef(null);
127
124
 
128
125
  // Track previous media type to handle transitions
129
126
  const previousMediaTypeRef = useRef(mediaType);
127
+ // First card's media type last seen, for the saved-carousel effect
128
+ const prevCardTypeRef = useRef(null);
130
129
 
131
130
  // Extract link props
132
131
  const { deepLink } = linkProps || {};
@@ -165,8 +164,12 @@ const MediaUploaders = ({
165
164
  };
166
165
  }, [getCurrentCarouselData, updateCarouselCard]);
167
166
 
168
- // Clear previous media data when switching media types
167
+ // Clear previous media data when this pane's media type changes.
168
+ // Skip re-runs from a tab switch: both panes stay mounted, and the
169
+ // hidden one must not wipe the visible tab's media.
169
170
  useEffect(() => {
171
+ if (previousMediaTypeRef.current === mediaType) return;
172
+
170
173
  // Clear carousel data when switching to non-carousel media types
171
174
  if (mediaType !== CAROUSEL) {
172
175
  setCurrentCarouselData([]);
@@ -178,15 +181,15 @@ const MediaUploaders = ({
178
181
  previousUploadDataRef.current = null;
179
182
  }
180
183
 
181
- // Clear image data when switching away from IMAGE media type
184
+ // Clear image data when switching away from IMAGE media type (this pane's platform only)
182
185
  if (mediaType !== IMAGE) {
183
- clearImageDataByMediaType(IMAGE);
186
+ clearImageDataByMediaType(IMAGE, activeTab);
184
187
  }
185
188
 
186
189
  // Clear image data when switching FROM CAROUSEL TO IMAGE
187
190
  // This prevents carousel images from appearing in IMAGE media type
188
191
  if (previousMediaTypeRef.current === CAROUSEL && mediaType === IMAGE) {
189
- clearImageDataByMediaType(IMAGE);
192
+ clearImageDataByMediaType(IMAGE, activeTab);
190
193
  }
191
194
 
192
195
  // Reset re-upload mode when switching media types
@@ -194,7 +197,7 @@ const MediaUploaders = ({
194
197
 
195
198
  // Update the previous media type ref
196
199
  previousMediaTypeRef.current = mediaType;
197
- }, [mediaType, clearImageDataByMediaType, setCurrentCarouselData]);
200
+ }, [mediaType, activeTab, clearImageDataByMediaType, setCurrentCarouselData]);
198
201
 
199
202
  // Handle platform tab changes for carousel data
200
203
  useEffect(() => {
@@ -369,6 +372,7 @@ const MediaUploaders = ({
369
372
  mediaType: value,
370
373
  imageUrl: value === IMAGE.toLowerCase() ? card.imageUrl : '',
371
374
  videoSrc: value === VIDEO.toLowerCase() ? card.videoSrc : '',
375
+ videoPreviewImg: value === VIDEO.toLowerCase() ? card.videoPreviewImg : '',
372
376
  buttons: card.buttons || [{
373
377
  actionOnClick: false,
374
378
  linkType: DEEP_LINK,
@@ -382,13 +386,18 @@ const MediaUploaders = ({
382
386
  setCarouselActiveTabIndex(Number(key));
383
387
  };
384
388
 
389
+ // A card is done once its media is uploaded and its tap link (if any) is filled
390
+ const hasIncompleteCard = getCurrentCarouselData()?.some((card) => getCarouselCardIssue(card, deepLink));
391
+
385
392
  const addCarouselCard = () => {
386
393
  const currentData = getCurrentCarouselData();
387
- if (currentData?.length < MAX_CAROUSEL_ALLOWED) {
394
+ if (currentData?.length < MAX_CAROUSEL_ALLOWED && !hasIncompleteCard) {
388
395
  setCurrentCarouselData([
389
396
  ...currentData,
390
397
  { ...CAROUSEL_INITIAL_DATA, mediaType: carouselMediaType },
391
398
  ]);
399
+ // Open the new card so its upload box is in view
400
+ setCarouselActiveTabIndex(currentData.length);
392
401
  }
393
402
  };
394
403
 
@@ -438,33 +447,40 @@ const MediaUploaders = ({
438
447
  }, 100);
439
448
  };
440
449
 
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
- };
450
+ const tapActionOptions = TAP_ACTION_OPTIONS.map(({ labelKey, value }) => ({ label: formatMessage(messages[labelKey]), value }));
449
451
 
450
- const handleCarouselLinkTypeChange = (cardIndex, value) => {
452
+ // "When tapped, open" for a card: App turns the card action off, a link type turns it on
453
+ const handleCarouselTapActionChange = (cardIndex, value) => {
451
454
  const currentData = getCurrentCarouselData();
452
455
  const card = currentData[cardIndex];
456
+ const button = card?.buttons?.[0];
457
+ const currentValue = button?.actionOnClick ? (button?.linkType || DEEP_LINK) : TAP_ACTION_APP;
458
+ if (value === currentValue) return;
459
+ const isApp = value === TAP_ACTION_APP;
453
460
  const updatedButtons = [...card?.buttons];
454
- updatedButtons[0] = {
455
- ...updatedButtons[0],
456
- linkType: value,
461
+ updatedButtons[0] = {
462
+ ...button,
463
+ actionOnClick: !isApp,
464
+ linkType: isApp ? DEEP_LINK : value,
457
465
  deepLinkValue: '',
458
466
  externalLinkValue: '',
459
- deepLinkKeys: []
467
+ deepLinkKeys: [],
468
+ // A new link stays open until its Save is clicked
469
+ isSaved: isApp ? undefined : false,
460
470
  };
461
471
  updateCarouselCard(cardIndex, { buttons: updatedButtons });
462
- // Clear errors when link type changes
463
472
  updateCarouselLinkError(cardIndex, 'deepLink', null);
464
473
  updateCarouselLinkError(cardIndex, 'externalLink', null);
465
474
  updateCarouselLinkError(cardIndex, 'deepLinkKeys', null);
466
475
  };
467
476
 
477
+ const setCarouselTapLinkSaved = (cardIndex, isSaved) => {
478
+ const card = getCurrentCarouselData()[cardIndex];
479
+ const updatedButtons = [...card?.buttons];
480
+ updatedButtons[0] = { ...updatedButtons[0], isSaved };
481
+ updateCarouselCard(cardIndex, { buttons: updatedButtons });
482
+ };
483
+
468
484
  const handleCarouselDeepLinkChange = (cardIndex, value) => {
469
485
  const currentData = getCurrentCarouselData();
470
486
  const card = currentData[cardIndex];
@@ -492,16 +508,15 @@ const MediaUploaders = ({
492
508
  updateCarouselLinkError(cardIndex, 'externalLink', error);
493
509
  };
494
510
 
495
- const handleCarouselDeepLinkKeysChange = (cardIndex, value) => {
511
+ // Stores "key=value" for the configured key being typed into
512
+ const handleCarouselDeepLinkKeysChange = (cardIndex, configuredKeys, key, value) => {
496
513
  const currentData = getCurrentCarouselData();
497
514
  const card = currentData[cardIndex];
498
515
  const updatedButtons = [...card?.buttons];
499
- // Parse comma-separated values into array
500
- const keysArray = value?.split(',')?.map((key) => key?.trim())?.filter((key) => key?.length > 0);
516
+ const keysArray = setDeepLinkParamValue(updatedButtons[0]?.deepLinkKeys, configuredKeys, key, value);
501
517
  updatedButtons[0] = { ...updatedButtons[0], deepLinkKeys: keysArray };
502
518
  updateCarouselCard(cardIndex, { buttons: updatedButtons });
503
- // Validate deep link keys
504
- const error = keysArray?.length === 0 ? formatMessage(messages.deepLinkKeysRequired) : null;
519
+ const error = hasAllDeepLinkParams(keysArray, configuredKeys) ? null : formatMessage(messages.deepLinkKeysRequired);
505
520
  updateCarouselLinkError(cardIndex, 'deepLinkKeys', error);
506
521
  };
507
522
 
@@ -554,25 +569,50 @@ const MediaUploaders = ({
554
569
  );
555
570
  };
556
571
 
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
- );
572
+ // Called by the box as (index, data): Re upload passes an empty videoSrc
573
+ const handleCarouselVideoChange = (cardIndex, data = {}) => {
574
+ const { videoSrc = '', previewUrl = '' } = data;
575
+ if (!videoSrc) {
576
+ // Re upload clicks the page's first "videoFileName" input, which may be another card's
577
+ reuploadCardRef.current = cardIndex;
578
+ }
579
+ updateCarouselCard(cardIndex, { videoSrc, videoPreviewImg: videoSrc ? previewUrl : '' });
580
+ };
581
+
582
+ const renderCarouselVideoComponent = (cardIndex) => {
583
+ const card = getCurrentCarouselData()?.[cardIndex];
584
+
585
+ // Track the uploading card; the completion effect below writes the result into it
586
+ const handleCarouselVideoUpload = (file, assetType, fileParams, index) => {
587
+ const targetCard = reuploadCardRef.current ?? cardIndex;
588
+ reuploadCardRef.current = null;
589
+ uploadIdRef.current += 1;
590
+ setUploadingCardIndex(targetCard);
591
+ setCurrentUploadId(uploadIdRef.current);
592
+ return uploadMpushAsset(file, assetType, fileParams, index);
593
+ };
594
+
595
+ return (
596
+ <CapVideoUpload
597
+ key={`carousel-video-${activeTab}-${cardIndex}`}
598
+ index={activeTab === ANDROID ? 0 : 1}
599
+ allowedExtensionsRegex={ALLOWED_EXTENSIONS_VIDEO_REGEX}
600
+ videoSize={MPUSH_VIDEO_SIZE}
601
+ isFullMode={isFullMode}
602
+ uploadAsset={handleCarouselVideoUpload}
603
+ uploadedAssetList={card?.videoSrc ? { videoSrc: card.videoSrc, previewUrl: card.videoPreviewImg || '' } : {}}
604
+ onVideoUploadUpdateAssestList={(_index, data) => handleCarouselVideoChange(cardIndex, data)}
605
+ videoData={{}}
606
+ className="cap-custom-video-upload"
607
+ formClassName="mpush-video-upload"
608
+ channel={MOBILE_PUSH_CHANNEL}
609
+ errorMessage={formatMessage(messages.videoErrorMessage)}
610
+ showVideoNameAndDuration={false}
611
+ showReUploadButton
612
+ mediaType="video"
613
+ />
614
+ );
615
+ };
576
616
 
577
617
  const renderCarouselActionLinks = (cardIndex) => {
578
618
  const currentData = getCurrentCarouselData();
@@ -584,178 +624,196 @@ const MediaUploaders = ({
584
624
  }
585
625
 
586
626
  const button = card?.buttons[0]; // We're handling only one button for now
627
+ const tapAction = button?.actionOnClick ? (button?.linkType || DEEP_LINK) : TAP_ACTION_APP;
587
628
 
588
629
  // Use the callback creator instead of useCallback inside render function
589
630
  const onButtonTagSelect = createCarouselButtonTagSelectCallback(cardIndex);
590
631
 
632
+ const toArray = (value) => {
633
+ if (Array.isArray(value)) return value;
634
+ return value ? [value] : [];
635
+ };
636
+ const keysFromSelection = toArray(findSelectedDeepLink(deepLink, button?.deepLinkValue)?.keys);
637
+ const savedKeys = toArray(button?.deepLinkKeys);
638
+ // One input per configured key
639
+ const deepLinkInputKeys = keysFromSelection;
640
+ const showDeepLinkKeys = tapAction === DEEP_LINK && button?.deepLinkValue && keysFromSelection.length > 0;
641
+
642
+ // Only errors from typed values show inline (as in Notification tap); an empty link just keeps Save off
643
+ const deepLinkError = carouselLinkErrors[`${cardIndex}-deepLink`];
644
+ const externalLinkError = carouselLinkErrors[`${cardIndex}-externalLink`];
645
+ const deepLinkKeysError = carouselLinkErrors[`${cardIndex}-deepLinkKeys`];
646
+ const cardIssue = getCarouselCardIssue(card, deepLink);
647
+ const isLinkIncomplete = [
648
+ CAROUSEL_CARD_ISSUE.DEEP_LINK,
649
+ CAROUSEL_CARD_ISSUE.DEEP_LINK_KEYS,
650
+ CAROUSEL_CARD_ISSUE.EXTERNAL_LINK,
651
+ ].includes(cardIssue);
652
+
653
+ // Link chosen and saved: collapsed row, as for a saved button
654
+ const isLinkSaved = tapAction !== TAP_ACTION_APP && button?.isSaved !== false;
655
+ const isLinkSaveDisabled = isLinkIncomplete || !!(deepLinkError || externalLinkError || deepLinkKeysError);
656
+ const savedLinkText = tapAction === DEEP_LINK
657
+ ? (findSelectedDeepLink(deepLink, button?.deepLinkValue)?.label || button?.deepLinkValue)
658
+ : button?.externalLinkValue;
659
+ const removeCardTapLink = () => handleCarouselTapActionChange(cardIndex, TAP_ACTION_APP);
660
+
661
+ if (isLinkSaved) {
662
+ return (
663
+ <>
664
+ <CapDivider />
665
+ <CapRow useLegacy className="creatives-mpush-actions">
666
+ <CapRow type="flex" align="middle" noWrap className="mpush-section-heading">
667
+ <CapHeading type="h4" className="mpush-actions">
668
+ <FormattedMessage {...messages.cardTap} />
669
+ </CapHeading>
670
+ <CapLabel className="optional-text">
671
+ <FormattedMessage {...messages.optionalText} />
672
+ </CapLabel>
673
+ </CapRow>
674
+ <CapLabel className="mpush-tap-description">
675
+ <FormattedMessage {...messages.cardTapDescription} />
676
+ </CapLabel>
677
+ <SavedTapLink
678
+ linkType={tapAction}
679
+ linkText={savedLinkText}
680
+ onEdit={() => setCarouselTapLinkSaved(cardIndex, false)}
681
+ onDelete={removeCardTapLink}
682
+ formatMessage={formatMessage}
683
+ />
684
+ </CapRow>
685
+ </>
686
+ );
687
+ }
688
+
591
689
  return (
592
690
  <>
593
691
  <CapDivider />
594
692
  <CapRow useLegacy className="creatives-mpush-actions">
595
- <CapRow useLegacy className="mpush-actions-main">
693
+ <CapRow type="flex" align="middle" noWrap className="mpush-section-heading">
596
694
  <CapHeading type="h4" className="mpush-actions">
597
- <FormattedMessage {...messages.buttonsAndLinks} />
695
+ <FormattedMessage {...messages.cardTap} />
598
696
  </CapHeading>
599
697
  <CapLabel className="optional-text">
600
698
  <FormattedMessage {...messages.optionalText} />
601
699
  </CapLabel>
602
700
  </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} />
701
+ <CapLabel className="mpush-tap-description">
702
+ <FormattedMessage {...messages.cardTapDescription} />
703
+ </CapLabel>
704
+ <CapRow type="flex" noWrap gap={16} className="mpush-tap-row">
705
+ <CapColumn flex="0 0 30%" className="mpush-tap-action">
706
+ <CapHeading type="h4" className="mpush-tap-label">
707
+ <FormattedMessage {...messages.whenTappedOpen} />
708
+ </CapHeading>
709
+ <CapSelect.CapCustomSelect
710
+ id={`mobile-push-carousel-tap-action-${activeTab}-${cardIndex}`}
711
+ width="100%"
712
+ options={tapActionOptions}
713
+ value={tapAction}
714
+ onChange={(value) => handleCarouselTapActionChange(cardIndex, value)}
715
+ />
716
+ </CapColumn>
717
+ {tapAction === DEEP_LINK && (
718
+ <CapColumn flex="1 1 0" className="mpush-tap-link">
719
+ <CapHeading type="h4" className="mpush-tap-label">
720
+ <FormattedMessage {...messages.tapActionDeepLink} />
620
721
  </CapHeading>
621
722
  <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}`}
723
+ width="100%"
724
+ options={(() => {
725
+ const options = [...(deepLink || [])];
726
+ // If the current value is not in the options, add it
727
+ if (button?.deepLinkValue && !options.find((opt) => opt.value === button?.deepLinkValue)) {
728
+ options.push({
729
+ value: button?.deepLinkValue,
730
+ label: button?.deepLinkValue,
731
+ });
732
+ }
733
+ return options;
734
+ })()}
735
+ value={button?.deepLinkValue}
736
+ onChange={(value) => handleCarouselDeepLinkChange(cardIndex, value)}
737
+ key={`mobile-push-deep-link-type-${activeTab}-${cardIndex}`}
626
738
  selectPlaceholder={formatMessage(messages.selectDeepLink)}
627
739
  />
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)}
740
+ {deepLinkError && (
741
+ <CapError className="mobile-push-carousel-deep-link-error">
742
+ {deepLinkError}
743
+ </CapError>
744
+ )}
745
+ {showDeepLinkKeys && (
746
+ <CapRow className="mpush-tap-deep-link-keys">
747
+ <CapHeading type="h4" className="deep-link-keys-heading">
748
+ {formatMessage(messages.deepLinkKeys)}
664
749
  </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}
676
- />
750
+ {deepLinkInputKeys.map((key, keyIndex) => (
751
+ <CapRow useLegacy key={key} className="mpush-deep-link-key">
752
+ <CapLabel type="label2" className="deep-link-keys-value">
753
+ {key}
754
+ </CapLabel>
755
+ <CapInput
756
+ id={keyIndex === 0
757
+ ? `mobile-push-carousel-deep-link-keys-input-${activeTab}-${cardIndex}`
758
+ : `mobile-push-carousel-deep-link-keys-input-${activeTab}-${cardIndex}-${keyIndex}`}
759
+ onChange={(e) => handleCarouselDeepLinkKeysChange(cardIndex, deepLinkInputKeys, key, e.target.value)}
760
+ placeholder={formatMessage(messages.deepLinkKeysPlaceholder, { key })}
761
+ value={getDeepLinkParamValue(savedKeys, key)}
762
+ size="default"
763
+ error={keyIndex === deepLinkInputKeys.length - 1 ? deepLinkKeysError : undefined}
764
+ />
765
+ </CapRow>
766
+ ))}
677
767
  </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(', ');
768
+ )}
769
+ </CapColumn>
770
+ )}
771
+ {tapAction === EXTERNAL_LINK && (
772
+ <CapColumn flex="1 1 0" className="mpush-tap-link">
773
+ <CapRow type="flex" align="middle" justify="space-between" noWrap className="mpush-tap-link-header">
774
+ <CapHeading type="h4" className="mpush-tap-label">
775
+ <FormattedMessage {...messages.url} />
776
+ </CapHeading>
777
+ <TagList
778
+ moduleFilterEnabled={
779
+ location?.query?.type !== "embedded"
733
780
  }
734
- })()}
735
- </CapLabel>
781
+ label={formatMessage(messages.addLabels)}
782
+ onTagSelect={onButtonTagSelect}
783
+ onContextChange={handleOnTagsContextChange}
784
+ location={location}
785
+ tags={tags}
786
+ injectedTags={injectedTags}
787
+ selectedOfferDetails={selectedOfferDetails}
788
+ />
789
+ </CapRow>
736
790
  <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 || "")}
791
+ id={`mobile-push-external-link-input-${activeTab}-${cardIndex}`}
792
+ onChange={(e) => handleCarouselExternalLinkChange(cardIndex, e.target.value)}
793
+ placeholder={formatMessage(messages.enterUrl)}
794
+ value={button?.externalLinkValue}
753
795
  size="default"
754
- style={{ marginTop: "10px" }}
755
- error={carouselLinkErrors[`${cardIndex}-deepLinkKeys`]}
796
+ isRequired
756
797
  />
798
+ {externalLinkError && (
799
+ <CapError className="mobile-push-carousel-external-link-error">
800
+ {externalLinkError}
801
+ </CapError>
802
+ )}
757
803
  </CapColumn>
758
- </CapRow>
804
+ )}
805
+ </CapRow>
806
+ {tapAction === TAP_ACTION_APP ? (
807
+ <CapLabel className="mpush-tap-description mpush-tap-help">
808
+ <FormattedMessage {...messages.cardTapAppHelp} />
809
+ </CapLabel>
810
+ ) : (
811
+ <TapLinkSaveDelete
812
+ isSaveDisabled={isLinkSaveDisabled}
813
+ onSave={() => setCarouselTapLinkSaved(cardIndex, true)}
814
+ onDelete={removeCardTapLink}
815
+ formatMessage={formatMessage}
816
+ />
759
817
  )}
760
818
  </CapRow>
761
819
  </>
@@ -804,17 +862,30 @@ const MediaUploaders = ({
804
862
  }));
805
863
  };
806
864
 
865
+ const isMaxCarouselCardsReached = getCurrentCarouselData()?.length >= MAX_CAROUSEL_ALLOWED;
866
+ let addCardTooltipTitle = "";
867
+ if (isMaxCarouselCardsReached) {
868
+ addCardTooltipTitle = formatMessage(messages.carouselMaxCardTooltip, { max: MAX_CAROUSEL_ALLOWED });
869
+ } else if (hasIncompleteCard) {
870
+ addCardTooltipTitle = formatMessage(messages.completeCardToAdd);
871
+ }
872
+
807
873
  const operations = (
808
874
  <>
809
875
  <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>
876
+ <CapTooltip title={addCardTooltipTitle}>
877
+ {/* Disabled buttons fire no hover events; the wrapper lets the tooltip show */}
878
+ <CapRow className="button-disabled-tooltip-wrapper">
879
+ <CapButton
880
+ onClick={addCarouselCard}
881
+ type="link"
882
+ className="add-carousel-content-button"
883
+ disabled={isMaxCarouselCardsReached || hasIncompleteCard}
884
+ >
885
+ <CapIcon type="plus" />
886
+ </CapButton>
887
+ </CapRow>
888
+ </CapTooltip>
818
889
  </>
819
890
  );
820
891
 
@@ -839,7 +910,6 @@ const MediaUploaders = ({
839
910
  {
840
911
  value: VIDEO.toLowerCase(),
841
912
  label: formatMessage(messages.mediaVideo),
842
- disabled: true,
843
913
  },
844
914
  ]}
845
915
  value={carouselMediaType}
@@ -893,8 +963,16 @@ const MediaUploaders = ({
893
963
  const previousDataKey = previousUploadDataRef.current;
894
964
 
895
965
  if (currentDataKey !== previousDataKey) {
896
- // Update the specific card that was uploading
897
- updateCarouselCard(uploadingCardIndex, { imageUrl: uploadedData?.metaInfo?.secure_file_path });
966
+ const {
967
+ secure_file_path: filePath,
968
+ video_file_path_preview: videoPreview = '',
969
+ preview_image_url: previewImage = '',
970
+ } = uploadedData.metaInfo;
971
+ const isVideoCard = getCurrentCarouselData()?.[uploadingCardIndex]?.mediaType === VIDEO.toLowerCase();
972
+ // Update the specific card that was uploading (videoPreviewImg is what the phone preview shows)
973
+ updateCarouselCard(uploadingCardIndex, isVideoCard
974
+ ? { videoSrc: filePath, videoPreviewImg: videoPreview || previewImage }
975
+ : { imageUrl: filePath });
898
976
 
899
977
  // Store this upload data as "processed" to avoid reprocessing
900
978
  previousUploadDataRef.current = currentDataKey;
@@ -905,7 +983,21 @@ const MediaUploaders = ({
905
983
  }
906
984
  }
907
985
  }
908
- }, [mediaType, imageData, uploadingCardIndex, currentUploadId, activeTab, updateCarouselCard]);
986
+ }, [mediaType, imageData, uploadingCardIndex, currentUploadId, activeTab, updateCarouselCard, getCurrentCarouselData]);
987
+
988
+ // Editing a saved video carousel: show video boxes, not the default image ones.
989
+ // Follows the cards' type only when it changes, so a radio click isn't undone.
990
+ useEffect(() => {
991
+ if (mediaType !== CAROUSEL) {
992
+ prevCardTypeRef.current = null;
993
+ return;
994
+ }
995
+ const savedCardType = carouselData?.[0]?.mediaType;
996
+ if (savedCardType && savedCardType !== prevCardTypeRef.current) {
997
+ setCarouselMediaType(savedCardType);
998
+ }
999
+ prevCardTypeRef.current = savedCardType;
1000
+ }, [mediaType, carouselData]);
909
1001
 
910
1002
  if (mediaType === IMAGE) return renderImageComponent();
911
1003
  if (mediaType === VIDEO) return renderVideoComponent();