@capillarytech/creatives-library 9.0.53-alpha.3 → 9.0.54-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.
- package/.vscode/settings.json +3 -0
- package/constants/unified.js +1 -0
- package/package.json +1 -1
- package/services/api.js +0 -9
- package/utils/common.js +4 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/ViberCarouselPreviewCards.js +127 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/ViberPreviewContent.js +106 -15
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +139 -1
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_viberCarouselPreviewCards.scss +133 -0
- package/v2Components/CommonTestAndPreview/constants.js +2 -0
- package/v2Components/CommonTestAndPreview/index.js +243 -26
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/ViberPreviewContent.test.js +364 -0
- package/v2Components/CommonTestAndPreview/tests/utils.test.js +49 -0
- package/v2Components/CommonTestAndPreview/utils.js +20 -0
- package/v2Containers/CommunicationFlow/CommunicationFlow.js +58 -93
- package/v2Containers/CommunicationFlow/CommunicationFlowCard.js +4 -20
- package/v2Containers/CommunicationFlow/Tests/CommunicationFlow.test.js +49 -194
- package/v2Containers/CommunicationFlow/Tests/CommunicationFlowCard.test.js +0 -16
- package/v2Containers/CommunicationFlow/constants.js +0 -47
- package/v2Containers/CommunicationFlow/index.js +20 -15
- package/v2Containers/CommunicationFlow/messages.js +0 -4
- package/v2Containers/CreativesContainer/index.js +2 -0
- package/v2Containers/Rcs/constants.js +1 -0
- package/v2Containers/Rcs/index.js +9 -1
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +108 -0
- package/v2Containers/Rcs/tests/index.test.js +121 -0
- package/v2Containers/Templates/_templates.scss +179 -1
- package/v2Containers/Templates/index.js +120 -10
- package/v2Containers/Viber/constants.js +23 -0
- package/v2Containers/Viber/index.js +718 -43
- package/v2Containers/Viber/index.scss +175 -0
- package/v2Containers/Viber/messages.js +121 -0
- package/v2Containers/Viber/tests/index.test.js +80 -0
|
@@ -200,6 +200,370 @@ describe('ViberPreviewContent', () => {
|
|
|
200
200
|
|
|
201
201
|
expect(screen.getByText('Click Here')).toBeTruthy();
|
|
202
202
|
});
|
|
203
|
+
|
|
204
|
+
it('should not render button when buttonText has only whitespace', () => {
|
|
205
|
+
const props = {
|
|
206
|
+
...defaultProps,
|
|
207
|
+
content: {
|
|
208
|
+
viberPreviewContent: {
|
|
209
|
+
messageContent: 'Message',
|
|
210
|
+
buttonText: ' ',
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const { container } = render(
|
|
216
|
+
<TestWrapper>
|
|
217
|
+
<ComponentToRender {...props} />
|
|
218
|
+
</TestWrapper>
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
expect(container.querySelector('.viber-button-base')).toBeFalsy();
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe('Carousel Content', () => {
|
|
226
|
+
it('should render no content when carousel is selected but cards are empty', () => {
|
|
227
|
+
const props = {
|
|
228
|
+
...defaultProps,
|
|
229
|
+
content: {
|
|
230
|
+
viberPreviewContent: {
|
|
231
|
+
type: 'CAROUSEL',
|
|
232
|
+
cards: [
|
|
233
|
+
{
|
|
234
|
+
text: '',
|
|
235
|
+
mediaUrl: '',
|
|
236
|
+
buttons: [
|
|
237
|
+
{ title: '', action: '' },
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
text: ' ',
|
|
242
|
+
mediaUrl: ' ',
|
|
243
|
+
buttons: [
|
|
244
|
+
{ title: ' ', action: 'https://example.com/2' },
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
render(
|
|
253
|
+
<TestWrapper>
|
|
254
|
+
<ComponentToRender {...props} />
|
|
255
|
+
</TestWrapper>
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
expect(screen.getByText('No content available')).toBeTruthy();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('should render carousel cards when type is CAROUSEL', () => {
|
|
262
|
+
const props = {
|
|
263
|
+
...defaultProps,
|
|
264
|
+
content: {
|
|
265
|
+
viberPreviewContent: {
|
|
266
|
+
type: 'CAROUSEL',
|
|
267
|
+
cards: [
|
|
268
|
+
{
|
|
269
|
+
text: 'Card 1 text',
|
|
270
|
+
mediaUrl: 'https://image.url/card1.jpg',
|
|
271
|
+
buttons: [
|
|
272
|
+
{ title: 'Button 1', action: 'https://example.com/1' },
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
text: 'Card 2 text',
|
|
277
|
+
mediaUrl: 'https://image.url/card2.jpg',
|
|
278
|
+
buttons: [
|
|
279
|
+
{ title: 'Button 2', action: 'https://example.com/2' },
|
|
280
|
+
],
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
render(
|
|
288
|
+
<TestWrapper>
|
|
289
|
+
<ComponentToRender {...props} />
|
|
290
|
+
</TestWrapper>
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
expect(screen.getByText('Card 1 text')).toBeTruthy();
|
|
294
|
+
expect(screen.getByText('Card 2 text')).toBeTruthy();
|
|
295
|
+
expect(screen.getByText('Button 1')).toBeTruthy();
|
|
296
|
+
expect(screen.getByText('Button 2')).toBeTruthy();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('should not render empty carousel button placeholder', () => {
|
|
300
|
+
const props = {
|
|
301
|
+
...defaultProps,
|
|
302
|
+
content: {
|
|
303
|
+
viberPreviewContent: {
|
|
304
|
+
type: 'CAROUSEL',
|
|
305
|
+
cards: [
|
|
306
|
+
{
|
|
307
|
+
text: 'Card 1 text',
|
|
308
|
+
mediaUrl: 'https://image.url/card1.jpg',
|
|
309
|
+
buttons: [
|
|
310
|
+
{ title: '', action: 'https://example.com/1' },
|
|
311
|
+
{ title: ' ', action: 'https://example.com/2' },
|
|
312
|
+
],
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const { container } = render(
|
|
320
|
+
<TestWrapper>
|
|
321
|
+
<ComponentToRender {...props} />
|
|
322
|
+
</TestWrapper>
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
expect(container.querySelector('.viber-carousel-preview .button')).toBeNull();
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('should show carousel shell when showCarouselEditorPreview is true even if cards are empty', () => {
|
|
329
|
+
const props = {
|
|
330
|
+
...defaultProps,
|
|
331
|
+
content: {
|
|
332
|
+
viberPreviewContent: {
|
|
333
|
+
type: 'CAROUSEL',
|
|
334
|
+
showCarouselEditorPreview: true,
|
|
335
|
+
cards: [
|
|
336
|
+
{ text: '', mediaUrl: '', buttons: [{ title: '', action: '' }] },
|
|
337
|
+
{ text: '', mediaUrl: '', buttons: [{ title: '', action: '' }] },
|
|
338
|
+
],
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const { container } = render(
|
|
344
|
+
<TestWrapper>
|
|
345
|
+
<ComponentToRender {...props} />
|
|
346
|
+
</TestWrapper>
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
expect(screen.queryByText('No content available')).toBeNull();
|
|
350
|
+
expect(container.querySelector('.viber-carousel-preview .scroll')).toBeTruthy();
|
|
351
|
+
expect(container.querySelector('.viber-carousel-message-box-placeholder')).toBeTruthy();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('should render carousel message text in message box when type is CAROUSEL', () => {
|
|
355
|
+
const props = {
|
|
356
|
+
...defaultProps,
|
|
357
|
+
content: {
|
|
358
|
+
viberPreviewContent: {
|
|
359
|
+
type: 'CAROUSEL',
|
|
360
|
+
messageContent: 'Carousel intro copy',
|
|
361
|
+
cards: [
|
|
362
|
+
{
|
|
363
|
+
text: 'Card text',
|
|
364
|
+
mediaUrl: 'https://image.url/c.jpg',
|
|
365
|
+
buttons: [{ title: 'Go', action: 'https://example.com' }],
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const { container } = render(
|
|
373
|
+
<TestWrapper>
|
|
374
|
+
<ComponentToRender {...props} />
|
|
375
|
+
</TestWrapper>
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
expect(container.querySelector('.viber-carousel-message-box-text')).toHaveTextContent('Carousel intro copy');
|
|
379
|
+
expect(screen.queryByText('Carousel intro copy')).toBeTruthy();
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('should hide account icon when carousel is shown', () => {
|
|
383
|
+
const props = {
|
|
384
|
+
...defaultProps,
|
|
385
|
+
content: {
|
|
386
|
+
viberPreviewContent: {
|
|
387
|
+
type: 'CAROUSEL',
|
|
388
|
+
cards: [
|
|
389
|
+
{
|
|
390
|
+
text: 'Carousel card line',
|
|
391
|
+
mediaUrl: '',
|
|
392
|
+
buttons: [{ title: 'Open link', action: 'https://x.com' }],
|
|
393
|
+
},
|
|
394
|
+
],
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
const { container } = render(
|
|
400
|
+
<TestWrapper>
|
|
401
|
+
<ComponentToRender {...props} />
|
|
402
|
+
</TestWrapper>
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
expect(container.querySelector('.viber-account-icon')).toBeNull();
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it('should use image placeholder when carousel card mediaUrl is whitespace only', () => {
|
|
409
|
+
const props = {
|
|
410
|
+
...defaultProps,
|
|
411
|
+
content: {
|
|
412
|
+
viberPreviewContent: {
|
|
413
|
+
type: 'CAROUSEL',
|
|
414
|
+
cards: [
|
|
415
|
+
{
|
|
416
|
+
text: 'Only text',
|
|
417
|
+
mediaUrl: ' ',
|
|
418
|
+
buttons: [{ title: 'Btn', action: 'https://example.com' }],
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const { container } = render(
|
|
426
|
+
<TestWrapper>
|
|
427
|
+
<ComponentToRender {...props} />
|
|
428
|
+
</TestWrapper>
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
expect(container.querySelector('.viber-carousel-preview .image-placeholder')).toBeTruthy();
|
|
432
|
+
expect(container.querySelector('.viber-carousel-preview .image')).toBeNull();
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('should render at most two carousel buttons per card', () => {
|
|
436
|
+
const props = {
|
|
437
|
+
...defaultProps,
|
|
438
|
+
content: {
|
|
439
|
+
viberPreviewContent: {
|
|
440
|
+
type: 'CAROUSEL',
|
|
441
|
+
cards: [
|
|
442
|
+
{
|
|
443
|
+
text: 'Card',
|
|
444
|
+
mediaUrl: 'https://image.url/c.jpg',
|
|
445
|
+
buttons: [
|
|
446
|
+
{ title: 'One', action: 'https://a.com' },
|
|
447
|
+
{ title: 'Two', action: 'https://b.com' },
|
|
448
|
+
{ title: 'Three', action: 'https://c.com' },
|
|
449
|
+
],
|
|
450
|
+
},
|
|
451
|
+
],
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const { container } = render(
|
|
457
|
+
<TestWrapper>
|
|
458
|
+
<ComponentToRender {...props} />
|
|
459
|
+
</TestWrapper>
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
expect(container.querySelectorAll('.viber-carousel-preview .button')).toHaveLength(2);
|
|
463
|
+
expect(screen.getByText('One')).toBeTruthy();
|
|
464
|
+
expect(screen.getByText('Two')).toBeTruthy();
|
|
465
|
+
expect(screen.queryByText('Three')).toBeNull();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('should apply secondary class to second carousel button', () => {
|
|
469
|
+
const props = {
|
|
470
|
+
...defaultProps,
|
|
471
|
+
content: {
|
|
472
|
+
viberPreviewContent: {
|
|
473
|
+
type: 'CAROUSEL',
|
|
474
|
+
cards: [
|
|
475
|
+
{
|
|
476
|
+
text: 'Card',
|
|
477
|
+
mediaUrl: 'https://image.url/c.jpg',
|
|
478
|
+
buttons: [
|
|
479
|
+
{ title: 'Primary', action: 'https://a.com' },
|
|
480
|
+
{ title: 'Secondary', action: 'https://b.com' },
|
|
481
|
+
],
|
|
482
|
+
},
|
|
483
|
+
],
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const { container } = render(
|
|
489
|
+
<TestWrapper>
|
|
490
|
+
<ComponentToRender {...props} />
|
|
491
|
+
</TestWrapper>
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
const buttons = container.querySelectorAll('.viber-carousel-preview .button');
|
|
495
|
+
expect(buttons[0].className).toContain('button');
|
|
496
|
+
expect(buttons[0].className).not.toContain('button-secondary');
|
|
497
|
+
expect(buttons[1].className).toContain('button-secondary');
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it('should show carousel when only a button title is present on a card', () => {
|
|
501
|
+
const props = {
|
|
502
|
+
...defaultProps,
|
|
503
|
+
content: {
|
|
504
|
+
viberPreviewContent: {
|
|
505
|
+
type: 'CAROUSEL',
|
|
506
|
+
cards: [
|
|
507
|
+
{
|
|
508
|
+
text: '',
|
|
509
|
+
mediaUrl: '',
|
|
510
|
+
buttons: [{ title: 'Tap me', action: 'https://example.com' }],
|
|
511
|
+
},
|
|
512
|
+
],
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
render(
|
|
518
|
+
<TestWrapper>
|
|
519
|
+
<ComponentToRender {...props} />
|
|
520
|
+
</TestWrapper>
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
expect(screen.getByText('Tap me')).toBeTruthy();
|
|
524
|
+
expect(screen.queryByText('No content available')).toBeNull();
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
it('should show one placeholder card when editor preview and cards array is empty', () => {
|
|
528
|
+
const props = {
|
|
529
|
+
...defaultProps,
|
|
530
|
+
content: {
|
|
531
|
+
viberPreviewContent: {
|
|
532
|
+
type: 'CAROUSEL',
|
|
533
|
+
showCarouselEditorPreview: true,
|
|
534
|
+
cards: [],
|
|
535
|
+
},
|
|
536
|
+
},
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
const { container } = render(
|
|
540
|
+
<TestWrapper>
|
|
541
|
+
<ComponentToRender {...props} />
|
|
542
|
+
</TestWrapper>
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
expect(container.querySelectorAll('.viber-carousel-preview .card')).toHaveLength(1);
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
it('should show no content when CAROUSEL has empty cards and no editor preview flag', () => {
|
|
549
|
+
const props = {
|
|
550
|
+
...defaultProps,
|
|
551
|
+
content: {
|
|
552
|
+
viberPreviewContent: {
|
|
553
|
+
type: 'CAROUSEL',
|
|
554
|
+
cards: [],
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
render(
|
|
560
|
+
<TestWrapper>
|
|
561
|
+
<ComponentToRender {...props} />
|
|
562
|
+
</TestWrapper>
|
|
563
|
+
);
|
|
564
|
+
|
|
565
|
+
expect(screen.getByText('No content available')).toBeTruthy();
|
|
566
|
+
});
|
|
203
567
|
});
|
|
204
568
|
|
|
205
569
|
describe('Account and Brand Name', () => {
|
|
@@ -6,6 +6,10 @@ import {
|
|
|
6
6
|
mapRcsSuggestionForTestMeta,
|
|
7
7
|
typeMatches,
|
|
8
8
|
unwrapEntity,
|
|
9
|
+
getTrimmedText,
|
|
10
|
+
hasTrimmedText,
|
|
11
|
+
getCarouselButtonsWithTitles,
|
|
12
|
+
getCarouselButtonSlotCount,
|
|
9
13
|
} from '../utils';
|
|
10
14
|
|
|
11
15
|
describe('CommonTestAndPreview/utils', () => {
|
|
@@ -148,4 +152,49 @@ describe('CommonTestAndPreview/utils', () => {
|
|
|
148
152
|
expect(unwrapEntity(response)).toBe(response);
|
|
149
153
|
});
|
|
150
154
|
});
|
|
155
|
+
|
|
156
|
+
describe('getTrimmedText / hasTrimmedText', () => {
|
|
157
|
+
it('trims string values', () => {
|
|
158
|
+
expect(getTrimmedText(' hello ')).toBe('hello');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('treats null/undefined as empty', () => {
|
|
162
|
+
expect(getTrimmedText(null)).toBe('');
|
|
163
|
+
expect(getTrimmedText(undefined)).toBe('');
|
|
164
|
+
expect(hasTrimmedText(' ')).toBe(false);
|
|
165
|
+
expect(hasTrimmedText('ok')).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('getCarouselButtonsWithTitles', () => {
|
|
170
|
+
it('returns up to 2 buttons with non-empty titles', () => {
|
|
171
|
+
expect(getCarouselButtonsWithTitles({
|
|
172
|
+
buttons: [
|
|
173
|
+
{ title: ' A ' },
|
|
174
|
+
{ title: '' },
|
|
175
|
+
{ title: 'B' },
|
|
176
|
+
{ title: 'C' },
|
|
177
|
+
],
|
|
178
|
+
})).toEqual([{ title: ' A ' }, { title: 'B' }]);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('returns empty array when card has no titled buttons', () => {
|
|
182
|
+
expect(getCarouselButtonsWithTitles({})).toEqual([]);
|
|
183
|
+
expect(getCarouselButtonsWithTitles(undefined)).toEqual([]);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe('getCarouselButtonSlotCount', () => {
|
|
188
|
+
it('returns the max titled-button count across cards, capped at 2', () => {
|
|
189
|
+
expect(getCarouselButtonSlotCount([
|
|
190
|
+
{ buttons: [{ title: 'A' }] },
|
|
191
|
+
{ buttons: [{ title: 'A' }, { title: 'B' }, { title: 'C' }] },
|
|
192
|
+
])).toBe(2);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('returns 0 when no cards have titled buttons', () => {
|
|
196
|
+
expect(getCarouselButtonSlotCount([])).toBe(0);
|
|
197
|
+
expect(getCarouselButtonSlotCount([{ buttons: [{ title: ' ' }] }])).toBe(0);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
151
200
|
});
|
|
@@ -116,3 +116,23 @@ export const unwrapEntity = (response) => {
|
|
|
116
116
|
if (response.entity === null) return null;
|
|
117
117
|
return response;
|
|
118
118
|
};
|
|
119
|
+
|
|
120
|
+
/** Trim string-like values; null/undefined become ''. */
|
|
121
|
+
export const getTrimmedText = (value = '') => (value ?? '').trim();
|
|
122
|
+
|
|
123
|
+
/** True when trimmed text is non-empty. */
|
|
124
|
+
export const hasTrimmedText = (value = '') => Boolean(getTrimmedText(value));
|
|
125
|
+
|
|
126
|
+
/** First up to 2 carousel buttons that have a non-empty title. */
|
|
127
|
+
export const getCarouselButtonsWithTitles = (card) => (
|
|
128
|
+
(card?.buttons ?? []).filter((button) => hasTrimmedText(button?.title)).slice(0, 2)
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Max button slots to reserve across carousel cards (0–2), so cards align
|
|
133
|
+
* even when some cards have fewer titled buttons.
|
|
134
|
+
*/
|
|
135
|
+
export const getCarouselButtonSlotCount = (cards = []) => {
|
|
136
|
+
const buttonCounts = cards.map((card) => getCarouselButtonsWithTitles(card).length);
|
|
137
|
+
return Math.min(2, Math.max(0, ...buttonCounts, 0));
|
|
138
|
+
};
|
|
@@ -17,11 +17,10 @@ import { createStructuredSelector } from 'reselect';
|
|
|
17
17
|
import CapRow from '@capillarytech/cap-ui-library/CapRow';
|
|
18
18
|
import CapDivider from '@capillarytech/cap-ui-library/CapDivider';
|
|
19
19
|
import CapButton from '@capillarytech/cap-ui-library/CapButton';
|
|
20
|
-
import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
|
|
21
20
|
// import injectSaga from '../../utils/injectSaga'; // cap-coupons flows disabled
|
|
22
21
|
// import injectReducer from '../../utils/injectReducer';
|
|
23
22
|
import { makeSelectAuthenticated } from '../Cap/selectors';
|
|
24
|
-
import {
|
|
23
|
+
import { createCentralCommsMetaId, getCentralCommsMetaIds } from '../../services/api';
|
|
25
24
|
import DynamicControlsStep from './steps/DynamicControlsStep';
|
|
26
25
|
import MessageTypeStep from './steps/MessageTypeStep';
|
|
27
26
|
import CommunicationStrategyStep from './steps/CommunicationStrategyStep';
|
|
@@ -36,10 +35,9 @@ import {
|
|
|
36
35
|
CHANNELS,
|
|
37
36
|
INCENTIVE_TYPES,
|
|
38
37
|
DYNAMIC_CONTROLS_CONFIG,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
CCS_CHANNEL_NAME_MAP,
|
|
38
|
+
CHANNEL_CONTENT_KEY_MAP,
|
|
39
|
+
CHANNEL_DELIVERY_KEY_MAP,
|
|
40
|
+
CAMPAIGNS,
|
|
43
41
|
} from './constants';
|
|
44
42
|
import { getEnabledSteps } from './utils/getEnabledSteps';
|
|
45
43
|
import messages from './messages';
|
|
@@ -66,25 +64,6 @@ const hasDeliverySettingForChannel = (channelSetting, channel) => {
|
|
|
66
64
|
return !!settings && Object.values(settings).some((v) => v !== null && v !== '' && v !== undefined);
|
|
67
65
|
};
|
|
68
66
|
|
|
69
|
-
// createCommDefinition resolves (rather than rejects) with the CCS error envelope
|
|
70
|
-
// for 4xx/5xx responses — see api.js's request()/checkStatus. A duplicate
|
|
71
|
-
// referenceId within the org comes back as this specific 409.
|
|
72
|
-
const isDuplicateReferenceIdError = (res) => res?.success === false && res?.status?.message === 'REFERENCE_ID_EXISTS';
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* CCS requires referenceId on create; the consumer-supplied Alert/comm name is
|
|
76
|
-
* mandatory but referenceId is optional in every consumer's own form. Generate
|
|
77
|
-
* a stable fallback from the name rather than failing the save.
|
|
78
|
-
*/
|
|
79
|
-
const buildCcsReferenceId = (name) => {
|
|
80
|
-
const slug = (name || 'COMM')
|
|
81
|
-
.trim()
|
|
82
|
-
.toUpperCase()
|
|
83
|
-
.replace(/[^A-Z0-9]+/g, '_')
|
|
84
|
-
.replace(/^_+|_+$/g, '') || 'COMM';
|
|
85
|
-
return `${slug}_${Date.now()}`;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
67
|
const CommunicationFlow = ({
|
|
89
68
|
config,
|
|
90
69
|
initialData,
|
|
@@ -112,7 +91,6 @@ const CommunicationFlow = ({
|
|
|
112
91
|
};
|
|
113
92
|
});
|
|
114
93
|
const [validationErrors, setValidationErrors] = useState({});
|
|
115
|
-
const [saveError, setSaveError] = useState(null);
|
|
116
94
|
|
|
117
95
|
// Memoize enabled steps
|
|
118
96
|
const enabledSteps = useMemo(() => getEnabledSteps(config), [config]);
|
|
@@ -172,82 +150,74 @@ const CommunicationFlow = ({
|
|
|
172
150
|
}, []);
|
|
173
151
|
|
|
174
152
|
const handleSave = useCallback(async () => {
|
|
175
|
-
setSaveError(null);
|
|
176
153
|
const aggregatedData = getAggregatedData();
|
|
177
154
|
const shouldUseCCS = config?.useCCS !== false;
|
|
178
|
-
let ccsCommDefinition = null;
|
|
179
155
|
|
|
180
156
|
if (shouldUseCCS) {
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
// has no name input of its own, so this is mandatory input from config.context.
|
|
185
|
-
const name = config?.context?.name;
|
|
157
|
+
const ouId = config?.context?.ouId || -1;
|
|
158
|
+
const module = config?.context?.module
|
|
159
|
+
|| (config?.consumer ? config.consumer.toUpperCase() : CAMPAIGNS);
|
|
186
160
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (!isMultiChannel && contentItem && name) {
|
|
190
|
-
const rawChannel = (contentItem.channel || '').toUpperCase();
|
|
191
|
-
const channel = CCS_CHANNEL_NAME_MAP[rawChannel] || rawChannel;
|
|
192
|
-
const contentKey = CCS_CHANNEL_CONTENT_KEY_MAP[channel];
|
|
193
|
-
const deliveryKey = CCS_CHANNEL_DELIVERY_KEY_MAP[channel];
|
|
194
|
-
const { dynamicControls = {} } = aggregatedData;
|
|
195
|
-
const channelSettings = aggregatedData.deliverySetting?.channelSetting?.[channel] || {};
|
|
196
|
-
const referenceId = config?.context?.referenceId || buildCcsReferenceId(name);
|
|
161
|
+
const channelContentKeyMap = CHANNEL_CONTENT_KEY_MAP;
|
|
162
|
+
const channelDeliveryKeyMap = CHANNEL_DELIVERY_KEY_MAP;
|
|
197
163
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
name,
|
|
201
|
-
description: config?.context?.description || undefined,
|
|
202
|
-
strategyType: CCS_STRATEGY_TYPE_SINGLE,
|
|
203
|
-
settings: {
|
|
204
|
-
additionalSettings: {
|
|
205
|
-
useTinyUrl: dynamicControls.useTinyUrl ?? false,
|
|
206
|
-
encryptUrl: dynamicControls.sendToControlCustomers ?? false,
|
|
207
|
-
linkTrackingEnabled: dynamicControls.overrideDailyLimit ?? false,
|
|
208
|
-
userSubscriptionDisabled: dynamicControls.sendToBrandPocs ?? false,
|
|
209
|
-
},
|
|
210
|
-
executionParams: {},
|
|
211
|
-
},
|
|
212
|
-
singleChannelStrategy: {
|
|
213
|
-
variant: {
|
|
214
|
-
channel,
|
|
215
|
-
...(contentKey && { [contentKey]: contentItem.templateData }),
|
|
216
|
-
...(deliveryKey && { [deliveryKey]: { channelSettings: { channel, ...channelSettings } } }),
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
};
|
|
164
|
+
const contentItems = aggregatedData.contentItems || [];
|
|
165
|
+
const { dynamicControls = {} } = aggregatedData;
|
|
220
166
|
|
|
167
|
+
const additionalSettings = {
|
|
168
|
+
useTinyUrl: dynamicControls.useTinyUrl ?? false,
|
|
169
|
+
encryptUrl: dynamicControls.sendToControlCustomers ?? false,
|
|
170
|
+
linkTrackingEnabled: dynamicControls.overrideDailyLimit ?? false,
|
|
171
|
+
userSubscriptionDisabled: dynamicControls.sendToBrandPocs ?? false,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
if (contentItems.length > 0) {
|
|
221
175
|
try {
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
176
|
+
const responses = await Promise.all(
|
|
177
|
+
contentItems.map((item) => {
|
|
178
|
+
const channel = (item.channel || '').toUpperCase();
|
|
179
|
+
const contentKey = channelContentKeyMap[channel];
|
|
180
|
+
const deliveryKey = channelDeliveryKeyMap[channel];
|
|
181
|
+
const payload = {
|
|
182
|
+
centralCommsPayload: {
|
|
183
|
+
ouId,
|
|
184
|
+
channel,
|
|
185
|
+
module,
|
|
186
|
+
executionParams: {},
|
|
187
|
+
clientName: 'EMF',
|
|
188
|
+
...(contentKey && {
|
|
189
|
+
[contentKey]: { channel, ...item.templateData },
|
|
190
|
+
}),
|
|
191
|
+
...(deliveryKey && {
|
|
192
|
+
[deliveryKey]: {
|
|
193
|
+
additionalSettings,
|
|
194
|
+
channelSettings: {
|
|
195
|
+
channel,
|
|
196
|
+
...(aggregatedData.deliverySetting?.channelSetting?.[channel] || {}),
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
}),
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
return createCentralCommsMetaId(payload);
|
|
203
|
+
}),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const metaIds = responses
|
|
207
|
+
.map((res) => res?.response?.data?.id)
|
|
208
|
+
.filter(Boolean)
|
|
209
|
+
.join(',');
|
|
210
|
+
|
|
211
|
+
if (metaIds) {
|
|
212
|
+
const getResponse = await getCentralCommsMetaIds(metaIds);
|
|
237
213
|
}
|
|
238
214
|
} catch (error) {
|
|
239
|
-
console.error('[CommunicationFlow] CCS
|
|
215
|
+
console.error('[CommunicationFlow] CCS createCentralCommsMetaId error:', error);
|
|
240
216
|
}
|
|
241
|
-
} else if (!name) {
|
|
242
|
-
console.warn('[CommunicationFlow] Skipping CCS createCommDefinition — config.context.name is required');
|
|
243
|
-
} else if (isMultiChannel) {
|
|
244
|
-
console.warn('[CommunicationFlow] Skipping CCS createCommDefinition — CHANNEL_PRIORITY/AB_TEST strategies are not supported by CCS create yet (SINGLE only)');
|
|
245
|
-
} else if (!contentItem) {
|
|
246
|
-
console.warn('[CommunicationFlow] Skipping CCS createCommDefinition — no content item found (contentItems is empty)');
|
|
247
217
|
}
|
|
248
218
|
}
|
|
249
219
|
|
|
250
|
-
onSave(
|
|
220
|
+
onSave(aggregatedData);
|
|
251
221
|
}, [getAggregatedData, config, onSave]);
|
|
252
222
|
|
|
253
223
|
// Call onChange callback when stepData changes
|
|
@@ -347,11 +317,6 @@ const CommunicationFlow = ({
|
|
|
347
317
|
{renderSteps()}
|
|
348
318
|
{onSave && (
|
|
349
319
|
<CapRow useLegacy className="communication-flow-container__footer">
|
|
350
|
-
{saveError && (
|
|
351
|
-
<CapLabel type="label2" className="communication-flow-container__save-error">
|
|
352
|
-
{saveError}
|
|
353
|
-
</CapLabel>
|
|
354
|
-
)}
|
|
355
320
|
<CapButton type="primary" onClick={handleSave} disabled={isSaveDisabled}>
|
|
356
321
|
{formatMessage(messages.save)}
|
|
357
322
|
</CapButton>
|