@capillarytech/creatives-library 7.16.3 → 7.16.5

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.16.3",
4
+ "version": "7.16.5",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
package/utils/common.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import _ from 'lodash';
2
2
  import { Auth } from '@capillarytech/cap-ui-utils';
3
+
3
4
  import {
4
5
  STORE2DOOR_PLUS_ENABLED,
5
6
  TRAI_DLT,
@@ -263,15 +264,23 @@ export const isTraiDLTEnable = (isFullMode, smsRegister) => {
263
264
  return isTraiDltFeature;
264
265
  };
265
266
 
266
- export function createNewFile(fileObject) {
267
- const encodedName = fileObject.name.replace(/(.+?)(\.[^.]*$|$)/, (match, name, extension) => {
267
+ /* function used to encode filename and check file name
268
+ pattern based on the given regex */
269
+ export function createNewFile(Files, allowedExtensionsRegex) {
270
+ const fileObject = Files[0];
271
+ let incorrectFile = false;
272
+
273
+ if (allowedExtensionsRegex && !allowedExtensionsRegex.test(fileObject?.name)) {
274
+ incorrectFile = true;
275
+ return [fileObject, incorrectFile];
276
+ }
277
+ const encodedName = fileObject?.name.replace(/(.+?)(\.[^.]*$|$)/, (match, name, extension) => {
268
278
  const filename = encodeURIComponent(name);
269
279
  return filename + extension;
270
280
  });
271
281
  const { type, ...rest } = fileObject;
272
282
  const newFile = new File([fileObject], encodedName, { type, ...rest });
273
283
  newFile.uid = fileObject.uid;
274
-
275
- return newFile;
284
+ return [newFile, incorrectFile];
276
285
  }
277
286
 
@@ -11,21 +11,43 @@ describe('Test v2common container', () => {
11
11
  });
12
12
 
13
13
  describe('Test createNewFile function', () => {
14
+ const allowedExtensionsRegex = /(\.png|\.jpg)$/i;
15
+ const tempFile = [{
16
+ name: '#image.png',
17
+ type: 'image/jpeg',
18
+ size: 2048,
19
+ uid: 'def456',
20
+ }];
21
+ const expectedFile = new File([tempFile], '%23image.png', {
22
+ type: 'image/jpeg',
23
+ size: 2048,
24
+ uid: 'def456',
25
+ });
14
26
  it('should create a new file with encoded name', () => {
15
- const tempFile = {
16
- name: '#image.png',
17
- type: 'image/jpeg',
27
+ const [resultFile, incorrectFile] = createNewFile(tempFile, allowedExtensionsRegex);
28
+ expect(resultFile).toMatchObject(expectedFile);
29
+ expect(incorrectFile).toBe(false);
30
+ });
31
+ it('should return incorrect file true', () => {
32
+ const tempFileWrong = [{
33
+ name: '#song.mov',
34
+ type: 'video/mov',
18
35
  size: 2048,
19
- uid: 'def456',
20
- };
36
+ uid: 'def4516',
37
+ }];
21
38
 
22
- const expectedFile = new File([tempFile], '%23image.png', {
23
- type: 'image/jpeg',
39
+ const expectedFileWrong = new File([tempFileWrong], '%23song.mov', {
40
+ type: 'video/mov',
24
41
  size: 2048,
25
- uid: 'def456',
42
+ uid: 'def4516',
26
43
  });
27
- const result = createNewFile(tempFile);
28
- expect(result).toMatchObject(expectedFile);
44
+ const [resultFile, incorrectFile] = createNewFile(tempFileWrong, allowedExtensionsRegex);
45
+ expect(resultFile).toMatchObject(expectedFileWrong);
46
+ expect(incorrectFile).toBe(true);
47
+ });
48
+ it('should return only the updated file as the validation is handled differently for some channels', () => {
49
+ const resultFile = createNewFile(tempFile)[0];
50
+ expect(resultFile).toMatchObject(expectedFile);
29
51
  });
30
52
  });
31
53
 
@@ -70,12 +70,7 @@ function CapDocumentUpload(props) {
70
70
  e.preventDefault();
71
71
  }
72
72
  const _URL = window.URL || window.webkitURL;
73
- let incorrectFile = false;
74
- const tempFile = files[0];
75
- if (!allowedExtensionsRegex.test(tempFile?.name)) {
76
- incorrectFile = true;
77
- }
78
- const file = createNewFile(tempFile);
73
+ const [file, incorrectFile] = createNewFile(files, allowedExtensionsRegex);
79
74
  const doc = new FileReader();
80
75
  doc.src = _URL.createObjectURL(file);
81
76
  const fileParams = {
@@ -88,7 +83,6 @@ function CapDocumentUpload(props) {
88
83
  ...whatsappDocParams,
89
84
  whatsappDocImg: data?.image,
90
85
  whatsappDocPages: data?.numberOfPages,
91
- nameEncoded: true,
92
86
  })
93
87
  );
94
88
  submitAction({file, type: 'document', fileParams}, incorrectFile);
@@ -79,12 +79,7 @@ function CapImageUpload(props) {
79
79
  e.preventDefault();
80
80
  }
81
81
  const _URL = window.URL || window.webkitURL;
82
- let incorrectFile = false;
83
- const tempFile = files[0];
84
- if (!allowedExtensionsRegex.test(tempFile?.name)) {
85
- incorrectFile = true;
86
- }
87
- const file = createNewFile(tempFile);
82
+ const [file, incorrectFile] = createNewFile(files, allowedExtensionsRegex);
88
83
  const img = new Image();
89
84
  img.src = _URL.createObjectURL(file);
90
85
  img.onload = () => {
@@ -64,12 +64,7 @@ function CapVideoUpload(props) {
64
64
  e.preventDefault();
65
65
  }
66
66
  const _URL = window.URL || window.webkitURL;
67
- let incorrectFile = false;
68
- const tempFile = files[0];
69
- if (!allowedExtensionsRegex.test(tempFile?.name)) {
70
- incorrectFile = true;
71
- }
72
- const file = createNewFile(tempFile);
67
+ const [file, incorrectFile] = createNewFile(files, allowedExtensionsRegex);
73
68
  const video = new FileReader();
74
69
  video.src = _URL.createObjectURL(file);
75
70
  const fileParams = {
@@ -2169,7 +2169,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
2169
2169
  this.callChildEvent({tempFile, type: 'wrong file'}, val, val.submitAction);
2170
2170
  }
2171
2171
  }
2172
- const file = createNewFile(tempFile);
2172
+ const file = createNewFile(files)[0];
2173
2173
  const img = new Image();
2174
2174
  img.src = _URL.createObjectURL(file);
2175
2175
  img.onload = () => {
@@ -13,8 +13,10 @@ import { FormattedMessage, injectIntl, intlShape } from 'react-intl';
13
13
  import { createStructuredSelector } from 'reselect';
14
14
  import moment from "moment";
15
15
  import _ from "lodash";
16
+ import Bugsnag from '@bugsnag/js';
16
17
  import { CapHeading, CapHeader, CapInput, CapButton, CapSpin, CapIcon, CapDropdown, CapMenu, CapCustomCard, CapSlideBox, CapLabel, CapIllustration} from '@capillarytech/cap-ui-library';
17
18
  import { Popover } from 'antd';
19
+ import { createNewFile } from '../../../utils/common';
18
20
  import makeSelectGallery from './selectors';
19
21
  import messages from './messages';
20
22
  import * as actions from './actions';
@@ -232,7 +234,7 @@ export class Gallery extends React.Component { // eslint-disable-line react/pref
232
234
  for (const file in files) {
233
235
  if (files.hasOwnProperty(file)) {
234
236
  const tempFile = files[file];
235
- const uploadFile = commonUtil.createNewFile(tempFile);
237
+ const [uploadFile] = createNewFile([tempFile]);
236
238
  const img = new Image();
237
239
  const that = this;
238
240
  img.src = _URL.createObjectURL(uploadFile);
@@ -396,17 +398,22 @@ export class Gallery extends React.Component { // eslint-disable-line react/pref
396
398
  const by = commonUtil.getUserNameById(parseInt(this.state.selectedAsset.updatedBy, 10), commonUtil.getMergedUserList(this.props.Gallery.userList));
397
399
  const width = this.state.selectedAsset.metaInfo.width;
398
400
  const height = this.state.selectedAsset.metaInfo.height;
401
+ /*
402
+ splitting the name on . and verifying
403
+ whether the filename is already encoded or not,
404
+ if yes decoding it ,to be shown on ui
405
+ */
399
406
  const nameParts = this.state.selectedAsset.name.split('.');
400
- console.log(this.state.selectedAsset);
401
- console.log(nameParts);
402
407
  let updatedTitle = this.state.selectedAsset.name;
403
- console.log(nameParts[0]);
404
408
  try {
405
409
  if (encodeURIComponent(decodeURIComponent(nameParts[0])) === nameParts[0]) {
406
410
  updatedTitle = `${decodeURIComponent(nameParts[0])}.${nameParts[1]}`;
407
411
  }
408
412
  } catch (error) {
409
- console.log('Error decoding the string:', error);
413
+ Bugsnag.leaveBreadcrumb("Error decoding the string:", error);
414
+ Bugsnag.notify(error, (event) => {
415
+ event.severity = "error";
416
+ });
410
417
  }
411
418
  const slideboxHeader = (<div>
412
419
  <CapHeader
@@ -172,12 +172,7 @@ export const LineImage = ({
172
172
  e.preventDefault();
173
173
  }
174
174
  const _URL = window.URL || window.webkitURL;
175
- let incorrectFile = false;
176
- const tempFile = files[0];
177
- if (!ALLOWED_EXTENSIONS_REGEX.test(tempFile?.name)) {
178
- incorrectFile = true;
179
- }
180
- const file = createNewFile(tempFile);
175
+ const [file, incorrectFile] = createNewFile(files, ALLOWED_EXTENSIONS_REGEX);
181
176
  const img = new Image();
182
177
  img.src = _URL.createObjectURL(file);
183
178
  img.onload = () => {
@@ -241,7 +241,7 @@ export const LineImageMap = ({
241
241
  incorrectFile = true;
242
242
  }
243
243
  }
244
- const file = createNewFile(tempFile);
244
+ const [file] = createNewFile(files);
245
245
  const img = new Image();
246
246
  img.src = _URL.createObjectURL(file);
247
247
  img.onload = () => {
@@ -255,12 +255,7 @@ export const LineVideo = ({
255
255
  e.preventDefault();
256
256
  }
257
257
  const _URL = window.URL || window.webkitURL;
258
- let incorrectFile = false;
259
- const tempFile = files[0];
260
- if (!ALLOWED_EXTENSIONS_REGEX.test(tempFile?.name)) {
261
- incorrectFile = true;
262
- }
263
- const file = createNewFile(tempFile);
258
+ const [file, incorrectFile] = createNewFile(files, ALLOWED_EXTENSIONS_REGEX);
264
259
  const video = new FileReader();
265
260
  video.src = _URL.createObjectURL(file);
266
261
  const fileParams = {
@@ -331,13 +331,8 @@ const Viber = (props) => {
331
331
  e.preventDefault();
332
332
  }
333
333
  const _URL = window.URL || window.webkitURL;
334
- let incorrectFile = false;
335
- const tempFile = files[0];
336
- if (!ALLOWED_EXTENSIONS_REGEX.test(tempFile?.name)) {
337
- incorrectFile = true;
338
- }
334
+ const [file, incorrectFile] = createNewFile(files, ALLOWED_EXTENSIONS_REGEX);
339
335
  const img = new Image();
340
- const file = createNewFile(tempFile);
341
336
  img.src = _URL.createObjectURL(file);
342
337
  img.onload = () => {
343
338
  const fileParams = {
@@ -666,6 +661,10 @@ const Viber = (props) => {
666
661
  if (buttonURLErrorMessage) {
667
662
  return true;
668
663
  }
664
+ //if template title is empty
665
+ if (messageTitle.trim() === '') {
666
+ return true;
667
+ }
669
668
  return false;
670
669
  };
671
670