@capillarytech/creatives-library 9.0.40 → 9.0.41-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';
@@ -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,65 @@ 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
+ // Keep VIBER in className for listing styles; cardType hits the default content path.
2480
+ templateData.cardType = 'VIBER_CAROUSEL_PREVIEW';
2481
+ templateData.className = 'viber-carousel-static VIBER';
2482
+ templateData.style = {
2483
+ height: 'auto',
2484
+ minHeight: '21.125rem',
2485
+ overflow: 'visible',
2486
+ };
2487
+ templateData.bodyStyle = {
2488
+ height: 'auto',
2489
+ overflow: 'visible',
2490
+ paddingBottom: '12px',
2491
+ };
2492
+ templateData.content = (
2493
+ <CapRow vertical className="viber-carousel-static-content">
2494
+ <CapRow className="viber-carousel-static-message-box">
2495
+ <CapLabel type="label1" className="viber-carousel-static-message">
2496
+ {text}
2497
+ </CapLabel>
2498
+ </CapRow>
2499
+ <CapRow className="viber-carousel-static-cards">
2500
+ {previewCards.map((card, cardIdx) => (
2501
+ <CapRow vertical className="viber-carousel-static-card" key={`viber-static-card-${cardIdx}`}>
2502
+ {card?.mediaUrl ? (
2503
+ <CapImage src={card.mediaUrl} className="viber-carousel-static-image" />
2504
+ ) : (
2505
+ <CapRow className="viber-carousel-static-image-placeholder" />
2506
+ )}
2507
+ <CapLabel type="label1" className="viber-carousel-static-text">
2508
+ {card?.text}
2509
+ </CapLabel>
2510
+ <CapRow vertical className="viber-carousel-static-buttons">
2511
+ {(Array.isArray(card?.buttons) && card.buttons.length ? card.buttons : [{}, {}]).slice(0, 2).map((carouselButton, btnIdx) => (
2512
+ <CapLabel
2513
+ key={`viber-static-btn-${cardIdx}-${btnIdx}`}
2514
+ type="label1"
2515
+ className={`viber-carousel-static-button ${btnIdx === 1 ? 'viber-carousel-static-button-secondary' : ''}`}
2516
+ >
2517
+ {(carouselButton?.title || '').trim()}
2518
+ </CapLabel>
2519
+ ))}
2520
+ </CapRow>
2521
+ </CapRow>
2522
+ ))}
2523
+ </CapRow>
2524
+ </CapRow>
2525
+ );
2526
+ break;
2527
+ }
2442
2528
  if (!isEmpty(image)) {
2443
2529
  const { url = '' } = image;
2444
2530
  templateData.url = url;
@@ -5106,15 +5192,22 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
5106
5192
  ? this.props.Templates.selectedWhatsappAccount.name
5107
5193
  : null
5108
5194
  }
5109
- // Pass formData for EMAIL and SMS channels for tag extraction
5195
+ // Pass formData for tag extraction (EMAIL/SMS use nested formData; VIBER uses content object)
5110
5196
  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
5197
+ (() => {
5198
+ const previewContent = this.state.testAndPreviewContent;
5199
+ const channelUpper = this.state.channel?.toUpperCase();
5200
+ if (!previewContent || typeof previewContent !== 'object') {
5201
+ return null;
5202
+ }
5203
+ if ([EMAIL, SMS].includes(channelUpper)) {
5204
+ return previewContent.formData || null;
5205
+ }
5206
+ if (channelUpper === VIBER) {
5207
+ return previewContent;
5208
+ }
5209
+ return null;
5210
+ })()
5118
5211
  }
5119
5212
  />
5120
5213
  )}
@@ -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 = [