@capillarytech/creatives-library 8.0.125-alpha.3 → 8.0.125-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/v2Containers/MobilePushNew/index.js +294 -17
package/package.json
CHANGED
|
@@ -597,15 +597,17 @@ const MobilePushNew = ({
|
|
|
597
597
|
}));
|
|
598
598
|
}
|
|
599
599
|
|
|
600
|
+
let androidButtonsValue = [];
|
|
601
|
+
if (Array.isArray(androidCtas)) {
|
|
602
|
+
androidButtonsValue = androidCtas;
|
|
603
|
+
} else if (Array.isArray(androidCta)) {
|
|
604
|
+
androidButtonsValue = androidCta;
|
|
605
|
+
}
|
|
600
606
|
const androidContentData = {
|
|
601
607
|
title: androidTitle,
|
|
602
608
|
message: androidMessage,
|
|
603
609
|
mediaType: androidMediaType,
|
|
604
|
-
buttons:
|
|
605
|
-
if (Array.isArray(androidCtas)) return androidCtas;
|
|
606
|
-
if (Array.isArray(androidCta)) return androidCta;
|
|
607
|
-
return [];
|
|
608
|
-
})(),
|
|
610
|
+
buttons: androidButtonsValue,
|
|
609
611
|
actionOnClick: false,
|
|
610
612
|
linkType: DEEP_LINK,
|
|
611
613
|
deepLinkValue: "",
|
|
@@ -643,17 +645,14 @@ const MobilePushNew = ({
|
|
|
643
645
|
androidContentData.linkType = DEEP_LINK;
|
|
644
646
|
androidContentData.deepLinkValue = androidMainCta.actionLink;
|
|
645
647
|
androidContentData.externalLinkValue = "";
|
|
648
|
+
} else if (androidMainCta.actionLink.startsWith('http://') || androidMainCta.actionLink.startsWith('https://')) {
|
|
649
|
+
androidContentData.linkType = EXTERNAL_LINK;
|
|
650
|
+
androidContentData.externalLinkValue = androidMainCta.actionLink;
|
|
651
|
+
androidContentData.deepLinkValue = "";
|
|
646
652
|
} else {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
androidContentData.externalLinkValue = androidMainCta.actionLink;
|
|
651
|
-
androidContentData.deepLinkValue = "";
|
|
652
|
-
} else {
|
|
653
|
-
androidContentData.linkType = DEEP_LINK;
|
|
654
|
-
androidContentData.deepLinkValue = androidMainCta.actionLink;
|
|
655
|
-
androidContentData.externalLinkValue = "";
|
|
656
|
-
}
|
|
653
|
+
androidContentData.linkType = DEEP_LINK;
|
|
654
|
+
androidContentData.deepLinkValue = androidMainCta.actionLink;
|
|
655
|
+
androidContentData.externalLinkValue = "";
|
|
657
656
|
}
|
|
658
657
|
} else {
|
|
659
658
|
// If no CTA data, ensure both link values are empty
|
|
@@ -756,11 +755,15 @@ const MobilePushNew = ({
|
|
|
756
755
|
}));
|
|
757
756
|
}
|
|
758
757
|
|
|
758
|
+
let iosButtonsValue = [];
|
|
759
|
+
if (Array.isArray(ctas)) {
|
|
760
|
+
iosButtonsValue = ctas;
|
|
761
|
+
}
|
|
759
762
|
const iosContentData = {
|
|
760
763
|
title: iosTitle,
|
|
761
764
|
message: iosMessage,
|
|
762
765
|
mediaType: iosMediaType,
|
|
763
|
-
buttons:
|
|
766
|
+
buttons: iosButtonsValue,
|
|
764
767
|
actionOnClick: false,
|
|
765
768
|
linkType: DEEP_LINK,
|
|
766
769
|
deepLinkValue: "",
|
|
@@ -816,6 +819,260 @@ const MobilePushNew = ({
|
|
|
816
819
|
}
|
|
817
820
|
}, [editData?.templateDetails, isEditMode, params?.id, resetFormData]);
|
|
818
821
|
|
|
822
|
+
// Data population useEffect - for library mode (not full mode) using templateData
|
|
823
|
+
useEffect(() => {
|
|
824
|
+
if (isFullMode || !templateData || isEmpty(templateData)) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// Always reset form state before populating new template data
|
|
829
|
+
resetFormData();
|
|
830
|
+
|
|
831
|
+
// templateData is expected to have a similar structure as editData.templateDetails
|
|
832
|
+
const { name = "", versions = {} } = templateData || {};
|
|
833
|
+
const templateContent = versions?.base || {};
|
|
834
|
+
|
|
835
|
+
if (isEmpty(templateContent)) {
|
|
836
|
+
setSpin(false);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
setTemplateName(name);
|
|
841
|
+
// Process Android content
|
|
842
|
+
const androidContentType = templateContent?.ANDROID;
|
|
843
|
+
if (!isEmpty(androidContentType)) {
|
|
844
|
+
const {
|
|
845
|
+
title: androidTitle = "",
|
|
846
|
+
message: androidMessage = "",
|
|
847
|
+
ctas: androidCta = [],
|
|
848
|
+
expandableDetails: androidExpandableDetails = {},
|
|
849
|
+
image: androidImage = "",
|
|
850
|
+
cta: androidMainCta = null,
|
|
851
|
+
} = androidContentType || {};
|
|
852
|
+
const { style: androidStyle, ctas: androidCtas = [], image: androidExpandableImage = "" } = androidExpandableDetails || {};
|
|
853
|
+
let androidMediaType = NONE;
|
|
854
|
+
let androidImageSrc = "";
|
|
855
|
+
let androidVideoSrc = "";
|
|
856
|
+
let androidVideoPreview = "";
|
|
857
|
+
let carouselDataFromTemplate = [];
|
|
858
|
+
if (androidStyle === BIG_PICTURE) {
|
|
859
|
+
androidMediaType = IMAGE;
|
|
860
|
+
androidImageSrc = androidExpandableImage || androidImage;
|
|
861
|
+
} else if (androidStyle === BIG_TEXT) {
|
|
862
|
+
androidMediaType = NONE;
|
|
863
|
+
} else if (androidStyle === MANUAL_CAROUSEL) {
|
|
864
|
+
androidMediaType = CAROUSEL;
|
|
865
|
+
}
|
|
866
|
+
if (androidExpandableDetails?.media && Array.isArray(androidExpandableDetails.media) && androidExpandableDetails.media.length > 0) {
|
|
867
|
+
const mediaItem = androidExpandableDetails.media[0];
|
|
868
|
+
if (mediaItem.type === VIDEO) {
|
|
869
|
+
if (mediaItem.url && mediaItem.url.toLowerCase().includes('.gif')) {
|
|
870
|
+
androidMediaType = GIF;
|
|
871
|
+
} else {
|
|
872
|
+
androidMediaType = VIDEO;
|
|
873
|
+
}
|
|
874
|
+
androidVideoSrc = mediaItem.url;
|
|
875
|
+
androidVideoPreview = mediaItem.url;
|
|
876
|
+
} else if (mediaItem.type === GIF) {
|
|
877
|
+
androidMediaType = GIF;
|
|
878
|
+
androidVideoSrc = mediaItem.url;
|
|
879
|
+
androidVideoPreview = mediaItem.url;
|
|
880
|
+
}
|
|
881
|
+
} else if (androidImage && (androidImage.includes('.mp4') || androidImage.includes('.mov'))) {
|
|
882
|
+
androidMediaType = VIDEO;
|
|
883
|
+
androidVideoSrc = androidImage;
|
|
884
|
+
androidVideoPreview = androidImage;
|
|
885
|
+
} else if (androidImage && androidImage.toLowerCase().includes('.gif')) {
|
|
886
|
+
androidMediaType = GIF;
|
|
887
|
+
androidVideoSrc = androidImage;
|
|
888
|
+
androidVideoPreview = androidImage;
|
|
889
|
+
} else if ((androidExpandableDetails?.style === MANUAL_CAROUSEL || androidContentType?.type === CAROUSEL) && androidExpandableDetails?.carouselData) {
|
|
890
|
+
androidMediaType = CAROUSEL;
|
|
891
|
+
carouselDataFromTemplate = androidExpandableDetails.carouselData.map((card) => ({
|
|
892
|
+
mediaType: card.mediaType || IMAGE.toLowerCase(),
|
|
893
|
+
imageUrl: card.imageUrl || '',
|
|
894
|
+
videoSrc: card.videoSrc || '',
|
|
895
|
+
buttons: card.buttons || [],
|
|
896
|
+
}));
|
|
897
|
+
}
|
|
898
|
+
let androidButtonsValue = [];
|
|
899
|
+
if (Array.isArray(androidCtas)) {
|
|
900
|
+
androidButtonsValue = androidCtas;
|
|
901
|
+
} else if (Array.isArray(androidCta)) {
|
|
902
|
+
androidButtonsValue = androidCta;
|
|
903
|
+
}
|
|
904
|
+
const androidContentData = {
|
|
905
|
+
title: androidTitle,
|
|
906
|
+
message: androidMessage,
|
|
907
|
+
mediaType: androidMediaType,
|
|
908
|
+
buttons: androidButtonsValue,
|
|
909
|
+
actionOnClick: false,
|
|
910
|
+
linkType: DEEP_LINK,
|
|
911
|
+
deepLinkValue: "",
|
|
912
|
+
externalLinkValue: "",
|
|
913
|
+
imageSrc: androidImageSrc,
|
|
914
|
+
videoSrc: androidVideoSrc,
|
|
915
|
+
videoPreview: androidVideoPreview,
|
|
916
|
+
carouselData: carouselDataFromTemplate,
|
|
917
|
+
};
|
|
918
|
+
setAndroidContent(androidContentData);
|
|
919
|
+
if (androidImageSrc) {
|
|
920
|
+
setUpdateMpushImageSrc(androidImageSrc, 0, IMAGE);
|
|
921
|
+
}
|
|
922
|
+
if (androidVideoSrc) {
|
|
923
|
+
setUpdateMpushVideoSrc(0, {
|
|
924
|
+
videoSrc: androidVideoSrc,
|
|
925
|
+
previewUrl: androidVideoPreview,
|
|
926
|
+
}, true);
|
|
927
|
+
}
|
|
928
|
+
if (androidMainCta?.actionLink) {
|
|
929
|
+
androidContentData.actionOnClick = true;
|
|
930
|
+
if (androidMainCta.type === EXTERNAL_URL) {
|
|
931
|
+
androidContentData.linkType = EXTERNAL_LINK;
|
|
932
|
+
androidContentData.externalLinkValue = androidMainCta.actionLink;
|
|
933
|
+
androidContentData.deepLinkValue = "";
|
|
934
|
+
} else if (androidMainCta.type === DEEP_LINK) {
|
|
935
|
+
androidContentData.linkType = DEEP_LINK;
|
|
936
|
+
androidContentData.deepLinkValue = androidMainCta.actionLink;
|
|
937
|
+
androidContentData.externalLinkValue = "";
|
|
938
|
+
} else if (androidMainCta.actionLink.startsWith('http://') || androidMainCta.actionLink.startsWith('https://')) {
|
|
939
|
+
androidContentData.linkType = EXTERNAL_LINK;
|
|
940
|
+
androidContentData.externalLinkValue = androidMainCta.actionLink;
|
|
941
|
+
androidContentData.deepLinkValue = "";
|
|
942
|
+
} else {
|
|
943
|
+
androidContentData.linkType = DEEP_LINK;
|
|
944
|
+
androidContentData.deepLinkValue = androidMainCta.actionLink;
|
|
945
|
+
androidContentData.externalLinkValue = "";
|
|
946
|
+
}
|
|
947
|
+
} else {
|
|
948
|
+
androidContentData.deepLinkValue = "";
|
|
949
|
+
androidContentData.externalLinkValue = "";
|
|
950
|
+
}
|
|
951
|
+
const androidButtons = androidExpandableDetails?.ctas || [];
|
|
952
|
+
if (androidButtons.length > 0) {
|
|
953
|
+
const ctaDataFromAndroid = androidButtons.map((button, index) => ({
|
|
954
|
+
text: button.actionText || button.label || "",
|
|
955
|
+
index,
|
|
956
|
+
url: button.actionLink || "",
|
|
957
|
+
urlType: button.type || DEEP_LINK,
|
|
958
|
+
ctaType: index === 0 ? PRIMARY : SECONDARY,
|
|
959
|
+
isSaved: true,
|
|
960
|
+
}));
|
|
961
|
+
setCtaDataAndroid(ctaDataFromAndroid);
|
|
962
|
+
setPrimaryButtonAndroid(androidButtons.length >= 1);
|
|
963
|
+
setSecondaryButtonAndroid(androidButtons.length >= 2);
|
|
964
|
+
} else {
|
|
965
|
+
setCtaDataAndroid([]);
|
|
966
|
+
setPrimaryButtonAndroid(false);
|
|
967
|
+
setSecondaryButtonAndroid(false);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
// Process iOS content
|
|
971
|
+
const iosContentType = templateContent?.IOS;
|
|
972
|
+
if (!isEmpty(iosContentType)) {
|
|
973
|
+
const {
|
|
974
|
+
title: iosTitle = "",
|
|
975
|
+
message: iosMessage = "",
|
|
976
|
+
ctas = [],
|
|
977
|
+
expandableDetails: iosExpandableDetails = {},
|
|
978
|
+
image: iosImage = "",
|
|
979
|
+
} = iosContentType || {};
|
|
980
|
+
const { style: iosStyle, image: iosExpandableImage = "" } = iosExpandableDetails || {};
|
|
981
|
+
let iosMediaType = NONE;
|
|
982
|
+
let iosImageSrc = "";
|
|
983
|
+
let iosVideoSrc = "";
|
|
984
|
+
let iosVideoPreview = "";
|
|
985
|
+
let carouselDataFromTemplate = [];
|
|
986
|
+
if (iosStyle === BIG_PICTURE) {
|
|
987
|
+
iosMediaType = IMAGE;
|
|
988
|
+
iosImageSrc = iosExpandableImage || iosImage;
|
|
989
|
+
} else if (iosStyle === BIG_TEXT) {
|
|
990
|
+
iosMediaType = NONE;
|
|
991
|
+
} else if (iosStyle === MANUAL_CAROUSEL) {
|
|
992
|
+
iosMediaType = CAROUSEL;
|
|
993
|
+
}
|
|
994
|
+
if (iosExpandableDetails?.media && Array.isArray(iosExpandableDetails.media) && iosExpandableDetails.media.length > 0) {
|
|
995
|
+
const mediaItem = iosExpandableDetails.media[0];
|
|
996
|
+
if (mediaItem.type === VIDEO) {
|
|
997
|
+
if (mediaItem.url && mediaItem.url.toLowerCase().includes('.gif')) {
|
|
998
|
+
iosMediaType = GIF;
|
|
999
|
+
} else {
|
|
1000
|
+
iosMediaType = VIDEO;
|
|
1001
|
+
}
|
|
1002
|
+
iosVideoSrc = mediaItem.url;
|
|
1003
|
+
iosVideoPreview = mediaItem.url;
|
|
1004
|
+
} else if (mediaItem.type === GIF) {
|
|
1005
|
+
iosMediaType = GIF;
|
|
1006
|
+
iosVideoSrc = mediaItem.url;
|
|
1007
|
+
iosVideoPreview = mediaItem.url;
|
|
1008
|
+
}
|
|
1009
|
+
} else if (iosImage && (iosImage.includes('.mp4') || iosImage.includes('.mov'))) {
|
|
1010
|
+
iosMediaType = VIDEO;
|
|
1011
|
+
iosVideoSrc = iosImage;
|
|
1012
|
+
iosVideoPreview = iosImage;
|
|
1013
|
+
} else if (iosImage && iosImage.toLowerCase().includes('.gif')) {
|
|
1014
|
+
iosMediaType = GIF;
|
|
1015
|
+
iosVideoSrc = iosImage;
|
|
1016
|
+
iosVideoPreview = iosImage;
|
|
1017
|
+
} else if ((iosExpandableDetails?.style === MANUAL_CAROUSEL || iosContentType?.type === CAROUSEL) && iosExpandableDetails?.carouselData) {
|
|
1018
|
+
iosMediaType = CAROUSEL;
|
|
1019
|
+
carouselDataFromTemplate = iosExpandableDetails.carouselData.map((card) => ({
|
|
1020
|
+
mediaType: card.mediaType || IMAGE.toLowerCase(),
|
|
1021
|
+
imageUrl: card.imageUrl || '',
|
|
1022
|
+
videoSrc: card.videoSrc || '',
|
|
1023
|
+
buttons: card.buttons || [],
|
|
1024
|
+
}));
|
|
1025
|
+
}
|
|
1026
|
+
let iosButtonsValue = [];
|
|
1027
|
+
if (Array.isArray(ctas)) {
|
|
1028
|
+
iosButtonsValue = ctas;
|
|
1029
|
+
}
|
|
1030
|
+
const iosContentData = {
|
|
1031
|
+
title: iosTitle,
|
|
1032
|
+
message: iosMessage,
|
|
1033
|
+
mediaType: iosMediaType,
|
|
1034
|
+
buttons: iosButtonsValue,
|
|
1035
|
+
actionOnClick: false,
|
|
1036
|
+
linkType: DEEP_LINK,
|
|
1037
|
+
deepLinkValue: "",
|
|
1038
|
+
externalLinkValue: "",
|
|
1039
|
+
imageSrc: iosImageSrc,
|
|
1040
|
+
videoSrc: iosVideoSrc,
|
|
1041
|
+
videoPreview: iosVideoPreview,
|
|
1042
|
+
carouselData: carouselDataFromTemplate,
|
|
1043
|
+
};
|
|
1044
|
+
setIosContent(iosContentData);
|
|
1045
|
+
if (iosImageSrc) {
|
|
1046
|
+
setUpdateMpushImageSrc(iosImageSrc, 1, IMAGE);
|
|
1047
|
+
}
|
|
1048
|
+
if (iosVideoSrc) {
|
|
1049
|
+
setUpdateMpushVideoSrc(1, {
|
|
1050
|
+
videoSrc: iosVideoSrc,
|
|
1051
|
+
previewUrl: iosVideoPreview,
|
|
1052
|
+
}, true);
|
|
1053
|
+
}
|
|
1054
|
+
const iosButtons = iosExpandableDetails?.ctas || [];
|
|
1055
|
+
if (iosButtons.length > 0) {
|
|
1056
|
+
const ctaDataFromIos = iosButtons.map((button, index) => ({
|
|
1057
|
+
text: button.actionText || button.label || "",
|
|
1058
|
+
index,
|
|
1059
|
+
url: button.actionLink || "",
|
|
1060
|
+
urlType: button.type || DEEP_LINK,
|
|
1061
|
+
ctaType: index === 0 ? PRIMARY : SECONDARY,
|
|
1062
|
+
isSaved: true,
|
|
1063
|
+
}));
|
|
1064
|
+
setCtaDataIos(ctaDataFromIos);
|
|
1065
|
+
setPrimaryButtonIos(iosButtons.length >= 1);
|
|
1066
|
+
setSecondaryButtonIos(iosButtons.length >= 2);
|
|
1067
|
+
} else {
|
|
1068
|
+
setCtaDataIos([]);
|
|
1069
|
+
setPrimaryButtonIos(false);
|
|
1070
|
+
setSecondaryButtonIos(false);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
setSpin(false);
|
|
1074
|
+
}, [isFullMode, templateData, resetFormData]);
|
|
1075
|
+
|
|
819
1076
|
// Determine platform support from accountData
|
|
820
1077
|
const isAndroidSupported = accountData?.configs?.android === '1';
|
|
821
1078
|
const isIosSupported = accountData?.configs?.ios === '1';
|
|
@@ -1107,6 +1364,7 @@ const MobilePushNew = ({
|
|
|
1107
1364
|
carouselLinkErrors,
|
|
1108
1365
|
updateCarouselLinkError,
|
|
1109
1366
|
linkProps: { deepLink },
|
|
1367
|
+
videoPreviewKey: videoState?.videoPreviewKey,
|
|
1110
1368
|
};
|
|
1111
1369
|
|
|
1112
1370
|
const ctaButtonProps = {
|
|
@@ -1332,6 +1590,25 @@ const MobilePushNew = ({
|
|
|
1332
1590
|
imageAdded: definitionMode === IMAGE.toLowerCase(),
|
|
1333
1591
|
});
|
|
1334
1592
|
|
|
1593
|
+
// --- BEGIN: Library mode communication fix ---
|
|
1594
|
+
if (!isFullMode) {
|
|
1595
|
+
// Send the created/edited template data to the consumer app
|
|
1596
|
+
const templateDataToSend = {
|
|
1597
|
+
...response,
|
|
1598
|
+
payload,
|
|
1599
|
+
};
|
|
1600
|
+
console.log('[MobilePushNew] Library mode: sending template data to consumer app:', templateDataToSend);
|
|
1601
|
+
if (window && window.parent) {
|
|
1602
|
+
console.log('[MobilePushNew] Calling window.parent.postMessage with MOBILEPUSH_TEMPLATE_SAVED');
|
|
1603
|
+
window.parent.postMessage({ type: 'MOBILEPUSH_TEMPLATE_SAVED', data: templateDataToSend }, '*');
|
|
1604
|
+
}
|
|
1605
|
+
if (typeof getFormLibraryData === 'function') {
|
|
1606
|
+
console.log('[MobilePushNew] Calling getFormLibraryData with template data');
|
|
1607
|
+
getFormLibraryData(templateDataToSend);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
// --- END: Library mode communication fix ---
|
|
1611
|
+
|
|
1335
1612
|
// Show success toast and refresh list after create (not edit)
|
|
1336
1613
|
if (!isEditMode && response && (response.templateId || response._id)) {
|
|
1337
1614
|
const message = `${intl.formatMessage(messages.templateCreateSuccess)}`;
|
|
@@ -1370,7 +1647,7 @@ const MobilePushNew = ({
|
|
|
1370
1647
|
resetFormData();
|
|
1371
1648
|
}
|
|
1372
1649
|
|
|
1373
|
-
if (getFormLibraryData) {
|
|
1650
|
+
if (getFormLibraryData && isFullMode) {
|
|
1374
1651
|
getFormLibraryData({ validity: true });
|
|
1375
1652
|
}
|
|
1376
1653
|
};
|