@capillarytech/creatives-library 8.0.87-alpha.21 → 8.0.87-alpha.23
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/containers/Templates/constants.js +6 -0
- package/containers/Templates/index.js +44 -24
- package/package.json +1 -1
- package/services/api.js +22 -12
- package/services/tests/api.test.js +5 -1
- package/utils/commonUtils.js +64 -10
- package/utils/tests/commonUtil.test.js +108 -3
- package/utils/tests/transformerUtils.test.js +2127 -0
- package/utils/transformerUtils.js +42 -96
- package/v2Components/CapImageUpload/index.js +13 -10
- package/v2Components/CapVideoUpload/index.js +12 -9
- package/v2Components/CapWhatsappCTA/messages.js +4 -0
- package/v2Components/CapWhatsappCarouselButton/constant.js +56 -0
- package/v2Components/CapWhatsappCarouselButton/index.js +446 -0
- package/v2Components/CapWhatsappCarouselButton/index.scss +39 -0
- package/v2Components/CapWhatsappCarouselButton/tests/index.test.js +237 -0
- package/v2Components/FormBuilder/constants.js +8 -0
- package/v2Components/FormBuilder/index.js +2 -2
- package/v2Components/TemplatePreview/_templatePreview.scss +20 -0
- package/v2Components/TemplatePreview/assets/images/empty_image_preview.svg +4 -0
- package/v2Components/TemplatePreview/assets/images/empty_video_preview.svg +4 -0
- package/v2Components/TemplatePreview/index.js +160 -105
- package/v2Components/TemplatePreview/tests/__snapshots__/index.test.js.snap +6 -6
- package/v2Containers/Cap/tests/saga.test.js +90 -1
- package/v2Containers/CreativesContainer/SlideBoxContent.js +0 -6
- package/v2Containers/CreativesContainer/constants.js +8 -1
- package/v2Containers/CreativesContainer/index.js +102 -9
- package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +3 -0
- package/v2Containers/Email/index.js +0 -1
- package/v2Containers/EmailWrapper/components/EmailWrapperView.js +192 -0
- package/v2Containers/EmailWrapper/constants.js +11 -1
- package/v2Containers/EmailWrapper/hooks/useEmailWrapper.js +343 -0
- package/v2Containers/EmailWrapper/index.js +116 -300
- package/v2Containers/EmailWrapper/mockdata/mockdata.js +119 -0
- package/v2Containers/EmailWrapper/tests/EmailWrapperView.test.js +214 -0
- package/v2Containers/EmailWrapper/tests/index.test.js +101 -0
- package/v2Containers/EmailWrapper/tests/useEmailWrapper.test.js +601 -0
- package/v2Containers/MobilePush/Edit/index.js +0 -1
- package/v2Containers/MobilepushWrapper/index.js +1 -2
- package/v2Containers/Sms/Create/index.js +0 -1
- package/v2Containers/SmsWrapper/index.js +0 -2
- package/v2Containers/Templates/_templates.scss +47 -0
- package/v2Containers/Templates/index.js +55 -5
- package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +177 -156
- package/v2Containers/TemplatesV2/index.js +2 -2
- package/v2Containers/Whatsapp/constants.js +87 -1
- package/v2Containers/Whatsapp/index.js +715 -190
- package/v2Containers/Whatsapp/index.scss +52 -1
- package/v2Containers/Whatsapp/messages.js +38 -2
- package/v2Containers/Whatsapp/styles.scss +5 -0
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +27722 -90751
- package/v2Containers/Whatsapp/tests/__snapshots__/utils.test.js.snap +6 -0
- package/v2Containers/Whatsapp/tests/mockData.js +3 -7
- package/v2Containers/Whatsapp/tests/utils.test.js +178 -1
- package/v2Containers/Whatsapp/utils.js +52 -0
- package/v2Containers/Zalo/index.js +47 -15
- package/v2Containers/Zalo/index.scss +8 -0
- package/v2Containers/Zalo/messages.js +4 -0
- package/v2Containers/mockdata.js +2 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`Test utils test getWhatsappContent 1`] = `
|
|
4
4
|
Object {
|
|
5
|
+
"carouselData": Array [],
|
|
5
6
|
"charCount": 151,
|
|
6
7
|
"ctaData": Array [
|
|
7
8
|
Object {
|
|
@@ -31,6 +32,7 @@ Click {{unsubscribe}} to unsubscribe
|
|
|
31
32
|
|
|
32
33
|
exports[`Test utils test getWhatsappContent 2`] = `
|
|
33
34
|
Object {
|
|
35
|
+
"carouselData": Array [],
|
|
34
36
|
"charCount": 36,
|
|
35
37
|
"templateFooterPreview": "",
|
|
36
38
|
"templateHeaderPreview": "",
|
|
@@ -44,6 +46,7 @@ Object {
|
|
|
44
46
|
|
|
45
47
|
exports[`Test utils test getWhatsappContent 3`] = `
|
|
46
48
|
Object {
|
|
49
|
+
"carouselData": Array [],
|
|
47
50
|
"charCount": 151,
|
|
48
51
|
"ctaData": Array [
|
|
49
52
|
Object {
|
|
@@ -73,6 +76,7 @@ Click {{unsubscribe}} to unsubscribe
|
|
|
73
76
|
|
|
74
77
|
exports[`Test utils test getWhatsappContent 4`] = `
|
|
75
78
|
Object {
|
|
79
|
+
"carouselData": Array [],
|
|
76
80
|
"charCount": 151,
|
|
77
81
|
"ctaData": Array [
|
|
78
82
|
Object {
|
|
@@ -151,6 +155,7 @@ Click {{unsubscribe}} to unsubscribe
|
|
|
151
155
|
|
|
152
156
|
exports[`Test utils test getWhatsappContent 5`] = `
|
|
153
157
|
Object {
|
|
158
|
+
"carouselData": Array [],
|
|
154
159
|
"charCount": -1,
|
|
155
160
|
"templateFooterPreview": "",
|
|
156
161
|
"templateHeaderPreview": "",
|
|
@@ -164,6 +169,7 @@ Object {
|
|
|
164
169
|
|
|
165
170
|
exports[`Test utils test getWhatsappContent for preview 1`] = `
|
|
166
171
|
Object {
|
|
172
|
+
"carouselData": Array [],
|
|
167
173
|
"charCount": 151,
|
|
168
174
|
"ctaData": Array [
|
|
169
175
|
Object {
|
|
@@ -3,7 +3,7 @@ export const mockData = {
|
|
|
3
3
|
selectedWhatsappAccount: {
|
|
4
4
|
name: 'WhatsppTest',
|
|
5
5
|
sourceAccountIdentifier: 'AC41030cebba9e2f1ce37c78235da0ee18',
|
|
6
|
-
configs: {
|
|
6
|
+
configs: { },
|
|
7
7
|
hostName: 'twiliowhatsapptrans',
|
|
8
8
|
},
|
|
9
9
|
},
|
|
@@ -11,7 +11,7 @@ export const mockData = {
|
|
|
11
11
|
selectedWhatsappAccount: {
|
|
12
12
|
name: 'WhatsappAccount',
|
|
13
13
|
sourceAccountIdentifier: '107499611940863',
|
|
14
|
-
configs: {
|
|
14
|
+
configs: { },
|
|
15
15
|
hostName: 'karixwhatsappbulk',
|
|
16
16
|
},
|
|
17
17
|
},
|
|
@@ -24,7 +24,7 @@ export const mockData = {
|
|
|
24
24
|
selectedWhatsappAccount: {
|
|
25
25
|
name: 'gupshup_test',
|
|
26
26
|
sourceAccountIdentifier: '2000222347',
|
|
27
|
-
configs: {
|
|
27
|
+
configs: { },
|
|
28
28
|
hostName: 'gupshupwhatsappbulk',
|
|
29
29
|
},
|
|
30
30
|
},
|
|
@@ -41,7 +41,6 @@ export const mockData = {
|
|
|
41
41
|
status: 'approved',
|
|
42
42
|
templateId: 'HT9bb4d61eea1699d2dbcaecd1cb558345',
|
|
43
43
|
accountName: 'WhatsppTest',
|
|
44
|
-
accessToken: '4676323eb5d1f975b0987070c03a8efc',
|
|
45
44
|
accountId: 'AC41030cebba9e2f1ce37c78235da0ee18',
|
|
46
45
|
mediaType: 'text',
|
|
47
46
|
languages: [
|
|
@@ -97,7 +96,6 @@ export const mockData = {
|
|
|
97
96
|
status: 'rejected',
|
|
98
97
|
templateId: 'HT9bb4d61eea1699d2dbcaecd1cb558345',
|
|
99
98
|
accountName: 'WhatsppTest',
|
|
100
|
-
accessToken: '4676323eb5d1f975b0987070c03a8efc',
|
|
101
99
|
accountId: 'AC41030cebba9e2f1ce37c78235da0ee18',
|
|
102
100
|
mediaType: 'text',
|
|
103
101
|
languages: [
|
|
@@ -136,7 +134,6 @@ export const mockData = {
|
|
|
136
134
|
status: 'rejected',
|
|
137
135
|
templateId: 'HT9bb4d61eea1699d2dbcaecd1cb558345',
|
|
138
136
|
accountName: 'WhatsppTest',
|
|
139
|
-
accessToken: '4676323eb5d1f975b0987070c03a8efc',
|
|
140
137
|
accountId: 'AC41030cebba9e2f1ce37c78235da0ee18',
|
|
141
138
|
mediaType: 'text',
|
|
142
139
|
languages: [
|
|
@@ -277,7 +274,6 @@ export const mockData = {
|
|
|
277
274
|
varMapped: {},
|
|
278
275
|
templateEditor: false,
|
|
279
276
|
accountId: '123456789',
|
|
280
|
-
accessToken: '12345',
|
|
281
277
|
hostName: 'karixwhatsappbulk',
|
|
282
278
|
whatsappMedia: {
|
|
283
279
|
header: '',
|
|
@@ -7,9 +7,11 @@ import {
|
|
|
7
7
|
getWhatsappDocPreview,
|
|
8
8
|
getWhatsappQuickReply,
|
|
9
9
|
getWhatsappAutoFill,
|
|
10
|
+
getWhatsappCarouselButtonView,
|
|
10
11
|
} from '../utils';
|
|
11
12
|
import mockdata from '../../mockdata';
|
|
12
|
-
import { HOST_ICS } from '../constants';
|
|
13
|
+
import { HOST_ICS, PHONE_NUMBER, QUICK_REPLY } from '../constants';
|
|
14
|
+
import { WHATSAPP_MEDIA_TYPES } from '../../Whatsapp/constants';
|
|
13
15
|
|
|
14
16
|
const {
|
|
15
17
|
whatsappPreviewTemplateData,
|
|
@@ -100,4 +102,179 @@ describe('Test utils', () => {
|
|
|
100
102
|
JSON.stringify(getWhatsappDocPreviewOutput1),
|
|
101
103
|
);
|
|
102
104
|
});
|
|
105
|
+
|
|
106
|
+
describe('test getWhatsappCarouselButtonView', () => {
|
|
107
|
+
it('should return empty array for null/undefined/empty input', () => {
|
|
108
|
+
expect(getWhatsappCarouselButtonView(null)).toEqual([]);
|
|
109
|
+
expect(getWhatsappCarouselButtonView(undefined)).toEqual([]);
|
|
110
|
+
expect(getWhatsappCarouselButtonView([])).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should render single button correctly', () => {
|
|
114
|
+
const singleButton = [{
|
|
115
|
+
text: 'Click Me',
|
|
116
|
+
buttonType: 'URL'
|
|
117
|
+
}];
|
|
118
|
+
|
|
119
|
+
const result = getWhatsappCarouselButtonView(singleButton);
|
|
120
|
+
expect(result).toHaveLength(2); // 1 divider + 1 button
|
|
121
|
+
expect(result[0].props.className).toBe('whatsapp-list-view-divider'); // Divider
|
|
122
|
+
expect(result[1].props.children[1]).toBe('Click Me'); // Button text
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should render multiple buttons with dividers', () => {
|
|
126
|
+
const multipleButtons = [
|
|
127
|
+
{ text: 'Call Us', type: PHONE_NUMBER },
|
|
128
|
+
{ text: 'Reply', type: QUICK_REPLY },
|
|
129
|
+
{ text: 'Visit Website', buttonType: 'URL' }
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
const result = getWhatsappCarouselButtonView(multipleButtons);
|
|
133
|
+
expect(result).toHaveLength(6); // Initial divider + 3 buttons + 2 intermediate dividers
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should handle template preview mode correctly', () => {
|
|
137
|
+
const buttons = [{
|
|
138
|
+
text: 'Click Me',
|
|
139
|
+
buttonType: 'URL'
|
|
140
|
+
}];
|
|
141
|
+
|
|
142
|
+
const result = getWhatsappCarouselButtonView(buttons, true);
|
|
143
|
+
expect(result[0].props.className).toBe('whatsapp-divider'); // Check preview mode divider class
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should handle buttons without text properly', () => {
|
|
147
|
+
const buttons = [
|
|
148
|
+
{ buttonType: 'URL' },
|
|
149
|
+
{ text: 'Valid Button', buttonType: 'URL' }
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
const result = getWhatsappCarouselButtonView(buttons);
|
|
153
|
+
expect(result).toHaveLength(3); // Initial divider + 1 valid button + 1 divider
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should use correct icons based on button type', () => {
|
|
157
|
+
const buttons = [
|
|
158
|
+
{ text: 'Call Now', type: PHONE_NUMBER },
|
|
159
|
+
{ text: 'Quick Reply', type: QUICK_REPLY },
|
|
160
|
+
{ text: 'Visit Site', buttonType: 'URL' }
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
const result = getWhatsappCarouselButtonView(buttons);
|
|
164
|
+
|
|
165
|
+
// Check icon types
|
|
166
|
+
expect(result[1].props.children[0].props.type).toBe('call'); // Phone number icon
|
|
167
|
+
expect(result[3].props.children[0].props.type).toBe('small-link'); // Quick reply icon
|
|
168
|
+
expect(result[5].props.children[0].props.type).toBe('launch'); // URL icon
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('should handle both type and buttonType properties', () => {
|
|
172
|
+
const buttons = [
|
|
173
|
+
{ text: 'Button 1', type: PHONE_NUMBER },
|
|
174
|
+
{ text: 'Button 2', buttonType: PHONE_NUMBER }
|
|
175
|
+
];
|
|
176
|
+
|
|
177
|
+
const result = getWhatsappCarouselButtonView(buttons);
|
|
178
|
+
// Both buttons should have call icons
|
|
179
|
+
expect(result[1].props.children[0].props.type).toBe('call');
|
|
180
|
+
expect(result[3].props.children[0].props.type).toBe('call');
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('carousel functionality', () => {
|
|
185
|
+
const mockTemplate = {
|
|
186
|
+
versions: {
|
|
187
|
+
base: {
|
|
188
|
+
content: {
|
|
189
|
+
whatsapp: {
|
|
190
|
+
languages: [{ content: 'Test message' }],
|
|
191
|
+
carouselData: [
|
|
192
|
+
{
|
|
193
|
+
mediaType: 'image',
|
|
194
|
+
imageUrl: 'https://example.com/image.jpg',
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
mediaType: 'video',
|
|
198
|
+
videoUrl: 'https://example.com/video.mp4',
|
|
199
|
+
videoPreviewImg: 'https://example.com/preview.jpg',
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
it('should return original carousel data when isPreview is false', () => {
|
|
209
|
+
const result = getWhatsappContent(mockTemplate, false);
|
|
210
|
+
expect(result.carouselData).toEqual([
|
|
211
|
+
{
|
|
212
|
+
mediaType: 'image',
|
|
213
|
+
imageUrl: 'https://example.com/image.jpg',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
mediaType: 'video',
|
|
217
|
+
videoUrl: 'https://example.com/video.mp4',
|
|
218
|
+
videoPreviewImg: 'https://example.com/preview.jpg',
|
|
219
|
+
},
|
|
220
|
+
]);
|
|
221
|
+
expect(result.carouselMediaType).toBeUndefined();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should transform carousel data correctly when isPreview is true', () => {
|
|
225
|
+
const result = getWhatsappContent(mockTemplate, true);
|
|
226
|
+
|
|
227
|
+
expect(result.carouselData).toEqual([
|
|
228
|
+
{
|
|
229
|
+
mediaType: 'image',
|
|
230
|
+
imageUrl: 'https://example.com/image.jpg',
|
|
231
|
+
imageSrc: 'https://example.com/image.jpg',
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
mediaType: 'video',
|
|
235
|
+
videoUrl: 'https://example.com/video.mp4',
|
|
236
|
+
videoPreviewImg: 'https://example.com/preview.jpg',
|
|
237
|
+
videoSrc: 'https://example.com/video.mp4',
|
|
238
|
+
},
|
|
239
|
+
]);
|
|
240
|
+
expect(result.carouselMediaType).toBe('image');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('should handle empty carousel data', () => {
|
|
244
|
+
const emptyTemplate = {
|
|
245
|
+
versions: {
|
|
246
|
+
base: {
|
|
247
|
+
content: {
|
|
248
|
+
whatsapp: {
|
|
249
|
+
languages: [{ content: 'Test message' }],
|
|
250
|
+
carouselData: [],
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const result = getWhatsappContent(emptyTemplate, true);
|
|
258
|
+
expect(result.carouselData).toEqual([]);
|
|
259
|
+
expect(result.carouselMediaType).toBeUndefined();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('should handle undefined carousel data', () => {
|
|
263
|
+
const undefinedTemplate = {
|
|
264
|
+
versions: {
|
|
265
|
+
base: {
|
|
266
|
+
content: {
|
|
267
|
+
whatsapp: {
|
|
268
|
+
languages: [{ content: 'Test message' }],
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const result = getWhatsappContent(undefinedTemplate, true);
|
|
276
|
+
expect(result.carouselData).toEqual([]);
|
|
277
|
+
expect(result.carouselMediaType).toBeUndefined();
|
|
278
|
+
});
|
|
279
|
+
});
|
|
103
280
|
});
|
|
@@ -80,6 +80,7 @@ export const getWhatsappContent = (template, isPreview) => {
|
|
|
80
80
|
header = '',
|
|
81
81
|
footer = '',
|
|
82
82
|
} = {},
|
|
83
|
+
carouselData = [],
|
|
83
84
|
} = {},
|
|
84
85
|
} = {},
|
|
85
86
|
} = {},
|
|
@@ -113,6 +114,22 @@ export const getWhatsappContent = (template, isPreview) => {
|
|
|
113
114
|
break;
|
|
114
115
|
}
|
|
115
116
|
|
|
117
|
+
const getCarouselData = () => {
|
|
118
|
+
if (isPreview && carouselData?.length) {
|
|
119
|
+
return carouselData.map((carousel) => {
|
|
120
|
+
if (carousel?.mediaType === WHATSAPP_MEDIA_TYPES.IMAGE.toLowerCase()) {
|
|
121
|
+
carousel.imageSrc = carousel?.imageUrl;
|
|
122
|
+
}
|
|
123
|
+
if (carousel?.mediaType === WHATSAPP_MEDIA_TYPES.VIDEO.toLowerCase()) {
|
|
124
|
+
carousel.videoSrc = carousel?.videoUrl;
|
|
125
|
+
carousel.videoPreviewImg = carousel?.videoPreviewImg;
|
|
126
|
+
}
|
|
127
|
+
return carousel;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return carouselData;
|
|
131
|
+
};
|
|
132
|
+
|
|
116
133
|
return {
|
|
117
134
|
templateHeaderPreview: header ? <CapLabel className="whatsapp-template-list-header-preview">{header}</CapLabel> : '',
|
|
118
135
|
templateFooterPreview: footer ? <CapLabel className="whatsapp-template-list-footer-preview">{footer}</CapLabel> : '',
|
|
@@ -125,6 +142,10 @@ export const getWhatsappContent = (template, isPreview) => {
|
|
|
125
142
|
quickReplyData: buttonsData
|
|
126
143
|
}),
|
|
127
144
|
...mediaParams,
|
|
145
|
+
carouselData: getCarouselData(),
|
|
146
|
+
...(isPreview && carouselData?.length && {
|
|
147
|
+
carouselMediaType: carouselData[0]?.mediaType,
|
|
148
|
+
}),
|
|
128
149
|
};
|
|
129
150
|
};
|
|
130
151
|
|
|
@@ -188,6 +209,37 @@ export const getWhatsappQuickReply= (template, templatePreview) => {
|
|
|
188
209
|
}
|
|
189
210
|
return renderArray;
|
|
190
211
|
}
|
|
212
|
+
|
|
213
|
+
export const getWhatsappCarouselButtonView = (buttons, templatePreview) => {
|
|
214
|
+
const renderArray = [];
|
|
215
|
+
if (buttons?.length) {
|
|
216
|
+
renderArray.push(<CapDivider className={templatePreview ? "whatsapp-divider" : "whatsapp-list-view-divider"} />);
|
|
217
|
+
buttons.forEach((button, index) => {
|
|
218
|
+
const { text, buttonType, type } = button || {};
|
|
219
|
+
const currentButtonType = type || buttonType;
|
|
220
|
+
if (text) {
|
|
221
|
+
renderArray.push(
|
|
222
|
+
<CapLabel
|
|
223
|
+
type="label21"
|
|
224
|
+
className="whatsapp-list-view-text-align"
|
|
225
|
+
>
|
|
226
|
+
<CapIcon
|
|
227
|
+
type={currentButtonType === PHONE_NUMBER ? 'call' : currentButtonType === QUICK_REPLY ? "small-link" : 'launch'}
|
|
228
|
+
size="xs"
|
|
229
|
+
svgProps={{ style: { marginRight: '4px' } }}
|
|
230
|
+
/>
|
|
231
|
+
{text}
|
|
232
|
+
</CapLabel>,
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
if (index < buttons?.length - 1) {
|
|
236
|
+
renderArray.push(<CapDivider className={templatePreview ? "whatsapp-divider" : "whatsapp-list-view-divider"} />);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return renderArray;
|
|
241
|
+
};
|
|
242
|
+
|
|
191
243
|
export const getWhatsappAutoFill = (template) => {
|
|
192
244
|
const {category}= get(
|
|
193
245
|
template,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import React, { useState, useEffect } from 'react';
|
|
4
4
|
import { bindActionCreators } from 'redux';
|
|
5
5
|
import { createStructuredSelector } from 'reselect';
|
|
6
|
-
import {
|
|
6
|
+
import { FormattedMessage } from 'react-intl';
|
|
7
7
|
import { get, isEmpty } from 'lodash';
|
|
8
8
|
import styled from 'styled-components';
|
|
9
9
|
import CapSpin from '@capillarytech/cap-ui-library/CapSpin';
|
|
@@ -53,6 +53,8 @@ import injectReducer from '../../utils/injectReducer';
|
|
|
53
53
|
import * as globalActions from '../Cap/actions';
|
|
54
54
|
import v2ZaloReducer from './reducer';
|
|
55
55
|
import { v2ZaloSagas } from './saga';
|
|
56
|
+
import { CapIcon } from '@capillarytech/cap-ui-library';
|
|
57
|
+
import { isTagIncluded } from '../../utils/commonUtils';
|
|
56
58
|
|
|
57
59
|
export const Zalo = (props) => {
|
|
58
60
|
const {
|
|
@@ -233,11 +235,11 @@ export const Zalo = (props) => {
|
|
|
233
235
|
const onTagSelect = (data) => {
|
|
234
236
|
if (data && textAreaId) {
|
|
235
237
|
const updatedZaloTemplateInfo = templateListParams?.map((listParams) => {
|
|
236
|
-
const { name = '', value = '', minLength, maxLength } = listParams;
|
|
238
|
+
const { name = '', value = '', minLength = '', maxLength = '' } = listParams;
|
|
237
239
|
if (name === textAreaId) {
|
|
238
240
|
const text = `${value}{{${data}}}`;
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
+
const hasTag = isTagIncluded(text);
|
|
242
|
+
const isLengthError = !hasTag && (text.length <= minLength || text.length > maxLength);
|
|
241
243
|
return {
|
|
242
244
|
...listParams,
|
|
243
245
|
value: text,
|
|
@@ -280,9 +282,12 @@ export const Zalo = (props) => {
|
|
|
280
282
|
|
|
281
283
|
//this function is used for checking errror validation in this it validate tags error and length error
|
|
282
284
|
const handleErrorValidation = (e, field) => {
|
|
283
|
-
const { minLength, maxLength } = field;
|
|
285
|
+
const { minLength = '', maxLength = '' } = field;
|
|
284
286
|
let error = e ? tagValidationErrorMessage(e) : '';
|
|
285
|
-
|
|
287
|
+
|
|
288
|
+
// Only check length validation if there are no tags in the content
|
|
289
|
+
const hasTag = isTagIncluded(e);
|
|
290
|
+
if (!hasTag && (!e || e.length <= minLength || e.length > maxLength)) {
|
|
286
291
|
error = formatMessage(messages.maxMinLengthMessage, {
|
|
287
292
|
minLength,
|
|
288
293
|
maxLength,
|
|
@@ -311,7 +316,7 @@ export const Zalo = (props) => {
|
|
|
311
316
|
};
|
|
312
317
|
|
|
313
318
|
const renderTextBoxesForListParams = (listParam) => {
|
|
314
|
-
const { name, error, value } = listParam;
|
|
319
|
+
const { name = '', error = '', value = '' } = listParam;
|
|
315
320
|
return (
|
|
316
321
|
<CapInput
|
|
317
322
|
id={`zalo-${name}`}
|
|
@@ -351,8 +356,9 @@ export const Zalo = (props) => {
|
|
|
351
356
|
const isEditDoneDisabled = () => {
|
|
352
357
|
let disableCheck = false;
|
|
353
358
|
templateListParams?.forEach((listParams) => {
|
|
354
|
-
const { error, value } = listParams;
|
|
355
|
-
const
|
|
359
|
+
const { error = '', value = '' } = listParams;
|
|
360
|
+
const hasTag = isTagIncluded(value);
|
|
361
|
+
const errorMessage = !error && !hasTag
|
|
356
362
|
? handleErrorValidation(value, listParams)
|
|
357
363
|
: error;
|
|
358
364
|
if (errorMessage) {
|
|
@@ -397,7 +403,9 @@ export const Zalo = (props) => {
|
|
|
397
403
|
|
|
398
404
|
const renderContent = () =>
|
|
399
405
|
templateListParams?.map((listParam) => {
|
|
400
|
-
const { name = '', value = '', maxLength } = listParam;
|
|
406
|
+
const { name = '', value = '', maxLength = '' } = listParam;
|
|
407
|
+
const hasTag = isTagIncluded(value);
|
|
408
|
+
|
|
401
409
|
return (
|
|
402
410
|
<>
|
|
403
411
|
{renderTextBoxesForListParams(listParam)}
|
|
@@ -408,16 +416,24 @@ export const Zalo = (props) => {
|
|
|
408
416
|
})}
|
|
409
417
|
</CapLabel>
|
|
410
418
|
<CapLabel className="variable-field-length">
|
|
411
|
-
{
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
419
|
+
{!hasTag && (
|
|
420
|
+
formatMessage(messages.charactersCount, {
|
|
421
|
+
variableLength: value.length,
|
|
422
|
+
maxLength,
|
|
423
|
+
})
|
|
424
|
+
)}
|
|
415
425
|
</CapLabel>
|
|
416
426
|
</CapRow>
|
|
417
427
|
</>
|
|
418
428
|
);
|
|
419
429
|
});
|
|
420
430
|
|
|
431
|
+
const hasTag = templateListParams?.some((listParam) => {
|
|
432
|
+
const { value = '' } = listParam;
|
|
433
|
+
const isTagAvailable = isTagIncluded(value);
|
|
434
|
+
return isTagAvailable;
|
|
435
|
+
});
|
|
436
|
+
|
|
421
437
|
return (
|
|
422
438
|
<CapSpin spinning={zaloTemplateInfoStatus === REQUEST}>
|
|
423
439
|
<CapRow type="flex" className="cap-zalo-creatives">
|
|
@@ -458,7 +474,23 @@ export const Zalo = (props) => {
|
|
|
458
474
|
}
|
|
459
475
|
/>
|
|
460
476
|
</CapRow>
|
|
461
|
-
<CapRow className="zalo-variable-list">
|
|
477
|
+
<CapRow className="zalo-variable-list">
|
|
478
|
+
{renderContent()}
|
|
479
|
+
{
|
|
480
|
+
hasTag && (
|
|
481
|
+
<CapAlert
|
|
482
|
+
message={
|
|
483
|
+
<CapLabel type="label2">
|
|
484
|
+
<CapIcon type="warning" className="alert-icon-zalo" />
|
|
485
|
+
{formatMessage(messages.tagLengthWarning)}
|
|
486
|
+
</CapLabel>
|
|
487
|
+
}
|
|
488
|
+
type="warning"
|
|
489
|
+
className="zalo-warning-message"
|
|
490
|
+
/>
|
|
491
|
+
)
|
|
492
|
+
}
|
|
493
|
+
</CapRow>
|
|
462
494
|
</CapRow>
|
|
463
495
|
</CapColumn>
|
|
464
496
|
<CapColumn span={10}>
|
|
@@ -83,4 +83,8 @@ export default defineMessages({
|
|
|
83
83
|
id: `${prefix}.btnDisabledTooltip`,
|
|
84
84
|
defaultMessage: 'Please add all mandatory fields to proceed further',
|
|
85
85
|
},
|
|
86
|
+
tagLengthWarning: {
|
|
87
|
+
id: `${prefix}.tagLengthWarning`,
|
|
88
|
+
defaultMessage: "If the resolved tag values in the variables exceed their character count limit, the message will fail to go out.",
|
|
89
|
+
},
|
|
86
90
|
});
|
package/v2Containers/mockdata.js
CHANGED
|
@@ -1592,6 +1592,7 @@ export default {
|
|
|
1592
1592
|
totalCount: 7,
|
|
1593
1593
|
},
|
|
1594
1594
|
whatsappPreviewTemplateData3Result: {
|
|
1595
|
+
carouselData: [],
|
|
1595
1596
|
quickReplyData: [
|
|
1596
1597
|
{
|
|
1597
1598
|
index: 0,
|
|
@@ -2598,3 +2599,4 @@ export default {
|
|
|
2598
2599
|
/>
|
|
2599
2600
|
</CapLabel>,
|
|
2600
2601
|
};
|
|
2602
|
+
|