@capillarytech/creatives-library 9.0.42 → 9.0.43

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';
@@ -1399,6 +1400,11 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1399
1400
  const image = viberContent.image || {};
1400
1401
  const video = viberContent.video || {};
1401
1402
  const button = viberContent.button || {};
1403
+ const messageType = viberContent.type || '';
1404
+ const cardsRaw = viberContent.cards;
1405
+ const cards = Array.isArray(cardsRaw) ? cardsRaw : [];
1406
+ const isCarousel =
1407
+ messageType === VIBER_MEDIA_TYPES.CAROUSEL || cards.length > 0;
1402
1408
 
1403
1409
  const viberPreview = {
1404
1410
  messageContent: text,
@@ -1416,14 +1422,39 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1416
1422
  };
1417
1423
  }
1418
1424
 
1425
+ if (isCarousel) {
1426
+ viberPreview.type = VIBER_MEDIA_TYPES.CAROUSEL;
1427
+ viberPreview.cards = cards.map((card) => ({
1428
+ text: card?.text || '',
1429
+ mediaUrl: card?.mediaUrl || '',
1430
+ buttons: (card?.buttons || []).map((btn) => ({
1431
+ title: btn?.title || '',
1432
+ action: btn?.action || '',
1433
+ })),
1434
+ }));
1435
+ viberPreview.showCarouselEditorPreview = true;
1436
+ }
1437
+
1419
1438
  // Extract account name
1420
1439
  const accountName = get(template, 'definition.accountName', '');
1421
1440
 
1422
1441
  // Return Viber content object (same as Viber/index.js getTemplateContent)
1423
1442
  return {
1424
1443
  viberPreviewContent: viberPreview,
1425
- accountName: accountName ? [accountName] : [],
1426
- brandName: accountName ? [accountName] : [],
1444
+ accountName: accountName || '',
1445
+ brandName: accountName || '',
1446
+ messageContent: text,
1447
+ ...(isCarousel && {
1448
+ type: VIBER_MEDIA_TYPES.CAROUSEL,
1449
+ cards: viberPreview.cards,
1450
+ }),
1451
+ ...(!isCarousel && !isEmpty(button) && button.text && (button.url || viberContent.buttonURL) && {
1452
+ button: {
1453
+ text: button.text,
1454
+ url: button.url || viberContent.buttonURL || '',
1455
+ },
1456
+ }),
1457
+ buttonURL: button.url || viberContent.buttonURL || '',
1427
1458
  };
1428
1459
  }
1429
1460
 
@@ -2435,10 +2466,59 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
2435
2466
  image = {},
2436
2467
  button = {},
2437
2468
  video = {},
2469
+ type = '',
2470
+ cards = [],
2438
2471
  } = {},
2439
2472
  } = {},
2440
2473
  } = template.versions.base;
2474
+ const isViberCarousel = type === VIBER_MEDIA_TYPES.CAROUSEL;
2441
2475
  templateData.content = text;
2476
+ if (isViberCarousel) {
2477
+ const previewCards = Array.isArray(cards) ? cards.slice(0, 1) : [];
2478
+ // Bypass CapCustomCard Viber Meta + line-clamp (clips title/buttons for tall images).
2479
+ // Parent class `viber-carousel-static` scopes listing styles in _templates.scss.
2480
+ // cardType hits the default content path; keep VIBER for channel card styles.
2481
+ templateData.cardType = 'VIBER_CAROUSEL_PREVIEW';
2482
+ templateData.className = 'viber-carousel-static VIBER';
2483
+ templateData.content = (
2484
+ <CapRow vertical className="content">
2485
+ <CapRow className="message-box">
2486
+ <CapLabel type="label1" className="message">
2487
+ {text}
2488
+ </CapLabel>
2489
+ </CapRow>
2490
+ <CapRow className="cards">
2491
+ {previewCards?.map((card, cardIdx) => (
2492
+ <CapRow vertical className="card" key={`viber-carousel-static-card-${cardIdx}`}>
2493
+ {card?.mediaUrl ? (
2494
+ <CapImage src={card.mediaUrl} className="image" />
2495
+ ) : (
2496
+ <CapRow className="image-placeholder" />
2497
+ )}
2498
+ <CapLabel type="label1" className="text">
2499
+ {card?.text}
2500
+ </CapLabel>
2501
+ <CapRow vertical className="buttons">
2502
+ {(Array.isArray(card?.buttons) && card.buttons.length
2503
+ ? card.buttons
2504
+ : [{}, {}]
2505
+ ).slice(0, 2).map((carouselButton, btnIdx) => (
2506
+ <CapLabel
2507
+ key={`viber-carousel-static-btn-${cardIdx}-${btnIdx}`}
2508
+ type="label1"
2509
+ className={`button${btnIdx === 1 ? ' button-secondary' : ''}`}
2510
+ >
2511
+ {(carouselButton?.title || '').trim()}
2512
+ </CapLabel>
2513
+ ))}
2514
+ </CapRow>
2515
+ </CapRow>
2516
+ ))}
2517
+ </CapRow>
2518
+ </CapRow>
2519
+ );
2520
+ break;
2521
+ }
2442
2522
  if (!isEmpty(image)) {
2443
2523
  const { url = '' } = image;
2444
2524
  templateData.url = url;
@@ -5106,15 +5186,22 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
5106
5186
  ? this.props.Templates.selectedWhatsappAccount.name
5107
5187
  : null
5108
5188
  }
5109
- // Pass formData for EMAIL and SMS channels for tag extraction
5189
+ // Pass formData for tag extraction (EMAIL/SMS use nested formData; VIBER uses content object)
5110
5190
  formData={
5111
- this.state.testAndPreviewContent &&
5112
- (this.state.channel?.toUpperCase() === EMAIL ||
5113
- this.state.channel?.toUpperCase() === SMS) &&
5114
- typeof this.state.testAndPreviewContent === 'object' &&
5115
- this.state.testAndPreviewContent?.formData
5116
- ? this.state.testAndPreviewContent.formData
5117
- : null
5191
+ (() => {
5192
+ const previewContent = this.state.testAndPreviewContent;
5193
+ const channelUpper = this.state.channel?.toUpperCase();
5194
+ if (!previewContent || typeof previewContent !== 'object') {
5195
+ return null;
5196
+ }
5197
+ if ([EMAIL, SMS].includes(channelUpper)) {
5198
+ return previewContent.formData || null;
5199
+ }
5200
+ if (channelUpper === VIBER) {
5201
+ return previewContent;
5202
+ }
5203
+ return null;
5204
+ })()
5118
5205
  }
5119
5206
  />
5120
5207
  )}
@@ -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 = [