@capillarytech/creatives-library 9.0.48 → 9.0.49-alpha.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.
@@ -73,6 +73,7 @@ import * as ebillActions from '../Ebill/actions';
73
73
  import * as emailActions from '../Email/actions';
74
74
  import * as lineActions from '../Line/Container/actions';
75
75
  import * as viberActions from '../Viber/actions';
76
+ import { VIBER_MEDIA_TYPES } from '../Viber/constants';
76
77
  import * as facebookActions from '../Facebook/actions';
77
78
  import * as whatsappActions from '../Whatsapp/actions';
78
79
  import * as rcsActions from '../Rcs/actions';
@@ -1405,6 +1406,11 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1405
1406
  const image = viberContent.image || {};
1406
1407
  const video = viberContent.video || {};
1407
1408
  const button = viberContent.button || {};
1409
+ const messageType = viberContent.type || '';
1410
+ const cardsRaw = viberContent.cards;
1411
+ const cards = Array.isArray(cardsRaw) ? cardsRaw : [];
1412
+ const isCarousel =
1413
+ messageType === VIBER_MEDIA_TYPES.CAROUSEL || cards.length > 0;
1408
1414
 
1409
1415
  const viberPreview = {
1410
1416
  messageContent: text,
@@ -1422,14 +1428,39 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1422
1428
  };
1423
1429
  }
1424
1430
 
1431
+ if (isCarousel) {
1432
+ viberPreview.type = VIBER_MEDIA_TYPES.CAROUSEL;
1433
+ viberPreview.cards = cards.map((card) => ({
1434
+ text: card?.text || '',
1435
+ mediaUrl: card?.mediaUrl || '',
1436
+ buttons: (card?.buttons || []).map((btn) => ({
1437
+ title: btn?.title || '',
1438
+ action: btn?.action || '',
1439
+ })),
1440
+ }));
1441
+ viberPreview.showCarouselEditorPreview = true;
1442
+ }
1443
+
1425
1444
  // Extract account name
1426
1445
  const accountName = get(template, 'definition.accountName', '');
1427
1446
 
1428
1447
  // Return Viber content object (same as Viber/index.js getTemplateContent)
1429
1448
  return {
1430
1449
  viberPreviewContent: viberPreview,
1431
- accountName: accountName ? [accountName] : [],
1432
- brandName: accountName ? [accountName] : [],
1450
+ accountName: accountName || '',
1451
+ brandName: accountName || '',
1452
+ messageContent: text,
1453
+ ...(isCarousel && {
1454
+ type: VIBER_MEDIA_TYPES.CAROUSEL,
1455
+ cards: viberPreview.cards,
1456
+ }),
1457
+ ...(!isCarousel && !isEmpty(button) && button.text && (button.url || viberContent.buttonURL) && {
1458
+ button: {
1459
+ text: button.text,
1460
+ url: button.url || viberContent.buttonURL || '',
1461
+ },
1462
+ }),
1463
+ buttonURL: button.url || viberContent.buttonURL || '',
1433
1464
  };
1434
1465
  }
1435
1466
 
@@ -2498,10 +2529,59 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
2498
2529
  image = {},
2499
2530
  button = {},
2500
2531
  video = {},
2532
+ type = '',
2533
+ cards = [],
2501
2534
  } = {},
2502
2535
  } = {},
2503
2536
  } = template.versions.base;
2537
+ const isViberCarousel = type === VIBER_MEDIA_TYPES.CAROUSEL;
2504
2538
  templateData.content = text;
2539
+ if (isViberCarousel) {
2540
+ const previewCards = Array.isArray(cards) ? cards.slice(0, 1) : [];
2541
+ // Bypass CapCustomCard Viber Meta + line-clamp (clips title/buttons for tall images).
2542
+ // Parent class `viber-carousel-static` scopes listing styles in _templates.scss.
2543
+ // cardType hits the default content path; keep VIBER for channel card styles.
2544
+ templateData.cardType = 'VIBER_CAROUSEL_PREVIEW';
2545
+ templateData.className = 'viber-carousel-static VIBER';
2546
+ templateData.content = (
2547
+ <CapRow vertical className="content">
2548
+ <CapRow className="message-box">
2549
+ <CapLabel type="label1" className="message">
2550
+ {text}
2551
+ </CapLabel>
2552
+ </CapRow>
2553
+ <CapRow className="cards">
2554
+ {previewCards?.map((card, cardIdx) => (
2555
+ <CapRow vertical className="card" key={`viber-carousel-static-card-${cardIdx}`}>
2556
+ {card?.mediaUrl ? (
2557
+ <CapImage src={card.mediaUrl} className="image" />
2558
+ ) : (
2559
+ <CapRow className="image-placeholder" />
2560
+ )}
2561
+ <CapLabel type="label1" className="text">
2562
+ {card?.text}
2563
+ </CapLabel>
2564
+ <CapRow vertical className="buttons">
2565
+ {(Array.isArray(card?.buttons) && card.buttons.length
2566
+ ? card.buttons
2567
+ : [{}, {}]
2568
+ ).slice(0, 2).map((carouselButton, btnIdx) => (
2569
+ <CapLabel
2570
+ key={`viber-carousel-static-btn-${cardIdx}-${btnIdx}`}
2571
+ type="label1"
2572
+ className={`button${btnIdx === 1 ? ' button-secondary' : ''}`}
2573
+ >
2574
+ {(carouselButton?.title || '').trim()}
2575
+ </CapLabel>
2576
+ ))}
2577
+ </CapRow>
2578
+ </CapRow>
2579
+ ))}
2580
+ </CapRow>
2581
+ </CapRow>
2582
+ );
2583
+ break;
2584
+ }
2505
2585
  if (!isEmpty(image)) {
2506
2586
  const { url = '' } = image;
2507
2587
  templateData.url = url;
@@ -5188,15 +5268,22 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
5188
5268
  ? this.props.Templates.selectedWhatsappAccount.name
5189
5269
  : null
5190
5270
  }
5191
- // Pass formData for EMAIL and SMS channels for tag extraction
5271
+ // Pass formData for tag extraction (EMAIL/SMS use nested formData; VIBER uses content object)
5192
5272
  formData={
5193
- this.state.testAndPreviewContent &&
5194
- (this.state.channel?.toUpperCase() === EMAIL ||
5195
- this.state.channel?.toUpperCase() === SMS) &&
5196
- typeof this.state.testAndPreviewContent === 'object' &&
5197
- this.state.testAndPreviewContent?.formData
5198
- ? this.state.testAndPreviewContent.formData
5199
- : null
5273
+ (() => {
5274
+ const previewContent = this.state.testAndPreviewContent;
5275
+ const channelUpper = this.state.channel?.toUpperCase();
5276
+ if (!previewContent || typeof previewContent !== 'object') {
5277
+ return null;
5278
+ }
5279
+ if ([EMAIL, SMS].includes(channelUpper)) {
5280
+ return previewContent.formData || null;
5281
+ }
5282
+ if (channelUpper === VIBER) {
5283
+ return previewContent;
5284
+ }
5285
+ return null;
5286
+ })()
5200
5287
  }
5201
5288
  />
5202
5289
  )}
@@ -47,7 +47,24 @@ export const VIBER_MEDIA_TYPES = {
47
47
  TEXT: 'TEXT',
48
48
  IMAGE: 'IMAGE',
49
49
  VIDEO: 'VIDEO',
50
+ CAROUSEL: 'CAROUSEL',
50
51
  };
52
+ export const VIBER_CAROUSEL_MIN_CARDS = 2;
53
+ export const VIBER_CAROUSEL_MAX_CARDS = 5;
54
+ export const VIBER_CAROUSEL_MAX_BUTTONS = 2;
55
+ export const VIBER_CAROUSEL_CARD_TITLE_MIN_LENGTH = 2;
56
+ export const VIBER_CAROUSEL_CARD_TITLE_MAX_LENGTH = 38;
57
+ export const VIBER_CAROUSEL_FIRST_BUTTON_TITLE_MAX_LENGTH = 10;
58
+ export const VIBER_CAROUSEL_SECOND_BUTTON_TITLE_MAX_LENGTH = 12;
59
+ export const VIBER_CAROUSEL_BUTTON_URL_MAX_LENGTH = 1000;
60
+ export const STATIC_URL = 'STATIC_URL';
61
+ export const DYNAMIC_URL = 'DYNAMIC_URL';
62
+ /** Recommended / validated carousel image height in pixels (passed to image upload). */
63
+ export const VIBER_CAROUSEL_IMG_HEIGHT = 600;
64
+ /** Recommended / validated carousel image width in pixels (passed to image upload). */
65
+ export const VIBER_CAROUSEL_IMG_WIDTH = 696;
66
+ /** Maximum carousel image file size (bytes). 10_000_000 ≈ 10 MB (decimal). */
67
+ export const VIBER_CAROUSEL_IMG_SIZE = 10000000;
51
68
  export const ALLOWED_IMAGE_EXTENSIONS_REGEX_VIBER = /\.(jpe?g|png)$/i;
52
69
  export const ALLOWED_EXTENSIONS_VIDEO_REGEX_VIBER = /\.(mp4|3gp|m4v|mov)$/i;
53
70
  export const NONE = 'NONE';
@@ -69,6 +86,10 @@ export const mediaRadioOptions = [
69
86
  value: VIBER_MEDIA_TYPES.VIDEO,
70
87
  label: <FormattedMessage {...messages.mediaVideo} />,
71
88
  },
89
+ {
90
+ value: VIBER_MEDIA_TYPES.CAROUSEL,
91
+ label: <FormattedMessage {...messages.mediaCarousel} />,
92
+ },
72
93
  ];
73
94
 
74
95
  export const buttonRadioOptions = [