@capillarytech/creatives-library 9.0.50-alpha.1 → 9.0.50

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 (25) hide show
  1. package/package.json +1 -1
  2. package/v2Components/CommonTestAndPreview/UnifiedPreview/ViberPreviewContent.js +15 -106
  3. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -139
  4. package/v2Components/CommonTestAndPreview/constants.js +0 -2
  5. package/v2Components/CommonTestAndPreview/index.js +26 -240
  6. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/ViberPreviewContent.test.js +0 -364
  7. package/v2Components/CommonTestAndPreview/tests/utils.test.js +0 -49
  8. package/v2Components/CommonTestAndPreview/utils.js +0 -20
  9. package/v2Containers/CreativesContainer/index.js +4 -9
  10. package/v2Containers/CreativesContainer/tests/index.test.js +4 -3
  11. package/v2Containers/Rcs/carouselUtils.js +43 -13
  12. package/v2Containers/Rcs/index.js +32 -8
  13. package/v2Containers/Rcs/tests/carouselUtils.test.js +23 -4
  14. package/v2Containers/Rcs/tests/index.test.js +265 -3
  15. package/v2Containers/Rcs/tests/utils.test.js +59 -74
  16. package/v2Containers/Rcs/utils.js +9 -34
  17. package/v2Containers/Templates/_templates.scss +1 -179
  18. package/v2Containers/Templates/index.js +10 -97
  19. package/v2Containers/Viber/constants.js +0 -21
  20. package/v2Containers/Viber/index.js +43 -711
  21. package/v2Containers/Viber/index.scss +0 -175
  22. package/v2Containers/Viber/messages.js +0 -121
  23. package/v2Containers/Viber/tests/index.test.js +0 -80
  24. package/v2Components/CommonTestAndPreview/UnifiedPreview/ViberCarouselPreviewCards.js +0 -127
  25. package/v2Components/CommonTestAndPreview/UnifiedPreview/_viberCarouselPreviewCards.scss +0 -133
@@ -246,8 +246,6 @@ const CommonTestAndPreview = (props) => {
246
246
  const [smsFallbackPreviewText, setSmsFallbackPreviewText] = useState(undefined);
247
247
  // Track if a preview call has been made (to know when to use previewDataHtml vs raw content)
248
248
  const [hasPreviewCallBeenMade, setHasPreviewCallBeenMade] = useState(false);
249
- // Viber: tag values applied to preview only after explicit Update preview / Discard (not while typing)
250
- const [viberPreviewTagValues, setViberPreviewTagValues] = useState(null);
251
249
  const [previewDataHtml, setPreviewDataHtml] = useState(() => {
252
250
  // Initialize preview data based on channel
253
251
  if (channel === CHANNELS.EMAIL && formData) {
@@ -689,159 +687,6 @@ const CommonTestAndPreview = (props) => {
689
687
  return resolvedText;
690
688
  };
691
689
 
692
- const getViberMergedFormData = useCallback((formDataOverride) => {
693
- const formDataObj = formDataOverride && typeof formDataOverride === 'object'
694
- ? formDataOverride
695
- : (formData && typeof formData === 'object' ? formData : {});
696
- let contentObj = {};
697
- if (content && typeof content === 'object') {
698
- contentObj = content;
699
- } else if (typeof content === 'string' && content.trim()) {
700
- try {
701
- contentObj = JSON.parse(content);
702
- } catch (e) {
703
- contentObj = {};
704
- }
705
- }
706
- const previewCards = formDataObj?.viberPreviewContent?.cards
707
- ?? formDataObj?.cards
708
- ?? contentObj?.viberPreviewContent?.cards
709
- ?? contentObj?.cards;
710
- const isCarousel = Boolean(
711
- formDataObj.type === MEDIA_TYPE_CAROUSEL
712
- || contentObj.type === MEDIA_TYPE_CAROUSEL
713
- || (Array.isArray(previewCards) && previewCards.length > 0),
714
- );
715
- const mergedPreview = {
716
- ...(contentObj.viberPreviewContent || {}),
717
- ...(formDataObj.viberPreviewContent || {}),
718
- ...(Array.isArray(previewCards) && previewCards.length ? { cards: previewCards } : {}),
719
- ...(isCarousel ? {
720
- type: MEDIA_TYPE_CAROUSEL,
721
- showCarouselEditorPreview: true,
722
- } : {}),
723
- };
724
- return {
725
- ...contentObj,
726
- ...formDataObj,
727
- ...(Array.isArray(previewCards) && previewCards.length ? { cards: previewCards } : {}),
728
- ...(isCarousel ? { type: MEDIA_TYPE_CAROUSEL } : {}),
729
- ...(Object.keys(mergedPreview).length ? { viberPreviewContent: mergedPreview } : {}),
730
- };
731
- }, [formData, content]);
732
-
733
- const getViberCarouselCardsFromFormData = (formDataObj) => {
734
- const previewCards = formDataObj?.viberPreviewContent?.cards;
735
- if (Array.isArray(previewCards) && previewCards.length) {
736
- return previewCards;
737
- }
738
- const rootCards = formDataObj?.cards;
739
- if (Array.isArray(rootCards) && rootCards.length) {
740
- return rootCards;
741
- }
742
- return [];
743
- };
744
-
745
- const getViberTagExtractionContent = (formDataObj, contentStr = '') => {
746
- const messageText = formDataObj?.messageContent
747
- || formDataObj?.viberPreviewContent?.messageContent
748
- || contentStr
749
- || '';
750
- const cardFieldTexts = getViberCarouselCardsFromFormData(formDataObj).flatMap((card) => {
751
- const fields = [card?.text || ''];
752
- (card?.buttons || []).forEach((button) => {
753
- fields.push(button?.title || '', button?.action || '');
754
- });
755
- return fields;
756
- });
757
- return [messageText, ...cardFieldTexts]
758
- .filter((value) => typeof value === 'string' && value.trim())
759
- .join(' ');
760
- };
761
-
762
- const resolveViberCarouselCards = (cards, tagValues) => {
763
- if (!Array.isArray(cards) || !tagValues || !Object.keys(tagValues).length) {
764
- return cards;
765
- }
766
- return cards.map((card) => ({
767
- ...card,
768
- text: resolveTagsInText(card?.text || '', tagValues),
769
- buttons: (card?.buttons || []).map((button) => ({
770
- ...button,
771
- title: resolveTagsInText(button?.title || '', tagValues),
772
- action: resolveTagsInText(button?.action || '', tagValues),
773
- })),
774
- }));
775
- };
776
-
777
- const applyViberCustomValuesToContent = (contentObj, tagValues) => {
778
- if (!contentObj || typeof contentObj !== 'object' || !tagValues || !Object.keys(tagValues).length) {
779
- return contentObj;
780
- }
781
- const result = { ...contentObj };
782
- if (typeof result.messageContent === 'string') {
783
- result.messageContent = resolveTagsInText(result.messageContent, tagValues);
784
- }
785
- if (Array.isArray(result.cards)) {
786
- result.cards = resolveViberCarouselCards(result.cards, tagValues);
787
- }
788
- if (result.viberPreviewContent && typeof result.viberPreviewContent === 'object') {
789
- const preview = result.viberPreviewContent;
790
- result.viberPreviewContent = {
791
- ...preview,
792
- messageContent: resolveTagsInText(preview.messageContent || '', tagValues),
793
- cards: resolveViberCarouselCards(preview.cards, tagValues),
794
- };
795
- }
796
- return result;
797
- };
798
-
799
- const mergeViberPreviewWithResolved = (base, resolved) => {
800
- if (!resolved || typeof resolved !== 'object') {
801
- return base && typeof base === 'object' ? base : {};
802
- }
803
- const baseObj = base && typeof base === 'object' ? base : {};
804
- const basePreview = baseObj.viberPreviewContent || {};
805
- const resolvedPreview = resolved.viberPreviewContent || {};
806
- const baseCards = basePreview.cards || baseObj.cards || [];
807
- const resolvedCards = resolvedPreview.cards || resolved.cards || [];
808
- const mergedCards = baseCards.length
809
- ? baseCards.map((card, index) => {
810
- const resolvedCard = resolvedCards[index];
811
- if (!resolvedCard) {
812
- return card;
813
- }
814
- return {
815
- ...card,
816
- ...(resolvedCard.text != null ? { text: resolvedCard.text } : {}),
817
- ...(resolvedCard.mediaUrl != null ? { mediaUrl: resolvedCard.mediaUrl } : {}),
818
- buttons: (card.buttons || []).map((button, buttonIndex) => ({
819
- ...button,
820
- ...(resolvedCard.buttons?.[buttonIndex] || {}),
821
- })),
822
- };
823
- })
824
- : resolvedCards;
825
- const resolvedMessage = resolved.messageContent ?? resolvedPreview.messageContent;
826
-
827
- return {
828
- ...baseObj,
829
- ...resolved,
830
- viberPreviewContent: {
831
- ...basePreview,
832
- ...resolvedPreview,
833
- type: resolvedPreview.type || basePreview.type || baseObj.type || (mergedCards.length ? MEDIA_TYPE_CAROUSEL : ''),
834
- cards: mergedCards.length ? mergedCards : (resolvedPreview.cards || basePreview.cards),
835
- showCarouselEditorPreview: Boolean(
836
- basePreview.showCarouselEditorPreview
837
- || resolvedPreview.showCarouselEditorPreview
838
- || mergedCards.length > 0,
839
- ),
840
- ...(resolvedMessage != null ? { messageContent: resolvedMessage } : {}),
841
- },
842
- };
843
- };
844
-
845
690
  /**
846
691
  * Common handler for saving test customers (both new and existing)
847
692
  */
@@ -1120,13 +965,11 @@ const CommonTestAndPreview = (props) => {
1120
965
  templateContent: formDataObj?.bodyText || contentStr,
1121
966
  };
1122
967
 
1123
- case CHANNELS.VIBER: {
1124
- const viberFormData = getViberMergedFormData(formDataObj);
968
+ case CHANNELS.VIBER:
1125
969
  return {
1126
- templateSubject: viberFormData?.messageTitle || '',
1127
- templateContent: getViberTagExtractionContent(viberFormData, contentStr),
970
+ templateSubject: formDataObj?.messageTitle || '',
971
+ templateContent: contentStr,
1128
972
  };
1129
- }
1130
973
 
1131
974
  case CHANNELS.WEBPUSH:
1132
975
  return {
@@ -2181,16 +2024,11 @@ const CommonTestAndPreview = (props) => {
2181
2024
  // 1. formDataObj from getTemplateContent (contains both viberPreviewContent and payload fields)
2182
2025
  // 2. formDataObj[0] (array format - legacy)
2183
2026
  // 3. contentStr (direct string - legacy)
2184
- // Merge content prop so listing / preview-only flows include carousel card tags
2185
- const viberFormData = getViberMergedFormData(formDataObj);
2186
- formDataObj = viberFormData;
2187
2027
 
2188
2028
  let messageText = '';
2189
2029
  let imageData = null;
2190
2030
  let videoData = null;
2191
2031
  let buttonData = null;
2192
- let cardsData = [];
2193
- let messageType = '';
2194
2032
  let accountId = null;
2195
2033
  let accountDetails = null;
2196
2034
  let scenarioKey = '';
@@ -2205,8 +2043,6 @@ const CommonTestAndPreview = (props) => {
2205
2043
  imageData = formDataObj.image || null;
2206
2044
  videoData = formDataObj.video || null;
2207
2045
  buttonData = formDataObj.button || null;
2208
- cardsData = formDataObj.cards || [];
2209
- messageType = formDataObj.type || '';
2210
2046
  accountId = formDataObj.accountId || null;
2211
2047
  accountDetails = formDataObj.accountDetails || null;
2212
2048
  scenarioKey = formDataObj.scenarioKey || VIBER_API_SCENARIO_KEY;
@@ -2233,8 +2069,6 @@ const CommonTestAndPreview = (props) => {
2233
2069
  url: formDataObj?.buttonURL || '',
2234
2070
  };
2235
2071
  }
2236
- cardsData = viberPreview.cards || formDataObj?.cards || [];
2237
- messageType = viberPreview.type || formDataObj?.type || '';
2238
2072
  // Extract account info from parent formDataObj if available
2239
2073
  accountId = formDataObj.accountId || null;
2240
2074
  accountDetails = formDataObj.accountDetails || null;
@@ -2277,10 +2111,6 @@ const CommonTestAndPreview = (props) => {
2277
2111
  text: messageText,
2278
2112
  };
2279
2113
 
2280
- if (messageType === CHANNELS.VIBER) {
2281
- messageType = '';
2282
- }
2283
-
2284
2114
  // Add image if present
2285
2115
  if (imageData && imageData.url) {
2286
2116
  viberContent.image = {
@@ -2309,34 +2139,9 @@ const CommonTestAndPreview = (props) => {
2309
2139
  }
2310
2140
  }
2311
2141
 
2312
- if (messageType === MEDIA_TYPE_CAROUSEL || (Array.isArray(cardsData) && cardsData.length)) {
2313
- viberContent.type = MEDIA_TYPE_CAROUSEL;
2314
- viberContent.cards = (cardsData || []).map((card) => ({
2315
- text: card?.text || '',
2316
- mediaUrl: card?.mediaUrl || '',
2317
- buttons: (card?.buttons || []).map((button) => ({
2318
- title: button?.title || '',
2319
- action: button?.action || '',
2320
- })),
2321
- }));
2322
- delete viberContent.button;
2323
- }
2324
-
2325
- // Resolve tags in text/cards if custom values are provided
2326
- if (customValuesObj && Object.keys(customValuesObj).length > 0) {
2327
- if (viberContent.text) {
2328
- viberContent.text = resolveTagsInText(viberContent.text, customValuesObj);
2329
- }
2330
- if (Array.isArray(viberContent.cards)) {
2331
- viberContent.cards = resolveViberCarouselCards(viberContent.cards, customValuesObj);
2332
- }
2333
- if (viberContent.button) {
2334
- viberContent.button = {
2335
- ...viberContent.button,
2336
- text: resolveTagsInText(viberContent.button.text || '', customValuesObj),
2337
- url: resolveTagsInText(viberContent.button.url || '', customValuesObj),
2338
- };
2339
- }
2142
+ // Resolve tags in text if custom values are provided
2143
+ if (customValuesObj && Object.keys(customValuesObj).length > 0 && viberContent.text) {
2144
+ viberContent.text = resolveTagsInText(viberContent.text, customValuesObj);
2340
2145
  }
2341
2146
 
2342
2147
  // Build messageBody JSON string
@@ -2728,39 +2533,33 @@ const CommonTestAndPreview = (props) => {
2728
2533
  // Only use previewDataHtml if preview call was made
2729
2534
  if (hasPreviewCallBeenMade && previewDataHtml?.resolvedBody) {
2730
2535
  resolvedContent = previewDataHtml.resolvedBody;
2731
- if (typeof resolvedContent === 'string') {
2732
- try {
2733
- resolvedContent = JSON.parse(resolvedContent);
2734
- } catch (e) {
2735
- resolvedContent = null;
2736
- }
2737
- }
2738
2536
  }
2739
2537
 
2740
- // Parse content if it's a string, then merge with formData for carousel + tags in all entry flows
2741
- let parsedViberContent = getViberMergedFormData();
2742
- if (!parsedViberContent || typeof parsedViberContent !== 'object') {
2743
- parsedViberContent = {};
2538
+ // Parse content if it's a string
2539
+ let parsedViberContent = content;
2540
+ if (typeof content === 'string') {
2541
+ try {
2542
+ parsedViberContent = JSON.parse(content);
2543
+ } catch (e) {
2544
+ parsedViberContent = {};
2545
+ }
2744
2546
  }
2745
- // Merge template preview state with API resolved body so carousel type/cards survive slim responses
2547
+ // Use resolvedContent if available (from preview call), otherwise use raw content
2746
2548
  if (resolvedContent && typeof resolvedContent === 'object') {
2747
- const base = parsedViberContent && typeof parsedViberContent === 'object' ? parsedViberContent : {};
2748
- contentObj = mergeViberPreviewWithResolved(base, resolvedContent);
2749
- if (base.accountName && !contentObj.accountName) {
2750
- contentObj.accountName = base.accountName;
2549
+ contentObj = { ...resolvedContent };
2550
+ // Merge in accountName and brandName from raw content if not in resolvedContent
2551
+ if (parsedViberContent?.accountName && !contentObj.accountName) {
2552
+ contentObj.accountName = parsedViberContent.accountName;
2751
2553
  }
2752
- if (base.brandName && !contentObj.brandName) {
2753
- contentObj.brandName = base.brandName;
2554
+ if (parsedViberContent?.brandName && !contentObj.brandName) {
2555
+ contentObj.brandName = parsedViberContent.brandName;
2754
2556
  }
2755
2557
  } else {
2756
- contentObj = parsedViberContent && typeof parsedViberContent === 'object' ? parsedViberContent : {};
2757
- }
2758
- if (
2759
- hasPreviewCallBeenMade
2760
- && viberPreviewTagValues
2761
- && Object.keys(viberPreviewTagValues).length > 0
2762
- ) {
2763
- contentObj = applyViberCustomValuesToContent(contentObj, viberPreviewTagValues);
2558
+ // Use raw content if no preview call was made or resolvedContent is not available
2559
+ contentObj = {...parsedViberContent, messageContent: resolvedContent};
2560
+ if (resolvedContent) {
2561
+ contentObj.viberPreviewContent = {...parsedViberContent?.viberPreviewContent, messageContent: resolvedContent};
2562
+ }
2764
2563
  }
2765
2564
  } else if (channel === CHANNELS.ZALO) {
2766
2565
  // For Zalo, content is an object with templatePreviewUrl, templateStatus, etc.
@@ -3144,11 +2943,6 @@ const CommonTestAndPreview = (props) => {
3144
2943
 
3145
2944
  setCustomValues(updatedValues);
3146
2945
 
3147
- // Viber: do not auto-resolve tags in preview; user must click Update preview
3148
- if (channel === CHANNELS.VIBER) {
3149
- return;
3150
- }
3151
-
3152
2946
  // Update preview with prefilled values (this is a valid preview call trigger)
3153
2947
  // For RCS: always dispatch with RCS channel/content so previewDataHtml stays RCS-shaped.
3154
2948
  // SMS fallback preview is kept in sync by syncSmsFallbackPreview via smsFallbackPreviewText.
@@ -3231,7 +3025,6 @@ const CommonTestAndPreview = (props) => {
3231
3025
  setPreviewDevice(DESKTOP);
3232
3026
  setPreviewDataHtml('');
3233
3027
  setHasPreviewCallBeenMade(false); // Reset preview call flag
3234
- setViberPreviewTagValues(null);
3235
3028
  setSelectedTestEntities([]);
3236
3029
  setBeeContent('');
3237
3030
  previousBeeContentRef.current = '';
@@ -3269,7 +3062,6 @@ const CommonTestAndPreview = (props) => {
3269
3062
  const handleClearSelection = () => {
3270
3063
  setSelectedCustomer(null);
3271
3064
  setHasPreviewCallBeenMade(false); // Reset flag when customer is cleared
3272
- setViberPreviewTagValues(null);
3273
3065
 
3274
3066
  // Clear all preview errors when customer is cleared
3275
3067
  actions.clearPreviewErrors();
@@ -3328,9 +3120,6 @@ const CommonTestAndPreview = (props) => {
3328
3120
  emptyValues,
3329
3121
  selectedCustomer
3330
3122
  );
3331
- if (channel === CHANNELS.VIBER) {
3332
- setViberPreviewTagValues({ ...emptyValues });
3333
- }
3334
3123
  actions.updatePreviewRequested(payload);
3335
3124
  setHasPreviewCallBeenMade(true); // Mark that preview call was made
3336
3125
  };
@@ -3356,9 +3145,6 @@ const CommonTestAndPreview = (props) => {
3356
3145
  customValues,
3357
3146
  selectedCustomer
3358
3147
  );
3359
- if (channel === CHANNELS.VIBER) {
3360
- setViberPreviewTagValues({ ...customValues });
3361
- }
3362
3148
  await actions.updatePreviewRequested(payload);
3363
3149
 
3364
3150
  await syncSmsFallbackPreview(customValues, selectedCustomer);