@capillarytech/creatives-library 9.1.8-alpha.sprint-cap-214249.38 → 9.2.0

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 (127) hide show
  1. package/constants/unified.js +4 -0
  2. package/index.js +13 -0
  3. package/package.json +1 -1
  4. package/services/getSchema.js +4 -1
  5. package/services/tests/getSchema.test.js +2 -2
  6. package/translations/en.json +1 -0
  7. package/translations/ja-JP.json +1 -0
  8. package/translations/zh.json +1 -0
  9. package/utils/common.js +6 -0
  10. package/utils/createMobilePushPayload.js +33 -47
  11. package/utils/tagValidations.js +35 -4
  12. package/utils/templateVarUtils.js +49 -0
  13. package/utils/tests/createMobilePushPayload.test.js +8 -102
  14. package/utils/tests/tagValidations.test.js +48 -0
  15. package/utils/tests/templateVarUtils.test.js +89 -0
  16. package/v2Components/CapMpushCTA/index.js +9 -10
  17. package/v2Components/CapMpushCTA/index.scss +3 -29
  18. package/v2Components/CapTagList/TagFallbackPanel.js +124 -0
  19. package/v2Components/CapTagList/constants.js +5 -0
  20. package/v2Components/CapTagList/index.js +46 -7
  21. package/v2Components/CapTagList/messages.js +44 -0
  22. package/v2Components/CapTagList/style.scss +113 -1
  23. package/v2Components/CapTagList/tests/TagFallback.test.js +222 -0
  24. package/v2Components/CapTagList/utils.js +17 -0
  25. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +13 -26
  26. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
  27. package/v2Components/CommonTestAndPreview/constants.js +3 -2
  28. package/v2Components/CommonTestAndPreview/index.js +62 -62
  29. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -79
  30. package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -86
  31. package/v2Components/CommonTestAndPreview/tests/utils.test.js +102 -0
  32. package/v2Components/CommonTestAndPreview/utils.js +42 -3
  33. package/v2Components/FormBuilder/Classic.js +24 -14
  34. package/v2Components/FormBuilder/Functional/channels/mobilepush/config.js +1 -0
  35. package/v2Components/FormBuilder/Functional/channels/mobilepush/getEditorErrorDescriptor.js +1 -1
  36. package/v2Components/FormBuilder/Functional/channels/mobilepush/tests/validate.test.js +57 -0
  37. package/v2Components/FormBuilder/Functional/channels/mobilepush/validate.js +4 -4
  38. package/v2Components/FormBuilder/Functional/channels/sms/getEditorErrorDescriptor.js +3 -0
  39. package/v2Components/FormBuilder/Functional/channels/sms/tests/getEditorErrorDescriptor.test.js +5 -0
  40. package/v2Components/FormBuilder/Functional/channels/sms/tests/validate.test.js +6 -0
  41. package/v2Components/FormBuilder/Functional/channels/sms/validate.js +3 -1
  42. package/v2Components/FormBuilder/Functional/renderers/mpushRenderers.js +3 -0
  43. package/v2Components/FormBuilder/Functional/tests/manual.typingPerf.test.js +135 -0
  44. package/v2Components/FormBuilder/Functional/tests/mpush.crossFlowParity.test.js +1 -1
  45. package/v2Components/FormBuilder/Functional/tests/mpush.ctaFlows.parity.test.js +320 -0
  46. package/v2Components/FormBuilder/Functional/tests/mpush.editContainer.parity.test.js +148 -0
  47. package/v2Components/FormBuilder/Functional/tests/mpush.libraryValidity.parity.test.js +152 -0
  48. package/v2Components/FormBuilder/Functional/tests/mpush.shellEvents.test.js +1 -1
  49. package/v2Components/FormBuilder/Functional/tests/mpush.singlePlatform.test.js +1 -1
  50. package/v2Components/FormBuilder/Functional/tests/mpushRenderers.test.js +22 -0
  51. package/v2Components/FormBuilder/tests/mpush.characterization.test.js +2 -2
  52. package/v2Components/TemplatePreview/_templatePreview.scss +2 -12
  53. package/v2Components/TemplatePreview/index.js +17 -30
  54. package/v2Components/TemplatePreview/tests/index.test.js +0 -61
  55. package/v2Containers/Cap/index.js +3 -0
  56. package/v2Containers/Cap/messages.js +4 -0
  57. package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +1 -0
  58. package/v2Containers/CreativesContainer/SlideBoxContent.js +151 -70
  59. package/v2Containers/CreativesContainer/index.js +6 -3
  60. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -29
  61. package/v2Containers/InApp/index.js +4 -1
  62. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +3 -0
  63. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +2 -0
  64. package/v2Containers/Line/Container/Text/index.js +3 -1
  65. package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +16 -0
  66. package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +18 -0
  67. package/v2Containers/MobilePush/Create/_mobilePushCreate.scss +70 -0
  68. package/v2Containers/MobilePush/Create/actions.js +52 -0
  69. package/v2Containers/MobilePush/Create/constants.js +26 -0
  70. package/v2Containers/MobilePush/Create/index.js +2149 -0
  71. package/v2Containers/MobilePush/Create/messages.js +349 -0
  72. package/v2Containers/MobilePush/Create/reducer.js +72 -0
  73. package/v2Containers/MobilePush/Create/sagas.js +79 -0
  74. package/v2Containers/MobilePush/Create/selectors.js +29 -0
  75. package/v2Containers/MobilePush/Create/test/contentValidity.test.js +154 -0
  76. package/v2Containers/MobilePush/Create/test/saga.test.js +19 -0
  77. package/v2Containers/MobilePush/Create/test/stayOpenOnSave.test.js +80 -0
  78. package/v2Containers/MobilePush/Edit/_mobilePushCreate.scss +65 -0
  79. package/v2Containers/MobilePush/Edit/actions.js +94 -0
  80. package/v2Containers/MobilePush/Edit/constants.js +37 -0
  81. package/v2Containers/MobilePush/Edit/index.js +2407 -0
  82. package/v2Containers/MobilePush/Edit/messages.js +341 -0
  83. package/v2Containers/MobilePush/Edit/reducer.js +113 -0
  84. package/v2Containers/MobilePush/Edit/sagas.js +113 -0
  85. package/v2Containers/MobilePush/Edit/selectors.js +33 -0
  86. package/v2Containers/MobilePush/Edit/test/contentValidity.test.js +149 -0
  87. package/v2Containers/MobilePush/Edit/test/saga.test.js +255 -0
  88. package/v2Containers/MobilePush/Edit/test/stayOpenOnSave.test.js +60 -0
  89. package/v2Containers/MobilePush/commonMethods.js +333 -0
  90. package/v2Containers/MobilePush/eventsMap.js +130 -0
  91. package/v2Containers/MobilePush/tests/commonMethods.test.js +401 -0
  92. package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
  93. package/v2Containers/MobilePushNew/components/MediaUploaders.js +192 -207
  94. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +121 -116
  95. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
  96. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +72 -316
  97. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +16 -45
  98. package/v2Containers/MobilePushNew/constants.js +0 -5
  99. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
  100. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -52
  101. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -38
  102. package/v2Containers/MobilePushNew/hooks/useUpload.js +39 -29
  103. package/v2Containers/MobilePushNew/index.js +192 -454
  104. package/v2Containers/MobilePushNew/index.scss +4 -188
  105. package/v2Containers/MobilePushNew/messages.js +6 -86
  106. package/v2Containers/MobilePushNew/tests/index.test.js +1 -450
  107. package/v2Containers/MobilePushNew/tests/utils.test.js +0 -25
  108. package/v2Containers/MobilePushNew/utils.js +0 -8
  109. package/v2Containers/MobilepushWrapper/_mobilepushWrapper.scss +22 -0
  110. package/v2Containers/MobilepushWrapper/index.js +178 -0
  111. package/v2Containers/MobilepushWrapper/messages.js +29 -0
  112. package/v2Containers/Rcs/index.js +8 -1
  113. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +59 -0
  114. package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +4 -0
  115. package/v2Containers/SmsTrai/Edit/index.js +17 -7
  116. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +42 -0
  117. package/v2Containers/Templates/_templates.scss +2 -10
  118. package/v2Containers/Templates/index.js +90 -84
  119. package/v2Containers/Templates/tests/index.test.js +0 -68
  120. package/v2Containers/Viber/index.js +3 -1
  121. package/v2Containers/WebPush/Create/utils/validation.js +6 -0
  122. package/v2Containers/WebPush/Create/utils/validation.test.js +50 -0
  123. package/v2Containers/Whatsapp/index.js +9 -5
  124. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
  125. package/v2Containers/Zalo/index.js +4 -1
  126. package/v2Components/CapMpushCTA/tests/index.test.js +0 -89
  127. /package/{v2Components/FormBuilder/Functional/tests/fixtures/mpushInitialSchema.js → v2Containers/MobilePush/initialSchema.js} +0 -0
@@ -0,0 +1,222 @@
1
+ import React from 'react';
2
+ import { render, screen, fireEvent, act } from '@testing-library/react';
3
+ import '@testing-library/jest-dom';
4
+ import { IntlProvider } from 'react-intl';
5
+ import TagFallbackPanel from '../TagFallbackPanel';
6
+ import { CapTagList } from '../index';
7
+ import { FALLBACK_OPTIONS } from '../constants';
8
+ import { buildTagWithFallback, isValidFallbackValue } from '../utils';
9
+
10
+ describe('buildTagWithFallback', () => {
11
+ it('returns tag as it is for NONE', () => {
12
+ expect(buildTagWithFallback('badge_description', FALLBACK_OPTIONS.NONE)).toBe('badge_description');
13
+ });
14
+
15
+ it('adds empty default for NULL_VALUE', () => {
16
+ expect(buildTagWithFallback('badge_description', FALLBACK_OPTIONS.NULL_VALUE)).toBe("badge_description | default: ''");
17
+ });
18
+
19
+ it('adds trimmed fallback value for CUSTOM_VALUE', () => {
20
+ expect(buildTagWithFallback('badge_description', FALLBACK_OPTIONS.CUSTOM_VALUE, ' Gold ')).toBe("badge_description | default: 'Gold'");
21
+ });
22
+
23
+ it('wraps value in double quotes when it has a single quote', () => {
24
+ expect(buildTagWithFallback('name', FALLBACK_OPTIONS.CUSTOM_VALUE, "member's")).toBe('name | default: "member\'s"');
25
+ });
26
+ });
27
+
28
+ describe('isValidFallbackValue', () => {
29
+ it('rejects braces and values having both quote types', () => {
30
+ expect(isValidFallbackValue('Gold')).toBe(true);
31
+ expect(isValidFallbackValue("member's")).toBe(true);
32
+ expect(isValidFallbackValue('a}b')).toBe(false);
33
+ expect(isValidFallbackValue('{a')).toBe(false);
34
+ expect(isValidFallbackValue(`it's "x"`)).toBe(false);
35
+ });
36
+
37
+ it('treats a missing value as valid (defaults to empty string)', () => {
38
+ expect(isValidFallbackValue()).toBe(true);
39
+ });
40
+ });
41
+
42
+ describe('TagFallbackPanel', () => {
43
+ const renderPanel = (props = {}) => {
44
+ const onInsert = jest.fn();
45
+ const onBack = jest.fn();
46
+ render(
47
+ <IntlProvider locale="en">
48
+ <TagFallbackPanel
49
+ tagKey="badge_description"
50
+ tagName="Badge description"
51
+ parentName="Badge"
52
+ onBack={onBack}
53
+ onInsert={onInsert}
54
+ {...props}
55
+ />
56
+ </IntlProvider>
57
+ );
58
+ return { onInsert, onBack };
59
+ };
60
+ const insertButton = () => screen.getByText('Insert tag').closest('button');
61
+
62
+ it('shows tag and parent name with "Don’t send message" selected by default', () => {
63
+ renderPanel();
64
+ expect(screen.getByText('Badge description')).toBeInTheDocument();
65
+ expect(screen.getByText('Badge')).toBeInTheDocument();
66
+ expect(screen.getByLabelText('Don’t send message')).toBeChecked();
67
+ expect(screen.getByText('{{badge_description}}')).toBeInTheDocument();
68
+ });
69
+
70
+ it('does not render the group name when parentName is not passed', () => {
71
+ renderPanel({ parentName: undefined });
72
+ expect(screen.getByText('Badge description')).toBeInTheDocument();
73
+ expect(screen.queryByText('Badge')).toBeNull();
74
+ expect(document.querySelector('.tag-fallback-group-name')).toBeNull();
75
+ });
76
+
77
+ it('does not throw on copy when clipboard is not available', () => {
78
+ Object.assign(navigator, { clipboard: undefined });
79
+ renderPanel();
80
+ expect(() => fireEvent.click(screen.getByLabelText('Copy'))).not.toThrow();
81
+ });
82
+
83
+ it('inserts tag as it is by default', () => {
84
+ const { onInsert } = renderPanel();
85
+ fireEvent.click(insertButton());
86
+ expect(onInsert).toHaveBeenCalledWith('badge_description');
87
+ });
88
+
89
+ it('inserts tag with empty default for "Send with null value"', () => {
90
+ const { onInsert } = renderPanel();
91
+ fireEvent.click(screen.getByLabelText('Send with null value'));
92
+ expect(screen.getByText("{{badge_description | default: ''}}")).toBeInTheDocument();
93
+ fireEvent.click(insertButton());
94
+ expect(onInsert).toHaveBeenCalledWith("badge_description | default: ''");
95
+ });
96
+
97
+ it('inserts tag with entered fallback value', () => {
98
+ const { onInsert } = renderPanel();
99
+ fireEvent.click(screen.getByLabelText('Fallback value'));
100
+ expect(insertButton()).toBeDisabled();
101
+ fireEvent.change(screen.getByPlaceholderText('Enter fallback value'), { target: { value: 'Gold' } });
102
+ expect(screen.getByText("{{badge_description | default: 'Gold'}}")).toBeInTheDocument();
103
+ fireEvent.click(insertButton());
104
+ expect(onInsert).toHaveBeenCalledWith("badge_description | default: 'Gold'");
105
+ });
106
+
107
+ it('disables insert for an invalid fallback value', () => {
108
+ renderPanel();
109
+ fireEvent.click(screen.getByLabelText('Fallback value'));
110
+ fireEvent.change(screen.getByPlaceholderText('Enter fallback value'), { target: { value: '{bad}' } });
111
+ expect(insertButton()).toBeDisabled();
112
+ });
113
+
114
+ it('copies the previewed tag on copy icon click', () => {
115
+ const writeText = jest.fn();
116
+ Object.assign(navigator, { clipboard: { writeText } });
117
+ renderPanel();
118
+ fireEvent.click(screen.getByLabelText('Send with null value'));
119
+ fireEvent.click(screen.getByLabelText('Copy'));
120
+ expect(writeText).toHaveBeenCalledWith("{{badge_description | default: ''}}");
121
+ });
122
+
123
+ it('calls onBack on back arrow click', () => {
124
+ const { onBack } = renderPanel();
125
+ fireEvent.click(screen.getByLabelText('Back'));
126
+ expect(onBack).toHaveBeenCalled();
127
+ });
128
+ });
129
+
130
+ describe('CapTagList fallback flow', () => {
131
+ const getInstance = (props = {}) => {
132
+ const instance = new CapTagList({
133
+ tags: {},
134
+ onSelect: jest.fn(),
135
+ intl: { formatMessage: ({ defaultMessage }) => defaultMessage },
136
+ disableTagsDetails: {},
137
+ ...props,
138
+ });
139
+ instance.setState = (update) => {
140
+ instance.state = { ...instance.state, ...(typeof update === 'function' ? update(instance.state) : update) };
141
+ };
142
+ return instance;
143
+ };
144
+ const leafInfo = (tagKey, extra = {}) => ({
145
+ selectedNodes: [{ isLeaf: true, tagKey, tagName: 'Badge description', parentName: 'Badge', ...extra }],
146
+ });
147
+
148
+ it('opens the fallback panel instead of inserting on leaf click', () => {
149
+ const instance = getInstance();
150
+ const info = leafInfo('badge_description');
151
+ instance.handleOnSelect(['Badge.badge_description'], info);
152
+ expect(instance.props.onSelect).not.toHaveBeenCalled();
153
+ expect(instance.state.selectedTag).toEqual({
154
+ tagKey: 'badge_description', tagName: 'Badge description', parentName: 'Badge', info,
155
+ });
156
+ });
157
+
158
+ it('keeps the dynamic expiry tag flow as it is', () => {
159
+ const instance = getInstance();
160
+ instance.handleOnSelect(['k'], leafInfo('dynamic_expiry_date_after_(N)_days.FORMAT_1'));
161
+ expect(instance.state.selectedTag).toBeNull();
162
+ expect(instance.state.showModal).toBe(true);
163
+ });
164
+
165
+ it('inserts built tag value and closes on insert', () => {
166
+ const instance = getInstance();
167
+ const info = leafInfo('badge_description');
168
+ instance.handleOnSelect(['Badge.badge_description'], info);
169
+ instance.handleFallbackInsert("badge_description | default: 'Gold'");
170
+ expect(instance.props.onSelect).toHaveBeenCalledWith(["badge_description | default: 'Gold'"], info);
171
+ expect(instance.state).toEqual(expect.objectContaining({ visible: false, selectedTag: null, selectedNodeKey: '' }));
172
+ });
173
+
174
+ it('goes back to the tag list and clears selection on back', () => {
175
+ const instance = getInstance();
176
+ instance.handleOnSelect(['Badge.badge_description'], leafInfo('badge_description'));
177
+ instance.handleFallbackBack();
178
+ expect(instance.state.selectedTag).toBeNull();
179
+ expect(instance.state.selectedNodeKey).toBe('');
180
+ });
181
+
182
+ it('resets the fallback panel when popover closes', () => {
183
+ const instance = getInstance();
184
+ instance.handleOnSelect(['Badge.badge_description'], leafInfo('badge_description'));
185
+ instance.togglePopoverVisibility(false);
186
+ expect(instance.state.selectedTag).toBeNull();
187
+ });
188
+
189
+ it('keeps the searched text after going back from the fallback panel', () => {
190
+ const intl = { formatMessage: ({ defaultMessage }) => defaultMessage, locale: 'en' };
191
+ const ref = React.createRef();
192
+ render(
193
+ <IntlProvider locale="en">
194
+ <CapTagList
195
+ ref={ref}
196
+ tags={{ Badge: { name: 'Badge', subtags: { badge_description: { name: 'Badge description', desc: 'Badge description' } } } }}
197
+ onSelect={jest.fn()}
198
+ intl={intl}
199
+ disableTagsDetails={{}}
200
+ hidePopover
201
+ visibleTaglist
202
+ />
203
+ </IntlProvider>
204
+ );
205
+ fireEvent.change(screen.getByPlaceholderText('Search'), { target: { value: 'badge desc' } });
206
+ // antd tree rows are not rendered in jsdom, so select the tag through the instance
207
+ act(() => ref.current.handleOnSelect(['Badge.badge_description'], leafInfo('badge_description')));
208
+ expect(screen.queryByPlaceholderText('Search')).toBeNull();
209
+ fireEvent.click(screen.getByLabelText('Back'));
210
+ expect(screen.getByPlaceholderText('Search')).toHaveValue('badge desc');
211
+ });
212
+
213
+ it('adds tag and parent names to leaf nodes', () => {
214
+ const instance = getInstance();
215
+ const list = instance.renderTags({
216
+ Badge: { name: 'Badge', subtags: { badge_description: { name: 'Badge description', desc: 'Badge description' } } },
217
+ });
218
+ expect(list[0].children[0]).toEqual(expect.objectContaining({
219
+ tagKey: 'badge_description', tagName: 'Badge description', parentName: 'Badge',
220
+ }));
221
+ });
222
+ });
@@ -0,0 +1,17 @@
1
+ import { FALLBACK_OPTIONS } from './constants';
2
+
3
+ // { } would break tag braces; a value having both quote types cannot be wrapped in either.
4
+ export const isValidFallbackValue = (value = '') => !/[{}]/.test(value) && !(value.includes("'") && value.includes('"'));
5
+
6
+ // Builds tag value (without braces) for the fallback option, e.g. tag | default: 'value'.
7
+ export const buildTagWithFallback = (tagKey, option, fallbackValue = '') => {
8
+ if (option === FALLBACK_OPTIONS.NULL_VALUE) {
9
+ return `${tagKey} | default: ''`;
10
+ }
11
+ if (option === FALLBACK_OPTIONS.CUSTOM_VALUE) {
12
+ const value = fallbackValue.trim();
13
+ const quote = value.includes("'") ? '"' : "'";
14
+ return `${tagKey} | default: ${quote}${value}${quote}`;
15
+ }
16
+ return tagKey;
17
+ };
@@ -86,20 +86,14 @@ const MobilePushPreviewContent = ({
86
86
 
87
87
  // Render MobilePush carousel (based on TemplatePreview renderMobilePushCarousel)
88
88
  const renderMobilePushCarousel = (contentData) => {
89
- // Only cards with an uploaded image/video
90
- const cardsWithMedia = (contentData?.carouselData || []).filter((item) => {
91
- const mediaType = item?.mediaType?.toLowerCase();
92
- return (mediaType === MEDIA_TYPE_IMAGE.toLowerCase() && (item?.imageUrl || item?.url))
93
- || (mediaType === MEDIA_TYPE_VIDEO.toLowerCase() && (item?.videoPreviewImg || item?.videoSrc));
94
- });
95
- if (cardsWithMedia.length === 0) {
89
+ if (!contentData?.carouselData || contentData?.carouselData?.length === 0) {
96
90
  return null;
97
91
  }
98
92
 
99
93
  return (
100
94
  <CapRow type="flex" vertical noWrap className="msg-container-carousel mobile-push-carousel-container">
101
- <CapRow type="flex" noWrap className="scroll-container mobile-push-scroll-container">
102
- {cardsWithMedia.map((item, idx) => (
95
+ <CapRow useLegacy className="scroll-container mobile-push-scroll-container">
96
+ {contentData?.carouselData?.map((item, idx) => (
103
97
  <CapColumn
104
98
  key={`carousel-card-${idx}`}
105
99
  className="mobile-push-carousel-card message-pop align-left message-pop-carousel"
@@ -111,20 +105,13 @@ const MobilePushPreviewContent = ({
111
105
  className="carousel-image"
112
106
  />
113
107
  )}
114
- {item?.mediaType?.toLowerCase() === MEDIA_TYPE_VIDEO.toLowerCase() && (item?.videoPreviewImg || item?.videoSrc) && (
108
+ {item?.mediaType?.toLowerCase() === MEDIA_TYPE_VIDEO.toLowerCase() && item?.videoPreviewImg && (
115
109
  <CapRow className="video-preview">
116
- {item?.videoPreviewImg ? (
117
- <CapImage
118
- src={item?.videoPreviewImg || item?.url}
119
- alt="carousel-video-preview"
120
- className="carousel-video-preview"
121
- />
122
- ) : (
123
- // No thumbnail from the upload: show the video's first frame
124
- <video src={item?.videoSrc} className="carousel-video-preview" muted preload="metadata">
125
- <track kind="captions" />
126
- </video>
127
- )}
110
+ <CapImage
111
+ src={item?.videoPreviewImg || item?.url}
112
+ alt="carousel-video-preview"
113
+ className="carousel-video-preview"
114
+ />
128
115
  <CapRow className="icon-position">
129
116
  <CapImage className="video-icon" src={videoPlay} alt="Play" />
130
117
  </CapRow>
@@ -230,15 +217,15 @@ const MobilePushPreviewContent = ({
230
217
  {/* Action Buttons */}
231
218
  {(deviceContent?.actions || []).filter((action) => action?.label || action?.actionText).length > 0
232
219
  && deviceContent?.carouselData?.length === 0 && (
233
- <CapRow type="flex" noWrap className="actions">
234
- {deviceContent.actions.map((action, index) => (
220
+ <CapRow useLegacy className="actions">
221
+ {(deviceContent?.actions || []).map((action) => (
235
222
  (action?.label || action?.actionText) && (
236
223
  <span
237
224
  className="action"
238
- key={`action-${index}`}
225
+ key={`action-${action?.label || action?.actionText}`}
239
226
  title={action?.url || action?.actionLink || ''}
240
227
  >
241
- {action?.label || action?.actionText}
228
+ {action?.label?.toUpperCase() || action?.actionText?.toUpperCase()}
242
229
  </span>
243
230
  )
244
231
  ))}
@@ -2307,21 +2307,9 @@
2307
2307
  flex-direction: row;
2308
2308
  gap: $CAP_SPACE_08;
2309
2309
 
2310
- // One button: centred. Two: equal halves, each centred, split by a divider.
2311
2310
  .action {
2312
2311
  font-size: $FONT_SIZE_S;
2313
- font-weight: 600;
2314
- color: $FONT_COLOR_01;
2315
- flex: 1 1 0;
2316
- min-width: 0;
2317
- text-align: center;
2318
- white-space: nowrap;
2319
- overflow: hidden;
2320
- text-overflow: ellipsis;
2321
-
2322
- & + .action {
2323
- border-left: 1px solid $CAP_G07;
2324
- }
2312
+ // Additional action button styles from TemplatePreview
2325
2313
  }
2326
2314
  }
2327
2315
  }
@@ -126,6 +126,9 @@ export const SMS_MUSTACHE_TAG_PATTERN = /\{\{[^}]+\}\}/;
126
126
  /** WhatsApp slot key `{{<var>}}_<index>`; captures `<var>`. */
127
127
  export const WHATSAPP_SLOT_KEY_PATTERN = /^\{\{(.+?)\}\}_\d+$/;
128
128
 
129
+ /** Regex metacharacters to escape before building a RegExp from an arbitrary tag key. */
130
+ export const REGEX_SPECIAL_CHARS_REGEX = /[.*+?^${}()|[\]\\]/g;
131
+
129
132
  /**
130
133
  * Key on `smsFallbackContent` passed into Test & Preview — RCS slot map from SmsTraiEdit
131
134
  * (`onRcsFallbackEditorStateChange`), merged before tag extraction like the embedded SMS editor.
@@ -209,8 +212,6 @@ export const CTA_TYPE_EXTERNAL_URL = 'EXTERNAL_URL';
209
212
  // ============================================
210
213
  export const STYLE_TYPE_BIG_PICTURE = 'BIG_PICTURE';
211
214
  export const STYLE_TYPE_BIG_TEXT = 'BIG_TEXT';
212
- export const STYLE_TYPE_VIDEO = 'VIDEO';
213
- export const STYLE_TYPE_MANUAL_CAROUSEL = 'MANUAL_CAROUSEL';
214
215
 
215
216
  // ============================================
216
217
  // DEVICE TYPE CONSTANTS (for API payloads)
@@ -43,7 +43,10 @@ import {
43
43
  getWhatsappCarouselCardBodyText,
44
44
  mergeZaloUnfilledParamTags,
45
45
  fillSlotMapFromCustomValues,
46
+ appendDltSmsTagRows,
47
+ dropBlankValues,
46
48
  } from './utils';
49
+ import { resolveDltSmsTemplate } from '../../utils/templateVarUtils';
47
50
  import AddTestCustomerButton from './AddTestCustomer';
48
51
  import ExistingCustomerModal from './ExistingCustomerModal';
49
52
  // Import constants
@@ -72,8 +75,6 @@ import {
72
75
  CTA_TYPE_EXTERNAL_URL,
73
76
  STYLE_TYPE_BIG_PICTURE,
74
77
  STYLE_TYPE_BIG_TEXT,
75
- STYLE_TYPE_VIDEO,
76
- STYLE_TYPE_MANUAL_CAROUSEL,
77
78
  DEVICE_TYPE_ANDROID,
78
79
  DEVICE_TYPE_IOS,
79
80
  BUTTON_TYPE_NONE,
@@ -103,6 +104,7 @@ import {
103
104
  RCS_TEST_META_CARD_TYPE_STANDALONE,
104
105
  RCS_TEST_META_CARD_ORIENTATION_VERTICAL,
105
106
  RCS_TEST_META_CARD_WIDTH_SMALL,
107
+ REGEX_SPECIAL_CHARS_REGEX,
106
108
  } from './constants';
107
109
  import { getCdnUrl } from '../../utils/cdnTransformation';
108
110
  import {
@@ -303,6 +305,7 @@ const CommonTestAndPreview = (props) => {
303
305
  const smsTemplateConfigs = formDataForSendTest?.templateConfigs || {};
304
306
  const smsTraiDltEnabled = !!smsTemplateConfigs?.traiDltEnabled;
305
307
  const registeredSenderIds = smsTemplateConfigs?.registeredSenderIds || [];
308
+ const smsDltEditorVarMapped = smsTemplateConfigs?.varMapped || {};
306
309
 
307
310
  // Fetch sender details and WeCRM accounts when Test & Preview opens (SMS, Email, WhatsApp, RCS — same process)
308
311
  useEffect(() => {
@@ -582,10 +585,15 @@ const CommonTestAndPreview = (props) => {
582
585
  const leftPanelExtractedTags = useMemo(() => {
583
586
  if (channel === CHANNELS.SMS) {
584
587
  const smsEditorBody = typeof getCurrentContent === 'string' ? getCurrentContent : '';
585
- if (!smsTemplateHasMustacheTags(smsEditorBody)) return [];
588
+ const withDltSmsRows = (rows) => (smsTraiDltEnabled
589
+ ? appendDltSmsTagRows(rows, smsDltEditorVarMapped, smsEditorBody)
590
+ : rows);
591
+ if (!smsTemplateHasMustacheTags(smsEditorBody)) return withDltSmsRows([]);
586
592
  const extractTagsFromApi = extractedTags ?? [];
587
- if (extractTagsFromApi.length > 0) return extractTagsFromApi;
588
- return buildSyntheticSmsMustacheTags(smsEditorBody);
593
+ const mustacheRows = extractTagsFromApi.length > 0
594
+ ? extractTagsFromApi
595
+ : buildSyntheticSmsMustacheTags(smsEditorBody);
596
+ return withDltSmsRows(mustacheRows);
589
597
  }
590
598
  const hasFallbackSmsBody = !!(smsFallbackContent?.templateContent || smsFallbackContent?.content);
591
599
  if (channel === CHANNELS.RCS && hasFallbackSmsBody) {
@@ -614,6 +622,7 @@ const CommonTestAndPreview = (props) => {
614
622
  channel,
615
623
  extractedTags,
616
624
  getCurrentContent,
625
+ smsTraiDltEnabled,
617
626
  formData,
618
627
  smsFallbackContent,
619
628
  smsFallbackExtractedTags,
@@ -693,15 +702,18 @@ const CommonTestAndPreview = (props) => {
693
702
  Object.keys(tagValues || {}).forEach((tagPath) => {
694
703
  const tagName = tagPath.split('.').pop(); // Get the actual tag name from the path
695
704
  // Escape regex metacharacters in tagName (arbitrary JSON key) so it can't break the pattern.
696
- const escapedTagName = tagName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
705
+ const escapedTagName = tagName.replace(REGEX_SPECIAL_CHARS_REGEX, '\\$&');
697
706
  // Braces escaped: unescaped `{{1}}` parses `{1}` as a quantifier and never matches numbered slots.
698
- const tagRegex = new RegExp(`\\{\\{${escapedTagName}\\}\\}`, 'g');
707
+ const escapedTagPath = tagPath.replace(REGEX_SPECIAL_CHARS_REGEX, '\\$&');
708
+ const tagTokenPattern = tagPath === tagName || Object.prototype.hasOwnProperty.call(tagValues, tagName)
709
+ ? escapedTagPath
710
+ : `(?:${escapedTagPath}|${escapedTagName})`;
711
+ const tagRegex = new RegExp(`\\{\\{${tagTokenPattern}\\}\\}`, 'g');
699
712
  const rawValue = tagValues[tagPath];
700
713
  // Preserve legitimate falsy values (0, false); only an unset/blank slot keeps the placeholder.
701
714
  const hasValue = rawValue !== null && rawValue !== undefined && rawValue !== '';
702
- const replacement = hasValue ? String(rawValue) : `{{${tagName}}}`;
703
715
  // Replacer function (not a string) so `$&`/`$1`-style sequences in the value are inserted literally.
704
- resolvedText = resolvedText.replace(tagRegex, () => replacement);
716
+ resolvedText = resolvedText.replace(tagRegex, (match) => (hasValue ? String(rawValue) : match));
705
717
  });
706
718
 
707
719
  return resolvedText;
@@ -1485,10 +1497,17 @@ const CommonTestAndPreview = (props) => {
1485
1497
  // Extract SMS message from content
1486
1498
  const message = contentStr || formDataObj?.['sms-editor'] || formDataObj?.[0]?.['sms-editor'] || formDataObj?.messageBody || '';
1487
1499
 
1488
- // Resolve tags in message if custom values are provided
1489
- const resolvedMessage = customValuesObj && Object.keys(customValuesObj).length > 0
1490
- ? resolveTagsInText(message, customValuesObj)
1500
+ const smsDltVarMappedForTest = formDataObj?.templateConfigs?.varMapped || {};
1501
+ const smsDltOnForTest = Boolean(formDataObj?.templateConfigs?.traiDltEnabled);
1502
+ const dltResolvedMessage = smsDltOnForTest
1503
+ ? resolveDltSmsTemplate(message, {
1504
+ ...smsDltVarMappedForTest,
1505
+ ...dropBlankValues(customValuesObj),
1506
+ })
1491
1507
  : message;
1508
+ const resolvedMessage = customValuesObj && Object.keys(customValuesObj).length > 0
1509
+ ? resolveTagsInText(dltResolvedMessage, customValuesObj)
1510
+ : dltResolvedMessage;
1492
1511
 
1493
1512
  const baseData = formDataObj?.base || formDataObj?.[0]?.base || formDataObj?.[0] || {};
1494
1513
  const templateId = formDataObj?.templateConfigs?.templateId || formDataObj?.template_id || formDataObj?.templateId || baseData?.template_id || '';
@@ -1846,7 +1865,7 @@ const CommonTestAndPreview = (props) => {
1846
1865
 
1847
1866
  case CHANNELS.MOBILEPUSH: {
1848
1867
  // MobilePush uses "PUSH" as channel in API
1849
- // Mirrors the removed old editor's getTransformedData
1868
+ // Reference: app/v2Containers/MobilePush/Create/index.js getTransformedData (lines 417-645)
1850
1869
  //
1851
1870
  // Data can come in multiple formats:
1852
1871
  // 1. formData[0] and formData[1] (raw formData from old MobilePush Create/Edit)
@@ -1865,10 +1884,6 @@ const CommonTestAndPreview = (props) => {
1865
1884
  'message-title': formDataObj.androidContent.header || '',
1866
1885
  'message-editor': formDataObj.androidContent.bodyText || '',
1867
1886
  'image': formDataObj.androidContent.bodyImage || '',
1868
- // bodyVideo also carries GIFs; send only real videos
1869
- 'video': formDataObj.androidContent.bodyGif ? '' : (formDataObj.androidContent.bodyVideo?.videoSrc || ''),
1870
- // Saved cards, already in the shape Save sent
1871
- carouselData: formDataObj.androidContent.carouselData || [],
1872
1887
  // Extract CTA info from actions if available
1873
1888
  ...(formDataObj.androidContent.actions?.[0] && {
1874
1889
  'cta-deeplink-label': formDataObj.androidContent.actions[0].label,
@@ -1887,8 +1902,6 @@ const CommonTestAndPreview = (props) => {
1887
1902
  'message-title2': formDataObj.iosContent.header || '',
1888
1903
  'message-editor2': formDataObj.iosContent.bodyText || '',
1889
1904
  'image': formDataObj.iosContent.bodyImage || '',
1890
- 'video': formDataObj.iosContent.bodyGif ? '' : (formDataObj.iosContent.bodyVideo?.videoSrc || ''),
1891
- carouselData: formDataObj.iosContent.carouselData || [],
1892
1905
  // Extract CTA info from actions if available
1893
1906
  ...(formDataObj.iosContent.actions?.[0] && {
1894
1907
  'cta-deeplink2-label': formDataObj.iosContent.actions[0].label,
@@ -1994,36 +2007,11 @@ const CommonTestAndPreview = (props) => {
1994
2007
  };
1995
2008
  };
1996
2009
 
1997
- const hasCarousel = (data) => Array.isArray(data.carouselData) && data.carouselData.length > 0;
1998
- // Carousel, then video, then image; BIG_TEXT when none
1999
- const getMpushStyle = (data) => {
2000
- if (hasCarousel(data)) return STYLE_TYPE_MANUAL_CAROUSEL;
2001
- if (data.video) return STYLE_TYPE_VIDEO;
2002
- return data.image ? STYLE_TYPE_BIG_PICTURE : STYLE_TYPE_BIG_TEXT;
2003
- };
2004
- const getMpushType = (data) => {
2005
- if (hasCarousel(data)) return MEDIA_TYPE_CAROUSEL;
2006
- if (data.video) return MEDIA_TYPE_VIDEO;
2007
- return data.image ? MEDIA_TYPE_IMAGE : MEDIA_TYPE_TEXT;
2008
- };
2009
- // Raw URL, as Save sends it (the CDN helper is an image transform)
2010
- const toMpushVideoMedia = (url) => [{ url, text: '', type: MEDIA_TYPE_VIDEO }];
2011
- // Cards plus the spec's media list, as CreativesContainer getMobilePushCarouselData sends to campaigns
2012
- const addMpushCarousel = (expandableDetails, data) => {
2013
- Object.assign(expandableDetails, {
2014
- carouselData: data.carouselData,
2015
- media: data.carouselData.map((card) => ({
2016
- url: card?.mediaType?.toUpperCase() === MEDIA_TYPE_VIDEO ? card.videoSrc : card.imageUrl,
2017
- type: card?.mediaType?.toUpperCase(),
2018
- text: '',
2019
- })),
2020
- });
2021
- };
2022
-
2023
2010
  // Helper function to build expandableDetails for Android
2024
2011
  const buildAndroidExpandableDetails = (data) => {
2012
+ // Default style is BIG_TEXT, change to BIG_PICTURE if image exists
2025
2013
  const imageLink = data.image;
2026
- const style = getMpushStyle(data);
2014
+ const style = imageLink ? STYLE_TYPE_BIG_PICTURE : STYLE_TYPE_BIG_TEXT;
2027
2015
 
2028
2016
  const expandableDetails = {
2029
2017
  style,
@@ -2032,11 +2020,7 @@ const CommonTestAndPreview = (props) => {
2032
2020
  };
2033
2021
 
2034
2022
  // Add image if present (transform to CDN URL if needed)
2035
- if (hasCarousel(data)) {
2036
- addMpushCarousel(expandableDetails, data);
2037
- } else if (data.video) {
2038
- expandableDetails.media = toMpushVideoMedia(data.video);
2039
- } else if (imageLink) {
2023
+ if (imageLink) {
2040
2024
  expandableDetails.image = getCdnUrl({ url: imageLink, channelName: CHANNEL_NAME_MOBILE_PUSH });
2041
2025
  }
2042
2026
 
@@ -2115,8 +2099,9 @@ const CommonTestAndPreview = (props) => {
2115
2099
 
2116
2100
  // Helper function to build expandableDetails for iOS
2117
2101
  const buildIosExpandableDetails = (data) => {
2102
+ // Default style is BIG_TEXT, change to BIG_PICTURE if image exists
2118
2103
  const imageLinkIos = data.image;
2119
- const style = getMpushStyle(data);
2104
+ const style = imageLinkIos ? STYLE_TYPE_BIG_PICTURE : STYLE_TYPE_BIG_TEXT;
2120
2105
 
2121
2106
  const expandableDetails = {
2122
2107
  style,
@@ -2125,11 +2110,7 @@ const CommonTestAndPreview = (props) => {
2125
2110
  };
2126
2111
 
2127
2112
  // Add image if present (transform to CDN URL if needed)
2128
- if (hasCarousel(data)) {
2129
- addMpushCarousel(expandableDetails, data);
2130
- } else if (data.video) {
2131
- expandableDetails.media = toMpushVideoMedia(data.video);
2132
- } else if (imageLinkIos) {
2113
+ if (imageLinkIos) {
2133
2114
  expandableDetails.image = getCdnUrl({ url: imageLinkIos, channelName: CHANNEL_NAME_MOBILE_PUSH });
2134
2115
  }
2135
2116
 
@@ -2206,7 +2187,8 @@ const CommonTestAndPreview = (props) => {
2206
2187
  const androidExpandableDetails = buildAndroidExpandableDetails(androidData);
2207
2188
  const androidCustomProperties = buildCustomProperties(androidData);
2208
2189
 
2209
- const androidType = getMpushType(androidData);
2190
+ // Determine type based on image presence
2191
+ const androidType = androidData.image ? MEDIA_TYPE_IMAGE : MEDIA_TYPE_TEXT;
2210
2192
 
2211
2193
  const androidContent = {
2212
2194
  type: androidType,
@@ -2225,7 +2207,8 @@ const CommonTestAndPreview = (props) => {
2225
2207
  const iosExpandableDetails = buildIosExpandableDetails(iosData);
2226
2208
  const iosCustomProperties = buildCustomProperties(iosData);
2227
2209
 
2228
- const iosType = getMpushType(iosData);
2210
+ // Determine type based on image presence
2211
+ const iosType = iosData.image ? MEDIA_TYPE_IMAGE : MEDIA_TYPE_TEXT;
2229
2212
 
2230
2213
  const iosContent = {
2231
2214
  type: iosType,
@@ -2695,9 +2678,18 @@ const CommonTestAndPreview = (props) => {
2695
2678
  } else if (channel === CHANNELS.SMS) {
2696
2679
  // For SMS, content is the text message (string)
2697
2680
  // Use previewDataHtml only if preview call was made, otherwise use raw content
2698
- contentObj = hasPreviewCallBeenMade && previewDataHtml?.resolvedBody
2681
+ const smsPreviewText = hasPreviewCallBeenMade && previewDataHtml?.resolvedBody
2699
2682
  ? previewDataHtml.resolvedBody
2700
2683
  : getCurrentContent || '';
2684
+ contentObj = smsTraiDltEnabled
2685
+ ? resolveTagsInText(
2686
+ resolveDltSmsTemplate(smsPreviewText, {
2687
+ ...smsDltEditorVarMapped,
2688
+ ...dropBlankValues(previewTagValues),
2689
+ }),
2690
+ previewTagValues || {},
2691
+ )
2692
+ : smsPreviewText;
2701
2693
  } else if ([CHANNELS.WHATSAPP, CHANNELS.WEBPUSH].includes(channel)) {
2702
2694
  // For WhatsApp, content is an object with templateMsg, media, CTA, etc.
2703
2695
  // Content comes from WhatsApp component state, passed via content prop
@@ -3257,6 +3249,11 @@ const CommonTestAndPreview = (props) => {
3257
3249
  allRequiredTags.forEach((tag) => {
3258
3250
  requiredTagObj[tag?.fullPath] = '';
3259
3251
  });
3252
+ if (channel === CHANNELS.SMS && smsTraiDltEnabled) {
3253
+ appendDltSmsTagRows([], smsDltEditorVarMapped).forEach((tag) => {
3254
+ requiredTagObj[tag.name] = '';
3255
+ });
3256
+ }
3260
3257
  if (allTags.length > 0) {
3261
3258
  const payload = preparePreviewPayload(
3262
3259
  activeChannelForActions,
@@ -3270,7 +3267,7 @@ const CommonTestAndPreview = (props) => {
3270
3267
  actions.getPrefilledValuesRequested(payload);
3271
3268
  }
3272
3269
  }
3273
- }, [selectedCustomer, allTags.length, activeChannelForActions, activePreviewTab]);
3270
+ }, [selectedCustomer, allTags.length, channel, smsTraiDltEnabled, JSON.stringify(smsDltEditorVarMapped), activeChannelForActions, activePreviewTab]);
3274
3271
 
3275
3272
  /**
3276
3273
  * Update custom values with prefilled values from API
@@ -3592,6 +3589,9 @@ const CommonTestAndPreview = (props) => {
3592
3589
  if (channel === CHANNELS.SMS && !smsTemplateHasMustacheTags(smsEditorBody)) {
3593
3590
  smsTagSource = [];
3594
3591
  }
3592
+ if (channel === CHANNELS.SMS && smsTraiDltEnabled) {
3593
+ smsTagSource = appendDltSmsTagRows(smsTagSource, smsDltEditorVarMapped, smsEditorBody);
3594
+ }
3595
3595
  // Unmapped variables become fillable test values, like RCS.
3596
3596
  if (channel === CHANNELS.WHATSAPP) {
3597
3597
  smsTagSource = mergeSyntheticMustacheTags(smsTagSource, getWhatsappTagExtractionText(formData));
@@ -3605,7 +3605,7 @@ const CommonTestAndPreview = (props) => {
3605
3605
  setTagsExtracted(hasPersonalizationTags);
3606
3606
  setCustomValues((prev) => mergeCustomValuesWithTagKeys(prev, { required, optional }, { required: [], optional: [] }));
3607
3607
  // eslint-disable-next-line react-hooks/exhaustive-deps -- applyRcsSmsFallbackTagExtraction closes over latest extractedTags/smsFallbackExtractedTags/formData
3608
- }, [show, extractedTags, channel, formData, smsFallbackContent, smsFallbackExtractedTags, getCurrentContent, smsFallbackTextForTagExtraction]);
3608
+ }, [show, extractedTags, channel, formData, smsTraiDltEnabled, smsFallbackContent, smsFallbackExtractedTags, getCurrentContent, smsFallbackTextForTagExtraction]);
3609
3609
 
3610
3610
  /**
3611
3611
  * Get content to run tag extraction on (channel-specific).