@capillarytech/creatives-library 8.0.345-alpha.13 → 8.0.345-alpha.15

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 (138) hide show
  1. package/constants/unified.js +29 -0
  2. package/package.json +1 -1
  3. package/services/api.js +0 -20
  4. package/services/tests/api.test.js +13 -59
  5. package/utils/commonUtils.js +19 -1
  6. package/utils/rcsPayloadUtils.js +92 -0
  7. package/utils/templateVarUtils.js +201 -0
  8. package/utils/tests/templateVarUtils.test.js +204 -0
  9. package/v2Components/CapActionButton/constants.js +7 -0
  10. package/v2Components/CapActionButton/index.js +167 -109
  11. package/v2Components/CapActionButton/index.scss +157 -6
  12. package/v2Components/CapActionButton/messages.js +19 -3
  13. package/v2Components/CapActionButton/tests/index.test.js +41 -17
  14. package/v2Components/CapCustomSkeleton/index.js +1 -1
  15. package/v2Components/CapCustomSkeleton/tests/__snapshots__/index.test.js.snap +12 -12
  16. package/v2Components/CapTagList/index.js +10 -0
  17. package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +70 -49
  18. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +8 -2
  19. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +207 -21
  20. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +16 -0
  21. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +85 -10
  22. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +30 -0
  23. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +79 -11
  24. package/v2Components/CommonTestAndPreview/SendTestMessage.js +10 -5
  25. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +160 -15
  26. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js.rej +18 -0
  27. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +341 -76
  28. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +133 -4
  29. package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +11 -0
  30. package/v2Components/CommonTestAndPreview/constants.js +38 -2
  31. package/v2Components/CommonTestAndPreview/index.js +676 -186
  32. package/v2Components/CommonTestAndPreview/messages.js +49 -3
  33. package/v2Components/CommonTestAndPreview/previewApiUtils.js +59 -0
  34. package/v2Components/CommonTestAndPreview/sagas.js +15 -6
  35. package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +308 -284
  36. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +231 -65
  37. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +118 -5
  38. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +341 -0
  39. package/v2Components/CommonTestAndPreview/tests/PreviewSection.test.js +8 -1
  40. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +34 -13
  41. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/RcsPreviewContent.test.js +281 -283
  42. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +199 -1
  43. package/v2Components/CommonTestAndPreview/tests/index.test.js +132 -4
  44. package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +67 -0
  45. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +2 -2
  46. package/v2Components/FormBuilder/index.js +8 -10
  47. package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +87 -0
  48. package/v2Components/SmsFallback/constants.js +73 -0
  49. package/v2Components/SmsFallback/index.js +955 -0
  50. package/v2Components/SmsFallback/index.scss +265 -0
  51. package/v2Components/SmsFallback/messages.js +78 -0
  52. package/v2Components/SmsFallback/smsFallbackUtils.js +118 -0
  53. package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +50 -0
  54. package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +147 -0
  55. package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +304 -0
  56. package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +197 -0
  57. package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +277 -0
  58. package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +422 -0
  59. package/v2Components/SmsFallback/useLocalTemplateList.js +92 -0
  60. package/v2Components/TemplatePreview/_templatePreview.scss +33 -23
  61. package/v2Components/TemplatePreview/constants.js +2 -0
  62. package/v2Components/TemplatePreview/index.js +143 -28
  63. package/v2Components/TemplatePreview/tests/index.test.js +142 -0
  64. package/v2Components/TestAndPreviewSlidebox/index.js +13 -1
  65. package/v2Components/TestAndPreviewSlidebox/sagas.js +11 -4
  66. package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +3 -1
  67. package/v2Components/VarSegmentMessageEditor/constants.js +2 -0
  68. package/v2Components/VarSegmentMessageEditor/index.js +125 -0
  69. package/v2Components/VarSegmentMessageEditor/index.scss +46 -0
  70. package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +43 -0
  71. package/v2Containers/CreativesContainer/SlideBoxContent.js +36 -4
  72. package/v2Containers/CreativesContainer/SlideBoxFooter.js +11 -4
  73. package/v2Containers/CreativesContainer/SlideBoxHeader.js +29 -4
  74. package/v2Containers/CreativesContainer/constants.js +9 -0
  75. package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +67 -0
  76. package/v2Containers/CreativesContainer/index.js +300 -108
  77. package/v2Containers/CreativesContainer/index.scss +51 -1
  78. package/v2Containers/CreativesContainer/messages.js +0 -4
  79. package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +90 -0
  80. package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +78 -34
  81. package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +79 -16
  82. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +8 -0
  83. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +357 -98
  84. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +20 -18
  85. package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +258 -0
  86. package/v2Containers/CreativesContainer/tests/index.test.js +71 -9
  87. package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +125 -0
  88. package/v2Containers/Rcs/constants.js +119 -8
  89. package/v2Containers/Rcs/index.js +2379 -807
  90. package/v2Containers/Rcs/index.js.rej +1336 -0
  91. package/v2Containers/Rcs/index.scss +276 -6
  92. package/v2Containers/Rcs/index.scss.rej +74 -0
  93. package/v2Containers/Rcs/messages.js +38 -3
  94. package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +225 -0
  95. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +98018 -70073
  96. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +0 -5
  97. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap.rej +128 -0
  98. package/v2Containers/Rcs/tests/index.test.js +152 -121
  99. package/v2Containers/Rcs/tests/mockData.js +38 -0
  100. package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +318 -0
  101. package/v2Containers/Rcs/tests/utils.test.js +646 -30
  102. package/v2Containers/Rcs/utils.js +478 -11
  103. package/v2Containers/Sms/Create/index.js +100 -40
  104. package/v2Containers/Sms/smsFormDataHelpers.js +67 -0
  105. package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +253 -0
  106. package/v2Containers/SmsTrai/Create/index.js +9 -4
  107. package/v2Containers/SmsTrai/Edit/constants.js +2 -0
  108. package/v2Containers/SmsTrai/Edit/index.js +636 -130
  109. package/v2Containers/SmsTrai/Edit/index.scss +121 -0
  110. package/v2Containers/SmsTrai/Edit/messages.js +14 -4
  111. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +4328 -2375
  112. package/v2Containers/SmsWrapper/index.js +37 -8
  113. package/v2Containers/TagList/index.js +6 -0
  114. package/v2Containers/Templates/ChannelTypeIllustration.js +6 -23
  115. package/v2Containers/Templates/TemplatesActionBar.js +101 -0
  116. package/v2Containers/Templates/_templates.scss +181 -126
  117. package/v2Containers/Templates/actions.js +11 -36
  118. package/v2Containers/Templates/constants.js +2 -23
  119. package/v2Containers/Templates/index.js +142 -333
  120. package/v2Containers/Templates/messages.js +0 -68
  121. package/v2Containers/Templates/reducer.js +0 -68
  122. package/v2Containers/Templates/sagas.js +55 -98
  123. package/v2Containers/Templates/selectors.js +0 -12
  124. package/v2Containers/Templates/tests/ChannelTypeIllustration.test.js +0 -12
  125. package/v2Containers/Templates/tests/TemplatesActionBar.test.js +120 -0
  126. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1042 -1256
  127. package/v2Containers/Templates/tests/index.test.js +0 -6
  128. package/v2Containers/Templates/tests/reducer.test.js +0 -178
  129. package/v2Containers/Templates/tests/sagas.test.js +200 -436
  130. package/v2Containers/Templates/tests/selector.test.js +0 -32
  131. package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +180 -0
  132. package/v2Containers/Templates/utils/smsTemplatesListApi.js +79 -0
  133. package/v2Containers/TemplatesV2/TemplatesV2.style.js +72 -1
  134. package/v2Containers/TemplatesV2/index.js +86 -23
  135. package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +131 -0
  136. package/v2Containers/Whatsapp/index.js +3 -20
  137. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +578 -34
  138. package/v2Containers/Assets/images/archive_Empty_Illustration.svg +0 -9
@@ -1,11 +1,28 @@
1
1
  import React from 'react';
2
2
  import {CapIcon, CapImage, CapLabel, CapDivider } from '@capillarytech/cap-ui-library';
3
- import { RCS } from './constants';
3
+ import {
4
+ RCS,
5
+ RCS_MEDIA_TYPES,
6
+ RCS_NUMERIC_VAR_NAME_REGEX,
7
+ RCS_REGEX_META_CHARS_PATTERN,
8
+ RCS_STRIP_MUSTACHE_DELIMITERS_REGEX,
9
+ } from './constants';
4
10
  import './index.scss';
5
11
  // import { formatMessage } from '../../../utils/intl';
6
12
  import messages from './messages';
7
- import { STATUS_OPTIONS, RCS_BUTTON_TYPES, RCS_STATUSES, RCS_MEDIA_TYPES } from './constants';
8
-
13
+ import {
14
+ STATUS_OPTIONS,
15
+ RCS_BUTTON_TYPES,
16
+ RCS_STATUSES,
17
+ rcsVarRegex,
18
+ rcsVarTestRegex,
19
+ } from './constants';
20
+ import {
21
+ splitTemplateVarString,
22
+ COMBINED_SMS_TEMPLATE_VAR_REGEX,
23
+ isAnyTemplateVarToken,
24
+ } from '../../utils/templateVarUtils';
25
+ import { pickRcsCardVarMappedEntries } from './rcsLibraryHydrationUtils';
9
26
 
10
27
  export const getRcsStatusType = (status) => {
11
28
  switch (status) {
@@ -33,6 +50,388 @@ export const getTemplateStatusType = (templateStatus) => {
33
50
  }
34
51
  };
35
52
 
53
+ /** Localized label for a carousel video thumbnail size (width × height in px). */
54
+ export const formatRcsCarouselVideoThumbnailLabel = (formatMessage, dimensionEntry) => {
55
+ if (!dimensionEntry) return '';
56
+ const { width, height } = dimensionEntry;
57
+ return formatMessage(messages.rcsCarouselVideoThumbnailLabel, { width, height });
58
+ };
59
+
60
+ /**
61
+ * Global RegExp matching `{{numericVarName}}` in RCS template strings.
62
+ * `numericVarName` is escaped for regex metacharacters.
63
+ */
64
+ export function buildRcsNumericMustachePlaceholderRegex(numericVarName) {
65
+ const escaped = String(numericVarName).replace(RCS_REGEX_META_CHARS_PATTERN, '\\$&');
66
+ return new RegExp(`\\{\\{${escaped}\\}\\}`, 'g');
67
+ }
68
+
69
+ export function normalizeCardVarMapped(rawCardVarMapped, orderedTagNames) {
70
+ if (!rawCardVarMapped || typeof rawCardVarMapped !== 'object') return {};
71
+ const normalizedMap = {};
72
+ const templateVarNamesInOrder = Array.isArray(orderedTagNames) ? orderedTagNames : null;
73
+ const hasOrderedSlots =
74
+ Boolean(templateVarNamesInOrder?.length);
75
+ Object.entries(rawCardVarMapped).forEach(([entryKey, entryValue]) => {
76
+ const trimmedValue = entryValue == null ? '' : String(entryValue).trim();
77
+ const entryKeyIsNumericSlot = RCS_NUMERIC_VAR_NAME_REGEX.test(String(entryKey));
78
+ const mustacheInnerMatch = trimmedValue.match(/^\{\{([^}]+)\}\}$/);
79
+ const innerFromMustache =
80
+ mustacheInnerMatch?.[1] != null ? String(mustacheInnerMatch[1]).trim() : null;
81
+
82
+ if (innerFromMustache !== null && entryKeyIsNumericSlot) {
83
+ const slotIndexZeroBased = parseInt(String(entryKey), 10) - 1;
84
+ const expectedVarForSlot =
85
+ hasOrderedSlots
86
+ && slotIndexZeroBased >= 0
87
+ && slotIndexZeroBased < templateVarNamesInOrder.length
88
+ ? templateVarNamesInOrder[slotIndexZeroBased]
89
+ : null;
90
+ const innerMatchesSlotToken =
91
+ expectedVarForSlot != null && innerFromMustache === expectedVarForSlot;
92
+ const legacyUnorderedPlaceholder = !hasOrderedSlots;
93
+ /* Library: slot "1" + {{user_id_b64}} when token is user_id_b64 → empty semantic. With ordered
94
+ * slots, only clear when inner matches that slot's template token; else keep (e.g. {{1}}+{{FirstName}}). */
95
+ const clearNumericSlotMustacheAsUnfilled =
96
+ !RCS_NUMERIC_VAR_NAME_REGEX.test(innerFromMustache)
97
+ && (legacyUnorderedPlaceholder || innerMatchesSlotToken);
98
+ if (clearNumericSlotMustacheAsUnfilled) {
99
+ const outputKey = innerFromMustache;
100
+ const existingValue = normalizedMap[outputKey];
101
+ if (existingValue != null && String(existingValue).trim() !== '') {
102
+ return;
103
+ }
104
+ normalizedMap[outputKey] = '';
105
+ return;
106
+ }
107
+ if (RCS_NUMERIC_VAR_NAME_REGEX.test(innerFromMustache)) {
108
+ const outputKey = innerFromMustache;
109
+ const existingValue = normalizedMap[outputKey];
110
+ if (existingValue != null && String(existingValue).trim() !== '') {
111
+ return;
112
+ }
113
+ normalizedMap[outputKey] = '';
114
+ return;
115
+ }
116
+ }
117
+
118
+ if (innerFromMustache !== null && !entryKeyIsNumericSlot) {
119
+ if (innerFromMustache === String(entryKey)) {
120
+ const existingValue = normalizedMap[entryKey];
121
+ if (existingValue != null && String(existingValue).trim() !== '') {
122
+ return;
123
+ }
124
+ normalizedMap[entryKey] = '';
125
+ return;
126
+ }
127
+ }
128
+
129
+ if (entryKeyIsNumericSlot && templateVarNamesInOrder?.length) {
130
+ const slotIndexZeroBased = parseInt(String(entryKey), 10) - 1;
131
+ if (slotIndexZeroBased >= 0 && slotIndexZeroBased < templateVarNamesInOrder.length) {
132
+ normalizedMap[templateVarNamesInOrder[slotIndexZeroBased]] = trimmedValue;
133
+ return;
134
+ }
135
+ }
136
+ normalizedMap[entryKey] = trimmedValue;
137
+ });
138
+ return normalizedMap;
139
+ }
140
+
141
+ /**
142
+ * Semantic names that appear in both title and description (e.g. `{{adv}}` in header and body).
143
+ * Those slots must not share one semantic `cardVarMapped` key — otherwise VarSegment inputs mirror.
144
+ */
145
+ export function getRcsSemanticVarNamesSpanningTitleAndDesc(
146
+ templateTitle,
147
+ templateDesc,
148
+ rcsVarRegex,
149
+ ) {
150
+ const getVarNameFromToken = (token = '') => token.replace(RCS_STRIP_MUSTACHE_DELIMITERS_REGEX, '');
151
+ const titleTokens = templateTitle?.match(rcsVarRegex) ?? [];
152
+ const descTokens = templateDesc?.match(rcsVarRegex) ?? [];
153
+ const titleNames = new Set(titleTokens.map(getVarNameFromToken).filter(Boolean));
154
+ const descNames = new Set(descTokens.map(getVarNameFromToken).filter(Boolean));
155
+ const spanning = new Set();
156
+ titleNames.forEach((n) => {
157
+ if (descNames.has(n)) spanning.add(n);
158
+ });
159
+ return spanning;
160
+ }
161
+
162
+ /**
163
+ * Rebuild `cardVarMapped` so keys match the current title/description tokens (title tokens first,
164
+ * then description), in order. Values are taken from the matching key, else from legacy slot
165
+ * `1`, `2`, … by index. If there are no `{{...}}` tokens, returns a shallow clone of `raw`.
166
+ */
167
+ export function coalesceCardVarMappedToTemplate(
168
+ sourceCardVarMap,
169
+ templateTitle,
170
+ templateDesc,
171
+ rcsVarRegex,
172
+ ) {
173
+ const getVarNameFromToken = (token = '') => token.replace(RCS_STRIP_MUSTACHE_DELIMITERS_REGEX, '');
174
+ const templateVarTokens = [
175
+ ...(templateTitle?.match(rcsVarRegex) ?? []),
176
+ ...(templateDesc?.match(rcsVarRegex) ?? []),
177
+ ];
178
+ const lookupSourceMap =
179
+ sourceCardVarMap != null && typeof sourceCardVarMap === 'object' ? sourceCardVarMap : {};
180
+ if (!templateVarTokens.length) {
181
+ return { ...lookupSourceMap };
182
+ }
183
+ const semanticNamesSpanningTitleAndDesc = getRcsSemanticVarNamesSpanningTitleAndDesc(
184
+ templateTitle,
185
+ templateDesc,
186
+ rcsVarRegex,
187
+ );
188
+ const coalescedMap = { ...lookupSourceMap };
189
+ const seenSemanticVarNames = new Set();
190
+ templateVarTokens.forEach((token, slotIndexZeroBased) => {
191
+ const semanticVarName = getVarNameFromToken(token);
192
+ if (!semanticVarName) return;
193
+ const numericSlotKey = String(slotIndexZeroBased + 1);
194
+ const isRepeatOfSemanticName = seenSemanticVarNames.has(semanticVarName);
195
+ const skipSharedSemanticLookup =
196
+ isRepeatOfSemanticName && semanticNamesSpanningTitleAndDesc.has(semanticVarName);
197
+ let valueFromSource = lookupSourceMap[numericSlotKey];
198
+ if (valueFromSource === undefined || valueFromSource === null) {
199
+ if (!skipSharedSemanticLookup) {
200
+ valueFromSource = lookupSourceMap[semanticVarName];
201
+ }
202
+ }
203
+ if (valueFromSource === undefined || valueFromSource === null) {
204
+ valueFromSource = lookupSourceMap[String(slotIndexZeroBased + 1)];
205
+ }
206
+ if (valueFromSource === undefined || valueFromSource === null) {
207
+ valueFromSource = lookupSourceMap[slotIndexZeroBased + 1];
208
+ }
209
+ const trimmedSlotValue = valueFromSource == null ? '' : String(valueFromSource).trim();
210
+ coalescedMap[numericSlotKey] = trimmedSlotValue;
211
+ if (!seenSemanticVarNames.has(semanticVarName)) {
212
+ seenSemanticVarNames.add(semanticVarName);
213
+ coalescedMap[semanticVarName] = trimmedSlotValue;
214
+ }
215
+ });
216
+ return coalescedMap;
217
+ }
218
+
219
+ /**
220
+ * Resolve the personalization value for a variable slot — aligned with createPayload:
221
+ * per-slot numeric keys `1`, `2`, … win over legacy semantic keys when both exist (duplicate
222
+ * `{{name}}` in title+desc). If semantic is explicitly cleared to '', that still wins over a
223
+ * stale numeric value (see tests) — except in embedded library / journey mode (`isLibraryMode`).
224
+ *
225
+ * In library mode, campaign payloads often set semantic keys to '' while numeric slot `1`,`2`,…
226
+ * still holds the value selected in the library; prefer that so VarSegment prepopulates.
227
+ *
228
+ * When a numeric slot is present but only whitespace / empty (common after hydration), do not
229
+ * treat it as authoritative — fall through to the semantic key so preview and payload match the
230
+ * tag the user selected (e.g. `1: ''` but `promotion_points: '{{newTag}}'`).
231
+ *
232
+ * @param {boolean} [omitSemanticFallback=false] When true, do not read `varName` on the map (and do
233
+ * not apply the early `semanticEmpty` short-circuit). Use when the same semantic name appears in
234
+ * both title and description so each global slot stays independent.
235
+ */
236
+ export function resolveCardVarMappedSlotValue(
237
+ cardVarMapped,
238
+ varName,
239
+ globalSlotIndexZeroBased,
240
+ isLibraryMode = false,
241
+ omitSemanticFallback = false,
242
+ ) {
243
+ const varMap = cardVarMapped ?? {};
244
+ const slotKey = String(globalSlotIndexZeroBased + 1);
245
+ const semanticEmpty =
246
+ Object.prototype.hasOwnProperty.call(varMap, varName)
247
+ && String(varMap[varName] ?? '') === '';
248
+ const slotNonEmpty =
249
+ Object.prototype.hasOwnProperty.call(varMap, slotKey)
250
+ && String(varMap[slotKey] ?? '').trim() !== '';
251
+
252
+ if (semanticEmpty && !(isLibraryMode && slotNonEmpty) && !omitSemanticFallback) {
253
+ return '';
254
+ }
255
+ let numericSlotValue = '';
256
+ if (Object.prototype.hasOwnProperty.call(varMap, slotKey)) {
257
+ /** Text-only RCS card: editor shows a single "Text message" field (description); title row is hidden. */
258
+ numericSlotValue = String(varMap[slotKey] ?? '');
259
+ } else if (Object.prototype.hasOwnProperty.call(varMap, globalSlotIndexZeroBased + 1)) {
260
+ numericSlotValue = String(varMap[globalSlotIndexZeroBased + 1] ?? '');
261
+ }
262
+ if (numericSlotValue.trim() !== '') {
263
+ return numericSlotValue;
264
+ }
265
+ if (!omitSemanticFallback && Object.prototype.hasOwnProperty.call(varMap, varName)) {
266
+ return String(varMap[varName] ?? '');
267
+ }
268
+ return '';
269
+ }
270
+
271
+ /** Text-only RCS card: editor shows a single “Text message” field (description); title row is hidden. */
272
+ export function isRcsTextOnlyCardMediaType(mediaType) {
273
+ return (
274
+ mediaType === RCS_MEDIA_TYPES.NONE
275
+ || String(mediaType || '').toUpperCase() === 'TEXT'
276
+ );
277
+ }
278
+
279
+ /**
280
+ * Resolve RCS card title/description for TemplatePreview (e.g. campaign slidebox preview).
281
+ * Mirrors `resolveTemplateWithMap` in the Rcs editor: title vars use global slots 0..n-1, then description.
282
+ * For text-only cards (`textOnlyCard`), ignore persisted `title` and resolve description from slot 0 — matches
283
+ * the editor where only the message body is shown.
284
+ */
285
+ export function resolveRcsCardPreviewStrings(
286
+ title,
287
+ description,
288
+ cardVarMapped,
289
+ isLibraryMode = false,
290
+ textOnlyCard = false,
291
+ ) {
292
+ const splitTemplateVarStringRcs = (str) => splitTemplateVarString(str, rcsVarRegex);
293
+ const getVarNameFromToken = (token = '') =>
294
+ token.replace(RCS_STRIP_MUSTACHE_DELIMITERS_REGEX, '');
295
+ const semanticNamesSpanningTitleAndDesc = textOnlyCard
296
+ ? new Set()
297
+ : getRcsSemanticVarNamesSpanningTitleAndDesc(title, description, rcsVarRegex);
298
+
299
+ const resolveTemplateWithMap = (str = '', slotOffset = 0) => {
300
+ if (!str) return '';
301
+ const arr = splitTemplateVarStringRcs(str);
302
+ let varOrdinal = 0;
303
+ return arr
304
+ .map((elem) => {
305
+ if (rcsVarTestRegex.test(elem)) {
306
+ const key = getVarNameFromToken(elem);
307
+ const globalSlot = slotOffset + varOrdinal;
308
+ varOrdinal += 1;
309
+ const omitSemantic = semanticNamesSpanningTitleAndDesc.has(key);
310
+ const v = resolveCardVarMappedSlotValue(
311
+ cardVarMapped,
312
+ key,
313
+ globalSlot,
314
+ isLibraryMode,
315
+ omitSemantic,
316
+ );
317
+ if (v == null || String(v).trim() === '') return elem;
318
+ return String(v);
319
+ }
320
+ return elem;
321
+ })
322
+ .join('');
323
+ };
324
+
325
+ const effectiveTitle = textOnlyCard ? '' : String(title || '');
326
+ const titleVarCount = textOnlyCard
327
+ ? 0
328
+ : (effectiveTitle.match(rcsVarRegex) || []).length;
329
+ return {
330
+ rcsTitle: textOnlyCard ? '' : resolveTemplateWithMap(effectiveTitle, 0),
331
+ rcsDesc: resolveTemplateWithMap(String(description || ''), titleVarCount),
332
+ };
333
+ }
334
+
335
+ /**
336
+ * Campaign consumer payload: replace each card's `title` / `description` with VarSegment-resolved
337
+ * tag strings (same rules as {@link resolveRcsCardPreviewStrings}). Root `rcsCardVarMapped` merges
338
+ * with per-card `cardVarMapped` for resolution; emitted `cardVarMapped` omits SMS-fallback slot keys
339
+ * (root/nested merged with {@link pickRcsCardVarMappedEntries} per side).
340
+ */
341
+ export function mapRcsCardContentForConsumerWithResolvedTags(
342
+ cardContentArray,
343
+ rootRcsCardVarMapped,
344
+ isFullMode,
345
+ ) {
346
+ const rootRecord =
347
+ rootRcsCardVarMapped != null && typeof rootRcsCardVarMapped === 'object'
348
+ ? rootRcsCardVarMapped
349
+ : {};
350
+ const list = Array.isArray(cardContentArray) ? cardContentArray : [];
351
+ const isLibraryMode = isFullMode !== true;
352
+ return list.map((card) => {
353
+ if (!card || typeof card !== 'object') return card;
354
+ const nested =
355
+ card.cardVarMapped != null && typeof card.cardVarMapped === 'object'
356
+ ? card.cardVarMapped
357
+ : {};
358
+ const rootClean = pickRcsCardVarMappedEntries(rootRecord);
359
+ const nestedClean = pickRcsCardVarMappedEntries(nested);
360
+ const merged = { ...rootClean, ...nestedClean };
361
+ const textOnly = isRcsTextOnlyCardMediaType(card.mediaType);
362
+ const { rcsTitle, rcsDesc } = resolveRcsCardPreviewStrings(
363
+ card.title ?? '',
364
+ card.description ?? '',
365
+ merged,
366
+ isLibraryMode,
367
+ textOnly,
368
+ );
369
+ const { cardVarMapped: _drop, ...cardRest } = card;
370
+ return {
371
+ ...cardRest,
372
+ title: rcsTitle,
373
+ description: rcsDesc,
374
+ ...(Object.keys(nestedClean).length > 0 ? { cardVarMapped: nestedClean } : {}),
375
+ };
376
+ });
377
+ }
378
+
379
+ /**
380
+ * Before save: strip only legacy numeric self-placeholders (`{{1}}`, `{{2}}`, …) mistakenly stored as
381
+ * slot values. Preserve semantic tokens like `{{FirstName}}` from TagList — those are valid mappings.
382
+ */
383
+ export function sanitizeCardVarMappedValue(val) {
384
+ if (val == null) return '';
385
+ const trimmedDisplayString = String(val).trim();
386
+ if (/^\{\{\d+\}\}$/.test(trimmedDisplayString)) return '';
387
+ return String(val);
388
+ }
389
+
390
+ /**
391
+ * Same completion rule as SmsTraiEdit RCS fallback — used by `isDisableDone` from
392
+ * `smsFallbackData.rcsSmsFallbackVarMapped` + template string.
393
+ * Every variable token (DLT {#…#} or mustache {{…}}) must have a non-empty trimmed value in the map.
394
+ *
395
+ * Slot keys are usually `${token}_${segmentIndex}` (same as VarSegmentMessageEditor). Persisted / API
396
+ * payloads may use `${token}_${varOrdinal}` with a 1-based occurrence index (see SmsTraiEdit init).
397
+ * We try segment index first, then ordinal — so e.g. template `{#var#}` (segment index 0) still matches
398
+ * map `{#var#}_1`.
399
+ *
400
+ * @param {string} templateText
401
+ * @param {Record<string, string>} [varSlotValueMap={}]
402
+ * @returns {boolean}
403
+ */
404
+ export function areAllRcsSmsFallbackVarSlotsFilled(templateText, varSlotValueMap = {}) {
405
+ if (!templateText || typeof templateText !== 'string') return true;
406
+ const segments = splitTemplateVarString(templateText, COMBINED_SMS_TEMPLATE_VAR_REGEX);
407
+ const hasVarToken = segments.some(
408
+ (segment) =>
409
+ typeof segment === 'string'
410
+ && isAnyTemplateVarToken(segment),
411
+ );
412
+ if (!hasVarToken) return true;
413
+ let varOrdinal = 0;
414
+ return segments.every((segment, segmentIndex) => {
415
+ if (
416
+ typeof segment !== 'string'
417
+ || !isAnyTemplateVarToken(segment)
418
+ ) return true;
419
+ varOrdinal += 1;
420
+ const indexKey = `${segment}_${segmentIndex}`;
421
+ const ordinalKey = `${segment}_${varOrdinal}`;
422
+ let mappedSlotValue;
423
+ if (Object.prototype.hasOwnProperty.call(varSlotValueMap, indexKey)) {
424
+ mappedSlotValue = varSlotValueMap[indexKey];
425
+ } else if (Object.prototype.hasOwnProperty.call(varSlotValueMap, ordinalKey)) {
426
+ mappedSlotValue = varSlotValueMap[ordinalKey];
427
+ } else {
428
+ mappedSlotValue = undefined;
429
+ }
430
+ if (mappedSlotValue == null) return false;
431
+ return String(mappedSlotValue).trim() !== '';
432
+ });
433
+ }
434
+
36
435
  export const getRCSContent = (template) => {
37
436
  const renderRcsSuggestionsPreview = (rcsSuggestions) => {
38
437
  const renderArray = [];
@@ -72,6 +471,7 @@ export const getRCSContent = (template) => {
72
471
  content: {
73
472
  [RCS]: {
74
473
  rcsContent: {
474
+ cardType = '',
75
475
  cardContent = [{}],
76
476
  cardSettings = {},
77
477
  } = {},
@@ -84,9 +484,75 @@ export const getRCSContent = (template) => {
84
484
  media = {},
85
485
  description,
86
486
  title,
487
+ mediaType,
87
488
  suggestions = [],
88
489
  } = cardContent[0];
490
+ const isCarousel =
491
+ (cardType || '').toString().toLowerCase() === 'carousel' ||
492
+ (cardContent || []).length > 1;
493
+ const isTextOnlyCard = isRcsTextOnlyCardMediaType(mediaType);
89
494
  const mediaPreview = media?.thumbnailUrl ? media.thumbnailUrl : media.mediaUrl;
495
+
496
+ const renderCarouselListingPreview = () => {
497
+ const cards = Array.isArray(cardContent) ? cardContent : [];
498
+ if (!cards.length) return null;
499
+ const cardsToShow = cards.slice(0, 3); // enough to show a "peek" of next card
500
+ return (
501
+ <div className="scroll-container">
502
+ {cardsToShow.map((c, idx) => {
503
+ const m = c?.media || {};
504
+ const isVideo = (m?.mediaType || '').toString().toUpperCase() === RCS_MEDIA_TYPES.VIDEO;
505
+ const thumbUrl = m?.thumbnailUrl;
506
+ const mediaUrl = m?.mediaUrl;
507
+ // Avoid rendering an <img src="...mp4"> when a video doesn't have a thumbnail.
508
+ const url = thumbUrl ? thumbUrl : (isVideo ? '' : mediaUrl);
509
+ return (
510
+ <div
511
+ key={`rcs-carousel-listing-${idx}-${url || ''}`}
512
+ className="whatsapp-carousel-container"
513
+ role="group"
514
+ >
515
+ <div className="whatsapp-carousel-card">
516
+ {url && (
517
+ <CapImage
518
+ src={url}
519
+ className="whatsapp-image"
520
+ />
521
+ )}
522
+ {!url && isVideo && (
523
+ <div
524
+ className="whatsapp-image video-preview rcs-video-preview-placeholder"
525
+ >
526
+ <CapLabel type="label9" className="rcs-video-preview-label">
527
+ Video preview
528
+ </CapLabel>
529
+ </div>
530
+ )}
531
+ <span
532
+ className={`${url ? 'whatsapp-message-with-media' : 'whatsapp-message-without-media'}`}
533
+ >
534
+ <CapLabel type="label9" className="whatsapp-carousel-body">
535
+ {c?.title || ''}
536
+ {c?.description ? `\n${c?.description}` : ''}
537
+ </CapLabel>
538
+ </span>
539
+ {Array.isArray(c?.suggestions) && c.suggestions.length > 0 && (
540
+ <>
541
+ {renderRcsSuggestionsPreview(c.suggestions)}
542
+ </>
543
+ )}
544
+ </div>
545
+ </div>
546
+ );
547
+ })}
548
+ </div>
549
+ );
550
+ };
551
+
552
+ if (isCarousel) {
553
+ return renderCarouselListingPreview();
554
+ }
555
+
90
556
  return (
91
557
  <div className="cap-rcs-creatives">
92
558
  {mediaPreview && (
@@ -95,13 +561,15 @@ export const getRCSContent = (template) => {
95
561
  className="rcs-listing-image"
96
562
  />
97
563
  )}
98
- <CapLabel
99
- type="label19"
100
- className="rcs-listing-content title"
101
- fontWeight="bold"
102
- >
103
- {title}
104
- </CapLabel>
564
+ {!isTextOnlyCard && (
565
+ <CapLabel
566
+ type="label19"
567
+ className="rcs-listing-content title"
568
+ fontWeight="bold"
569
+ >
570
+ {title}
571
+ </CapLabel>
572
+ )}
105
573
  <CapLabel type="label19" className="rcs-listing-content desc">
106
574
  {description}
107
575
  </CapLabel>
@@ -109,4 +577,3 @@ export const getRCSContent = (template) => {
109
577
  </div>
110
578
  );
111
579
  };
112
-