@capillarytech/creatives-library 7.12.41 → 7.12.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "7.12.41",
4
+ "version": "7.12.43",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -3,9 +3,9 @@ import { injectIntl } from 'react-intl';
3
3
 
4
4
  import * as actions from '../actions';
5
5
  import {Cap} from '../index';
6
- import mockData from '../../mockdata';
6
+ import mockdata from '../../mockdata';
7
7
  import { shallowWithIntl } from '../../../helpers/intl-enzym-test-helpers';
8
- const { match, location, capGlobal, language } = mockData;
8
+ const { match, location, capGlobal, language } = mockdata;
9
9
 
10
10
  jest.mock('@capillarytech/cap-ui-utils', () => ({
11
11
  GA: {
@@ -18,7 +18,6 @@ import messages from './messages';
18
18
 
19
19
  export class ChannelTemplates extends React.Component { // eslint-disable-line react/prefer-stateless-function
20
20
  componentDidMount() {
21
- debugger;
22
21
  this.props.actions.getTemplates(this.props.channel);
23
22
  }
24
23
  render() {
@@ -6,6 +6,7 @@ import cloneDeep from 'lodash/cloneDeep';
6
6
  import TemplatesV2 from '../TemplatesV2';
7
7
  import TemplatePreview from '../../v2Components/TemplatePreview';
8
8
  import SmsWrapper from '../SmsWrapper';
9
+ import isEmpty from 'lodash/isEmpty';
9
10
  // import SmsEdit from '../Sms/Edit';
10
11
  import Email from '../Email';
11
12
  import EmailWrapper from '../EmailWrapper';
@@ -239,7 +240,9 @@ export function SlideBoxContent(props) {
239
240
  baseUrl,
240
241
  video,
241
242
  template,
243
+ contents,
242
244
  }) => {
245
+ const isNewLineFormat = isEmpty(template) && !isEmpty(contents);
243
246
  const {
244
247
  originalContentUrl,
245
248
  externalLink: {
@@ -258,8 +261,14 @@ export function SlideBoxContent(props) {
258
261
  previewContent.baseUrl = baseUrl;
259
262
  previewContent.video = originalContentUrl;
260
263
  previewContent.actionUrl = linkUri;
261
- previewContent.imageCarousel = get(template, 'columns', [{}]).map(({ imageUrl, action: { label: actionLabel } = {} }) => ({ imageUrl, actionLabel }) );
262
-
264
+ if (isNewLineFormat) {
265
+ previewContent.imageCarousel = get(contents, 'contents', [{}]).map(({
266
+ hero: { url = ''} = {},
267
+ footer: { contents: [{ action: { label = '' } = {} }] = [{}] } = {},
268
+ }) => ({ imageUrl: url, actionLabel: label }));
269
+ } else {
270
+ previewContent.imageCarousel = get(template, 'columns', [{}]).map(({ imageUrl, action: { label: actionLabel } = {} }) => ({ imageUrl, actionLabel }) );
271
+ }
263
272
  const getType = () => {
264
273
  if (text) {
265
274
  return 'text';
@@ -273,7 +282,7 @@ export function SlideBoxContent(props) {
273
282
  if (baseUrl) {
274
283
  return 'imagemap';
275
284
  }
276
- if (template) {
285
+ if (template || contents) {
277
286
  return 'image_carousel';
278
287
  }
279
288
  if (video) {
@@ -4,7 +4,7 @@ import { shallowWithIntl } from '../../../helpers/intl-enzym-test-helpers';
4
4
  import { SlideBoxContent } from '../SlideBoxContent';
5
5
  import mockdata from '../../mockdata';
6
6
 
7
- const { whatsappEditTemplateData, whatsappPreviewTemplateData, rcsEditTemplateData, rcsPreviewTemplateData } = mockdata;
7
+ const { whatsappEditTemplateData, whatsappPreviewTemplateData, rcsEditTemplateData, rcsPreviewTemplateData, lineEditTemplateData, linePreviewTemplateData } = mockdata;
8
8
 
9
9
  jest.mock("../../../v2Components/FormBuilder", () => ({
10
10
  __esModule: true,
@@ -66,4 +66,14 @@ describe('Test SlideBoxContent container', () => {
66
66
  expect(renderedComponent).toMatchSnapshot();
67
67
  });
68
68
 
69
+ it('Should render correct component for line channel edit mode', () => {
70
+ renderFunction("LINE", "editTemplate", lineEditTemplateData);
71
+ expect(renderedComponent).toMatchSnapshot();
72
+ });
73
+
74
+ it('Should render correct component for line channel preview mode', () => {
75
+ renderFunction("LINE", "preview", linePreviewTemplateData);
76
+ expect(renderedComponent).toMatchSnapshot();
77
+ });
78
+
69
79
  });
@@ -1,5 +1,229 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`Test SlideBoxContent container Should render correct component for line channel edit mode 1`] = `
4
+ <SlideBoxContent__CreativesWrapper>
5
+ <Connect(UserIsAuthenticated(Connect(InjectIntl(CreativesCommon))))
6
+ location={
7
+ Object {
8
+ "pathname": "/sms/edit",
9
+ "query": Object {
10
+ "isEditFromCampaigns": undefined,
11
+ "module": "library",
12
+ "type": "embedded",
13
+ },
14
+ "search": "",
15
+ }
16
+ }
17
+ onCreateComplete={[MockFunction]}
18
+ params={
19
+ Object {
20
+ "id": "629f7ecf134738019b2e332e",
21
+ "mode": undefined,
22
+ }
23
+ }
24
+ route={
25
+ Object {
26
+ "name": "edit_text",
27
+ }
28
+ }
29
+ templateData={
30
+ Object {
31
+ "_id": "629f7ecf134738019b2e332e",
32
+ "channel": "LINE",
33
+ "mode": "edit",
34
+ "modeType": "",
35
+ "type": "LINE",
36
+ "validity": true,
37
+ }
38
+ }
39
+ />
40
+ </SlideBoxContent__CreativesWrapper>
41
+ `;
42
+
43
+ exports[`Test SlideBoxContent container Should render correct component for line channel preview mode 1`] = `
44
+ <SlideBoxContent__CreativesWrapper>
45
+ <InjectIntl(TemplatePreview)
46
+ channel="line"
47
+ charCounterEnabled={false}
48
+ content={
49
+ Array [
50
+ Object {
51
+ "actionUrl": undefined,
52
+ "baseUrl": undefined,
53
+ "imageCarousel": Array [
54
+ Object {
55
+ "actionLabel": "ggg",
56
+ "imageUrl": "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/b9f2aa7a-3f1a-4a20-a737-8d50841.jpeg",
57
+ },
58
+ ],
59
+ "messageContent": undefined,
60
+ "previewImageUrl": undefined,
61
+ "selectedSticker": Object {
62
+ "animatedStickerUrl": undefined,
63
+ "packageId": undefined,
64
+ "stickerId": undefined,
65
+ "stickerUrl": undefined,
66
+ },
67
+ "type": "image_carousel",
68
+ "video": undefined,
69
+ },
70
+ ]
71
+ }
72
+ showCount={true}
73
+ templateData={
74
+ Object {
75
+ "_id": "629f7ecf134738019b2e332e",
76
+ "createdAt": "2022-06-07T16:37:35.447Z",
77
+ "createdBy": "15000449",
78
+ "isActive": true,
79
+ "mode": "preview",
80
+ "name": "ggg1",
81
+ "orgId": 1604,
82
+ "totalCount": 31,
83
+ "type": "LINE",
84
+ "updatedAt": "2022-06-07T16:42:02.243Z",
85
+ "updatedBy": "15000449",
86
+ "updatedByName": "Ashish Karan fd",
87
+ "versions": Object {
88
+ "base": Object {
89
+ "content": Object {
90
+ "messages": Array [
91
+ Object {
92
+ "altText": "ggg",
93
+ "contents": Object {
94
+ "contents": Array [
95
+ Object {
96
+ "footer": Object {
97
+ "contents": Array [
98
+ Object {
99
+ "action": Object {
100
+ "label": "ggg",
101
+ "text": "ggg",
102
+ "type": "message",
103
+ },
104
+ "height": "sm",
105
+ "style": "link",
106
+ "type": "button",
107
+ },
108
+ ],
109
+ "layout": "vertical",
110
+ "spacing": "xs",
111
+ "type": "box",
112
+ },
113
+ "hero": Object {
114
+ "aspectMode": "cover",
115
+ "aspectRatio": "1:1",
116
+ "size": "full",
117
+ "type": "image",
118
+ "url": "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/b9f2aa7a-3f1a-4a20-a737-8d50841.jpeg",
119
+ },
120
+ "type": "bubble",
121
+ },
122
+ ],
123
+ "type": "carousel",
124
+ },
125
+ "type": "flex",
126
+ },
127
+ ],
128
+ "to": "{{line_id}}",
129
+ },
130
+ },
131
+ "history": Array [],
132
+ },
133
+ }
134
+ }
135
+ viberBrandName=""
136
+ />
137
+ <Connect(UserIsAuthenticated(Connect(InjectIntl(CreativesCommon))))
138
+ location={
139
+ Object {
140
+ "pathname": "/sms/edit",
141
+ "query": Object {
142
+ "isEditFromCampaigns": undefined,
143
+ "module": "library",
144
+ "type": "embedded",
145
+ },
146
+ "search": "",
147
+ }
148
+ }
149
+ onCreateComplete={[MockFunction]}
150
+ params={
151
+ Object {
152
+ "id": "629f7ecf134738019b2e332e",
153
+ "mode": undefined,
154
+ }
155
+ }
156
+ route={
157
+ Object {
158
+ "name": "edit_text",
159
+ }
160
+ }
161
+ templateData={
162
+ Object {
163
+ "_id": "629f7ecf134738019b2e332e",
164
+ "createdAt": "2022-06-07T16:37:35.447Z",
165
+ "createdBy": "15000449",
166
+ "isActive": true,
167
+ "mode": "preview",
168
+ "name": "ggg1",
169
+ "orgId": 1604,
170
+ "totalCount": 31,
171
+ "type": "LINE",
172
+ "updatedAt": "2022-06-07T16:42:02.243Z",
173
+ "updatedBy": "15000449",
174
+ "updatedByName": "Ashish Karan fd",
175
+ "versions": Object {
176
+ "base": Object {
177
+ "content": Object {
178
+ "messages": Array [
179
+ Object {
180
+ "altText": "ggg",
181
+ "contents": Object {
182
+ "contents": Array [
183
+ Object {
184
+ "footer": Object {
185
+ "contents": Array [
186
+ Object {
187
+ "action": Object {
188
+ "label": "ggg",
189
+ "text": "ggg",
190
+ "type": "message",
191
+ },
192
+ "height": "sm",
193
+ "style": "link",
194
+ "type": "button",
195
+ },
196
+ ],
197
+ "layout": "vertical",
198
+ "spacing": "xs",
199
+ "type": "box",
200
+ },
201
+ "hero": Object {
202
+ "aspectMode": "cover",
203
+ "aspectRatio": "1:1",
204
+ "size": "full",
205
+ "type": "image",
206
+ "url": "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/b9f2aa7a-3f1a-4a20-a737-8d50841.jpeg",
207
+ },
208
+ "type": "bubble",
209
+ },
210
+ ],
211
+ "type": "carousel",
212
+ },
213
+ "type": "flex",
214
+ },
215
+ ],
216
+ "to": "{{line_id}}",
217
+ },
218
+ },
219
+ "history": Array [],
220
+ },
221
+ }
222
+ }
223
+ />
224
+ </SlideBoxContent__CreativesWrapper>
225
+ `;
226
+
3
227
  exports[`Test SlideBoxContent container Should render correct component for rcs channel create mode 1`] = `
4
228
  <SlideBoxContent__CreativesWrapper>
5
229
  <Connect(UserIsAuthenticated(Connect(InjectIntl(CreativesCommon))))
@@ -47,6 +47,7 @@ export const LineImageCarouselContent = ({
47
47
  const [isDrawerRequired, updateDrawerRequirement] = useState(false);
48
48
  const [isImageError, updateImageErrorMessage] = useState(false);
49
49
  const [imageSrc, updateImageSrc] = useState();
50
+ const [aspectRatio, updateAspectRatio] = useState();
50
51
  const [isImage, updateImageStatus] = useState(false);
51
52
  const [selectedActionType, updateActionType] = useState('');
52
53
  const [actionLabel, updateActionLabel] = useState('');
@@ -58,16 +59,18 @@ export const LineImageCarouselContent = ({
58
59
  const {
59
60
  originalContentUrl = '',
60
61
  type,
62
+ aspectRatio: contentAspectRatio = '',
61
63
  selectedActionType = '',
62
64
  actionLabel = '',
63
65
  actionContent = '',
64
66
  } = content;
65
- if (type === 'image_carousel') {
67
+ if (type === 'carousel') {
66
68
  updateImageStatus(!!originalContentUrl);
67
69
  updateImageSrc(originalContentUrl);
68
70
  updateActionType(selectedActionType);
69
71
  updateActionLabel(actionLabel);
70
72
  updateActionContent(actionContent);
73
+ if (!!contentAspectRatio) updateAspectRatio(contentAspectRatio);
71
74
  }
72
75
  }, [content]);
73
76
 
@@ -76,13 +79,14 @@ export const LineImageCarouselContent = ({
76
79
  updateCarouselMessageState({
77
80
  activeIndex,
78
81
  originalContentUrl: imageSrc,
82
+ aspectRatio,
79
83
  selectedActionType,
80
84
  actionContent,
81
85
  actionLabel,
82
86
  actionContentErrorMessage,
83
87
  actionLabelErrorMessage,
84
88
  index,
85
- type: 'image_carousel',
89
+ type: 'carousel',
86
90
  messageType: 'originalContentUrl',
87
91
  });
88
92
  }
@@ -120,10 +124,11 @@ export const LineImageCarouselContent = ({
120
124
  selectedActionType,
121
125
  actionContent,
122
126
  actionLabel,
127
+ aspectRatio,
123
128
  actionContentErrorMessage,
124
129
  actionLabelErrorMessage,
125
130
  index,
126
- type: 'image_carousel',
131
+ type: 'carousel',
127
132
  messageType: 'originalContentUrl',
128
133
  });
129
134
  }
@@ -140,10 +145,12 @@ export const LineImageCarouselContent = ({
140
145
  },
141
146
  type,
142
147
  } = data;
143
- if (incorrectFile || size > LINE_IMG_SIZE || height > LINE_IMG_HEIGHT || width > LINE_IMG_WIDTH || height / width !== 1) {
148
+ if (incorrectFile || size > LINE_IMG_SIZE || height > LINE_IMG_HEIGHT || width > LINE_IMG_WIDTH || height > (width * 3)) {
144
149
  updateImageErrorMessage(formatMessage(messages.lineImageIncorrectSize));
145
150
  } else {
146
151
  updateImageErrorMessage('');
152
+ const aspectRatio1 = calculateAspectRatio(width, height);
153
+ updateAspectRatio(aspectRatio1);
147
154
  actions.uploadAsset(
148
155
  data.file,
149
156
  data.type,
@@ -153,7 +160,18 @@ export const LineImageCarouselContent = ({
153
160
  }
154
161
  }
155
162
 
156
-
163
+ const calculateGCD = (width, height) => {
164
+ while (height !== 0 ) {
165
+ let reminder = width % height;
166
+ width = height;
167
+ height = reminder;
168
+ }
169
+ return Math.abs(width);
170
+ };
171
+ const calculateAspectRatio = (width, height) => {
172
+ const absValue = calculateGCD(width, height);
173
+ return `${width / absValue}:${height / absValue}`;
174
+ }
157
175
 
158
176
  const uploadImages = (e, { files }) => {
159
177
  if (e) {
@@ -240,10 +258,11 @@ export const LineImageCarouselContent = ({
240
258
  selectedActionType,
241
259
  actionContent,
242
260
  actionLabel,
261
+ aspectRatio,
243
262
  actionContentErrorMessage,
244
263
  actionLabelErrorMessage,
245
264
  index,
246
- type: 'image_carousel',
265
+ type: 'carousel',
247
266
  messageType: 'originalContentUrl',
248
267
  });
249
268
  }
@@ -303,10 +322,11 @@ export const LineImageCarouselContent = ({
303
322
  const imageHeight = get(imageTemplate, 'metaInfo.height');
304
323
  const imageWidth = get(imageTemplate, 'metaInfo.width');
305
324
  const imageSize = get(imageTemplate, 'metaInfo.file_size');
325
+ const aspectRatio1 = calculateAspectRatio(imageWidth, imageHeight);
306
326
  updateDrawerRequirement(false);
307
327
  if (
308
328
  !ALLOWED_EXTENSIONS_REGEX.test(image)
309
- || imageHeight / imageWidth !== 1
329
+ // || imageHeight / imageWidth !== 1
310
330
  || imageHeight > LINE_IMG_HEIGHT
311
331
  || imageWidth > LINE_IMG_WIDTH
312
332
  || imageSize > LINE_IMG_SIZE
@@ -316,17 +336,19 @@ export const LineImageCarouselContent = ({
316
336
  updateImageErrorMessage('');
317
337
  updateImageStatus(true);
318
338
  updateImageSrc(image);
339
+ updateAspectRatio(aspectRatio1);
319
340
  updateCarouselMessageState({
320
341
  activeIndex,
321
342
  isError: !image || isImageError,
322
343
  originalContentUrl: image,
344
+ aspectRatio: aspectRatio1,
323
345
  selectedActionType,
324
346
  actionContent,
325
347
  actionLabel,
326
348
  actionContentErrorMessage,
327
349
  actionLabelErrorMessage,
328
350
  index,
329
- type: 'image_carousel',
351
+ type: 'carousel',
330
352
  messageType: 'originalContentUrl',
331
353
  });
332
354
  }
@@ -383,10 +405,11 @@ export const LineImageCarouselContent = ({
383
405
  selectedActionType,
384
406
  actionContent,
385
407
  actionLabel: value,
408
+ aspectRatio,
386
409
  actionContentErrorMessage,
387
410
  actionLabelErrorMessage,
388
411
  index,
389
- type: 'image_carousel',
412
+ type: 'carousel',
390
413
  messageType: 'originalContentUrl',
391
414
  });
392
415
  }
@@ -400,10 +423,11 @@ export const LineImageCarouselContent = ({
400
423
  selectedActionType: type,
401
424
  actionContent: '',
402
425
  actionLabel,
426
+ aspectRatio,
403
427
  actionContentErrorMessage,
404
428
  actionLabelErrorMessage,
405
429
  index,
406
- type: 'image_carousel',
430
+ type: 'carousel',
407
431
  messageType: 'originalContentUrl',
408
432
  });
409
433
  }
@@ -430,10 +454,11 @@ export const LineImageCarouselContent = ({
430
454
  selectedActionType,
431
455
  actionContent: value,
432
456
  actionLabel,
457
+ aspectRatio,
433
458
  actionContentErrorMessage,
434
459
  actionLabelErrorMessage,
435
460
  index,
436
- type: 'image_carousel',
461
+ type: 'carousel',
437
462
  messageType: 'originalContentUrl',
438
463
  });
439
464
  }