@capillarytech/creatives-library 7.14.14 → 7.14.16

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/config/app.js CHANGED
@@ -17,7 +17,6 @@ const config = {
17
17
  },
18
18
  development: {
19
19
  api_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/arya/api/v1/creatives',
20
- //api_endpoint: 'http://localhost:2022/arya/api/v1/creatives',
21
20
  campaigns_api_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/iris/v2/campaigns',
22
21
  campaigns_api_org_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/iris/v2/org/campaign',
23
22
  auth_endpoint: 'https://crm-nightly-new.cc.capillarytech.com/arya/api/v1/auth',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "7.14.14",
4
+ "version": "7.14.16",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -11,7 +11,7 @@ import { injectIntl, FormattedMessage, intlShape} from 'react-intl';
11
11
  import { isEmpty, get } from 'lodash';
12
12
  import './index.scss';
13
13
  import messages from './messages';
14
- const PDFJS = require("pdfjs-dist");
14
+ import { convertPdfToImages } from '../WhatsappDocumentPreview/index';
15
15
 
16
16
  function CapDocumentUpload(props) {
17
17
  const {
@@ -32,10 +32,6 @@ function CapDocumentUpload(props) {
32
32
  supportedFormat,
33
33
  supportedMaxSize,
34
34
  } = props;
35
- const {
36
- formatMessage,
37
- } = intl || {};
38
-
39
35
 
40
36
  useEffect(() => {
41
37
  const docDataObj = documentData[`uploadedAssetData${index}`];
@@ -54,6 +50,7 @@ function CapDocumentUpload(props) {
54
50
 
55
51
  const {CapHeadingSpan} = CapHeading;
56
52
 
53
+ //renders the preview for document
57
54
  const DocPreviewComponent = useCallback(
58
55
  () => (
59
56
  <div className={`upload uploaded-container ${props.ifError ? 'error' : ''}`}>
@@ -65,6 +62,7 @@ function CapDocumentUpload(props) {
65
62
 
66
63
  const WithLabel = LabelHOC(DocPreviewComponent);
67
64
 
65
+ //this function gets executed on the upload of a document
68
66
  const uploadDocuments = useCallback((e, {files}) => {
69
67
  if (e) {
70
68
  e.preventDefault();
@@ -80,47 +78,21 @@ function CapDocumentUpload(props) {
80
78
  const fileParams = {
81
79
  error: false, // checking error based on file size
82
80
  };
83
- convertPdfToImages(file);
81
+ const result = convertPdfToImages(file);
82
+ result.then((data) =>
83
+ setWhatsappDocParams(
84
+ {
85
+ ...whatsappDocParams,
86
+ whatsappDocImg: data?.image,
87
+ whatsappDocPages: data?.numberOfPages,
88
+ })
89
+ );
84
90
  submitAction({file, type: 'document', fileParams}, incorrectFile);
85
91
  if (e) {
86
92
  const event = e;
87
93
  event.target.value = null;
88
94
  }
89
95
  }, []);
90
- const readFileData = (file) => new Promise((resolve, reject) => {
91
- const reader = new FileReader();
92
- reader.onload = (e) => {
93
- resolve(e.target.result);
94
- };
95
- reader.onerror = (err) => {
96
- reject(err);
97
- };
98
- reader.readAsDataURL(file);
99
- });
100
- const convertPdfToImages = async (file) => {
101
- const data = await readFileData(file);
102
- return PDFJS.getDocument(data)
103
- .then(async function (pdf) {
104
- const numberOfPages = pdf.numPages;
105
- const canvas = document.createElement("canvas");
106
- const page = await pdf.getPage(1);
107
- const viewport = page.getViewport({ scale: 1 });
108
- const context = canvas.getContext("2d");
109
- canvas.height = viewport.height;
110
- canvas.width = viewport.width;
111
- await page.render({ canvasContext: context, viewport: viewport }).promise;
112
- const image = (canvas.toDataURL('image/jpeg', 1.0));
113
- canvas.remove();
114
- setWhatsappDocParams({
115
- ...whatsappDocParams,
116
- whatsappDocImg: image,
117
- whatsappDocPages: numberOfPages,
118
- });
119
- return image;
120
- })
121
- .catch((error) => Promise.reject(error));
122
- };
123
-
124
96
  const submitAction = useCallback((data, incorrectFile) => {
125
97
  const {
126
98
  file,
@@ -129,13 +101,13 @@ function CapDocumentUpload(props) {
129
101
  const { size } = file || {};
130
102
  const { error } = fileParams || {};
131
103
  if (incorrectFile || size > documentSize || error) {
132
- updateDocErrorMessage(formatMessage(messages.docErrorDesc));
104
+ updateDocErrorMessage(<FormattedMessage {...messages.docErrorDesc} />);
133
105
  } else {
134
106
  updateDocErrorMessage('');
135
107
  uploadAsset(
136
- data.file,
108
+ file,
137
109
  data.type,
138
- data.fileParams,
110
+ fileParams,
139
111
  index,
140
112
  );
141
113
  }
@@ -145,11 +117,13 @@ function CapDocumentUpload(props) {
145
117
  uploadDocuments(undefined, {files: [uploadData.file]});
146
118
  }, []);
147
119
 
120
+ //this function gets called when reUpload button is clicked
148
121
  const onReUpload = useCallback(() => {
149
122
  updateDocumentSrc('');
150
123
  updateOnReUpload();
151
124
  }, []);
152
125
 
126
+ //renders the dragger component to upload the document
153
127
  const getDocumentSection = useCallback(() => {
154
128
  if (documentSrc === "") {
155
129
  return (
@@ -195,6 +169,8 @@ function CapDocumentUpload(props) {
195
169
  className="input-div"
196
170
  id="fileName"
197
171
  type="file"
172
+ //passing event and files to the uploadDocuments function as
173
+ //there are other instance where event is undefined and we have files
198
174
  onChange={(e) => uploadDocuments(e, { files: e.target.files })}
199
175
  accept={supportedExtensions || ".pdf"}
200
176
  />
@@ -12,7 +12,7 @@ $classPrefix: cap-custom-document-upload;
12
12
  .image-info-wrapper {
13
13
  display: flex;
14
14
  justify-content: space-between;
15
- margin-top: 8px;
15
+ margin-top: $CAP_SPACE_08;
16
16
  }
17
17
  .whatsapp-background div {
18
18
  background: $CAP_G10;
@@ -38,18 +38,18 @@ $classPrefix: cap-custom-document-upload;
38
38
  background-color: $CAP_G09;
39
39
  display: flex;
40
40
  .cap-image-v2 {
41
- margin: 6px 4px;
41
+ margin: $CAP_SPACE_06 $CAP_SPACE_04;
42
42
  width: 32px;
43
43
  height: 32px;
44
44
  }
45
45
  .pdf-info {
46
- margin: 8px 4px;
46
+ margin: $CAP_SPACE_08 $CAP_SPACE_04;
47
47
  max-width: 114px;
48
48
  .pdf-info-sec {
49
- color: #5f6d85;
50
- font-size: 8px;
49
+ color: $CAP_G03;
50
+ font-size: $CAP_SPACE_08;
51
51
  font-weight: 400;
52
- line-height: 12px;
52
+ line-height: $CAP_SPACE_12;
53
53
  }
54
54
  .pdf-name-div {
55
55
  display: flex;
@@ -7,6 +7,7 @@ import {
7
7
  screen,
8
8
  } from '../../../utils/test-utils';
9
9
  import CapDocumentUpload from '../index';
10
+ import { mockData } from './mockData';
10
11
 
11
12
  const ComponentToRender = injectIntl(CapDocumentUpload);
12
13
  const renderComponent = (props) => render(
@@ -49,21 +50,7 @@ describe("test for document upload", () => {
49
50
  it("test for cap document upload 1", () => {
50
51
  const props1 = {
51
52
  ...props,
52
- documentData: {
53
- uploadedAssetData0: {
54
- file_size: 134532,
55
- name: 'sample.pdf',
56
- secure_file_path: "https://www.africau.edu/images/default/sample.pdf",
57
- karixFileHandle: 'abcd',
58
- },
59
- },
60
- documentSrc: "https://www.africau.edu/images/default/sample.pdf",
61
- whatsappDocParams: {
62
- whatsappDocName: 'sample.pdf',
63
- whatsappDocSize: 134532,
64
- whatsappDocPages: 2,
65
- whatsappDocImg: 'https://play-lh.googleusercontent.com/BkRfMfIRPR9hUnmIYGDgHHKjow-g18-ouP6B2ko__VnyUHSi1spcc78UtZ4sVUtBH4g',
66
- },
53
+ ...mockData,
67
54
  };
68
55
  renderComponent(props1);
69
56
  });
@@ -0,0 +1,17 @@
1
+ export const mockData = {
2
+ documentData: {
3
+ uploadedAssetData0: {
4
+ file_size: 134532,
5
+ name: 'sample.pdf',
6
+ secure_file_path: "https://www.africau.edu/images/default/sample.pdf",
7
+ karixFileHandle: 'abcd',
8
+ },
9
+ },
10
+ documentSrc: "https://www.africau.edu/images/default/sample.pdf",
11
+ whatsappDocParams: {
12
+ whatsappDocName: 'sample.pdf',
13
+ whatsappDocSize: 134532,
14
+ whatsappDocPages: 2,
15
+ whatsappDocImg: 'https://play-lh.googleusercontent.com/BkRfMfIRPR9hUnmIYGDgHHKjow-g18-ouP6B2ko__VnyUHSi1spcc78UtZ4sVUtBH4g',
16
+ },
17
+ };
@@ -36,6 +36,8 @@ function CapVideoUpload(props) {
36
36
  videoData,
37
37
  channel,
38
38
  errorMessage,
39
+ showVideoNameAndDuration = true,
40
+ formClassName = 'video-form',
39
41
  } = props;
40
42
  const [isVideoError, updateVideoErrorMessage] = useState(false);
41
43
  const [isVideo, updateVideoStatus] = useState(false);
@@ -242,7 +244,7 @@ function CapVideoUpload(props) {
242
244
  <FormattedMessage {...messages.imageReUpload} />
243
245
  </CapButton>
244
246
  </div>
245
- <div className="video-panel">
247
+ <div className={showVideoNameAndDuration ? 'video-panel' : 'video-panel-wp'}>
246
248
  <video
247
249
  width="230"
248
250
  poster={previewUrl}
@@ -257,14 +259,16 @@ function CapVideoUpload(props) {
257
259
  >
258
260
  <source src={videoSrc} type="video/mp4" />
259
261
  </video>
260
- <div className="video-info">
261
- <CapHeading type="h6">
262
- {videoName}
263
- </CapHeading>
264
- <CapHeading type="h6">
265
- {videoDuration}
266
- </CapHeading>
267
- </div>
262
+ {showVideoNameAndDuration &&
263
+ <div className="video-info">
264
+ <CapHeading type="h6">
265
+ {videoName}
266
+ </CapHeading>
267
+ <CapHeading type="h6">
268
+ {videoDuration}
269
+ </CapHeading>
270
+ </div>
271
+ }
268
272
  </div>
269
273
  </Fragment>
270
274
  );
@@ -272,7 +276,7 @@ function CapVideoUpload(props) {
272
276
  return (
273
277
  <CapSpin spinning={isSpinning}>
274
278
  <div style={style} className="cap-custom-video-upload">
275
- <form encType="multipart/form-data" id={`form`} className={channel !== WHATSAPP ? "video-form" : ""}>
279
+ <form encType="multipart/form-data" id={`form`} className={formClassName}>
276
280
  <input
277
281
  key={`videoFile`}
278
282
  style={{ display: 'none' }}
@@ -320,6 +324,7 @@ CapVideoUpload.propTypes = {
320
324
  allowedExtensionsRegex: PropTypes.string,
321
325
  videoSize: PropTypes.string,
322
326
  intl: intlShape,
327
+ showVideoNameAndDuration: PropTypes.bool,
323
328
  uploadAsset: PropTypes.func,
324
329
  uploadedAssetList: PropTypes.object,
325
330
  style: PropTypes.any,
@@ -328,6 +333,7 @@ CapVideoUpload.propTypes = {
328
333
  videoData: PropTypes.object,
329
334
  channel: PropTypes.string,
330
335
  errorMessage: PropTypes.string,
336
+ formClassName: PropTypes.string,
331
337
  };
332
338
 
333
339
  export default injectIntl(CapVideoUpload);
@@ -44,6 +44,11 @@ $classPrefix: cap-custom-video-upload;
44
44
  justify-content: center;
45
45
  margin: 4px;
46
46
  }
47
+ .video-panel-wp {
48
+ display: flex;
49
+ justify-content: center;
50
+ margin: 4px;
51
+ }
47
52
  .video-panel {
48
53
  display: flex;
49
54
  }
@@ -291,6 +291,9 @@
291
291
  margin-bottom: 4px;
292
292
  .pdf-img-box {
293
293
  width: 153px;
294
+ img {
295
+ width: 100%;
296
+ }
294
297
  }
295
298
  .pdf-label{
296
299
  width: 153px;
@@ -0,0 +1,33 @@
1
+ const PDFJS = require("pdfjs-dist");
2
+ const readFileData = (file) => new Promise((resolve, reject) => {
3
+ const reader = new FileReader();
4
+ reader.onload = (e) => {
5
+ resolve(e.target.result);
6
+ };
7
+ reader.onerror = (err) => {
8
+ reject(err);
9
+ };
10
+ reader.readAsDataURL(file);
11
+ });
12
+ //function to convert first page of pdf to image for the thumbnail preview
13
+ export const convertPdfToImages = async (file) => {
14
+ const data = await readFileData(file);
15
+ const encoderQuality = 1.0;
16
+ return PDFJS.getDocument(data)
17
+ .then(async function (pdf) {
18
+ const numberOfPages = pdf.numPages;
19
+ const canvas = document.createElement("canvas");
20
+ //fetch first page from pdf
21
+ const page = await pdf.getPage(1);
22
+ const viewport = page.getViewport({ scale: 1 });
23
+ const context = canvas.getContext("2d");
24
+ canvas.height = viewport.height;
25
+ canvas.width = viewport.width;
26
+ await page.render({ canvasContext: context, viewport: viewport }).promise;
27
+ //return the base64 format image that we use for preview
28
+ const image = (canvas.toDataURL('image/jpeg', encoderQuality));
29
+ canvas.remove();
30
+ return Promise.resolve({image, numberOfPages});
31
+ })
32
+ .catch((error) => Promise.reject(error));
33
+ };
@@ -384,26 +384,21 @@ export class Creatives extends React.Component {
384
384
  whatsappMedia = {},
385
385
  } = {},
386
386
  } = templateData;
387
- let mediaParams = {};
387
+ const mediaParams = {};
388
+ const { url = '', previewUrl = '', docParams = {}} = whatsappMedia;
388
389
  switch (mediaType) {
389
390
  case (WHATSAPP_MEDIA_TYPES.IMAGE):
390
- mediaParams = {
391
- imageUrl: whatsappMedia?.url,
392
- };
391
+ mediaParams.imageUrl = url;
393
392
  break;
394
393
  case (WHATSAPP_MEDIA_TYPES.VIDEO):
395
- mediaParams = {
396
- videoUrl: whatsappMedia?.url,
397
- videoPreviewImg: whatsappMedia?.previewUrl,
398
- };
394
+ mediaParams.videoUrl = url;
395
+ mediaParams.videoPreviewImg = previewUrl;
399
396
  break;
400
397
  case (WHATSAPP_MEDIA_TYPES.DOCUMENT):
401
- mediaParams = {
402
- documentUrl: whatsappMedia?.url,
403
- whatsappDocParams: {
404
- ...whatsappMedia?.docParams,
405
- whatsappDocImg: whatsappMedia?.previewUrl,
406
- },
398
+ mediaParams.documentUrl = url;
399
+ mediaParams.whatsappDocParams = {
400
+ ...docParams,
401
+ whatsappDocImg: previewUrl,
407
402
  };
408
403
  break;
409
404
  default:
@@ -659,28 +654,25 @@ export class Creatives extends React.Component {
659
654
  varMapped[`{{${Object.keys(varMapped).length + 1}}}_unsubscribe`] =
660
655
  "{{unsubscribe}}";
661
656
  }
662
- let whatsappMedia = {};
657
+ const whatsappMedia = {};
658
+ const {
659
+ whatsappDocName = '', whatsappDocSize, whatsappDocPages, whatsappDocImg = ''
660
+ } = whatsappDocParams;
663
661
  switch (mediaType) {
664
662
  case (WHATSAPP_MEDIA_TYPES.IMAGE):
665
- whatsappMedia = {
666
- url: imageUrl,
667
- };
663
+ whatsappMedia.url = imageUrl;
668
664
  break;
669
665
  case (WHATSAPP_MEDIA_TYPES.VIDEO):
670
- whatsappMedia = {
671
- url: videoUrl,
672
- previewUrl: videoPreviewImg,
673
- };
666
+ whatsappMedia.url = videoUrl;
667
+ whatsappMedia.previewUrl = videoPreviewImg;
674
668
  break;
675
669
  case (WHATSAPP_MEDIA_TYPES.DOCUMENT):
676
- whatsappMedia = {
677
- url: documentUrl,
678
- previewUrl: whatsappDocParams?.whatsappDocImg,
679
- docParams: {
680
- whatsappDocName: whatsappDocParams?.whatsappDocName,
681
- whatsappDocSize: whatsappDocParams?.whatsappDocSize,
682
- whatsappDocPages: whatsappDocParams?.whatsappDocPages,
683
- },
670
+ whatsappMedia.url = documentUrl;
671
+ whatsappMedia.previewUrl = whatsappDocImg;
672
+ whatsappMedia.docParams = {
673
+ whatsappDocName,
674
+ whatsappDocSize,
675
+ whatsappDocPages,
684
676
  };
685
677
  break;
686
678
  default:
@@ -1067,7 +1067,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1067
1067
  break;
1068
1068
  }
1069
1069
  case WHATSAPP: {
1070
- const { whatsappImageSrc = '', templateMsg, docPreview, whatsappVideoSrc = ''} = getWhatsappContent(template);
1070
+ const { whatsappImageSrc = '', templateMsg, docPreview, whatsappVideoPreviewImg = ''} = getWhatsappContent(template);
1071
1071
  templateData.title = (
1072
1072
  <CapRow>
1073
1073
  <CapLabel className="whatsapp-rcs-template-name">{template?.name}</CapLabel>
@@ -1079,17 +1079,16 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1079
1079
  {whatsappImageSrc && (
1080
1080
  <CapImage src={whatsappImageSrc} className="whatsapp-image" />
1081
1081
  )}
1082
- {whatsappVideoSrc && (
1082
+ {whatsappVideoPreviewImg && (
1083
1083
  <div className="video-preview">
1084
1084
  <CapImage
1085
- src={whatsappVideoSrc}
1085
+ src={whatsappVideoPreviewImg}
1086
1086
  className="whatsapp-image"
1087
1087
  />
1088
1088
  <div className="icon-position">
1089
1089
  <CapImage className="video-icon" src={videoPlay} />
1090
1090
  </div>
1091
1091
  </div>
1092
- // <CapImage src={whatsappVideoSrc} className="whatsapp-image" />
1093
1092
  )}
1094
1093
  <div className="whatsapp-doc">{docPreview}</div>
1095
1094
  <span
@@ -187,9 +187,8 @@ export const WHATSAPP_DOCUMENT_SIZE = 16000000; // 16MB
187
187
  export const HOST_TWILIO = 'twiliowhatsapptrans';
188
188
  export const HOST_KARIX = 'karixwhatsappbulk';
189
189
  export const SIZE_UNITS = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
190
- export const PAGES = "pages";
191
- export const PAGE = "page";
192
- export const PDF = "PDF";
190
+ export const DOCUMENT_FORMAT = 'PDF';
191
+ export const DOCUMENT_SIZE = '16 MB';
193
192
 
194
193
  export const LANGUAGE_OPTIONS = [
195
194
  {
@@ -64,6 +64,8 @@ import {
64
64
  ALLOWED_EXTENSIONS_DOCUMENT_REGEX,
65
65
  WHATSAPP_DOCUMENT_SIZE,
66
66
  WHATSAPP_VIDEO_SIZE,
67
+ DOCUMENT_FORMAT,
68
+ DOCUMENT_SIZE,
67
69
  } from './constants';
68
70
  import { DATE_DISPLAY_FORMAT, TIME_DISPLAY_FORMAT } from '../App/constants';
69
71
  import messages from './messages';
@@ -729,9 +731,10 @@ export const Whatsapp = (props) => {
729
731
 
730
732
  const setUpdateWhatsappVideoSrc = useCallback(
731
733
  (index, data) => {
734
+ const {videoSrc = '', previewUrl = ''} = data;
732
735
  setWhatsappVideoSrcAndPreview({
733
- whatsappVideoSrc: data?.videoSrc,
734
- whatsappVideoPreviewImg: data?.previewUrl,
736
+ whatsappVideoSrc: videoSrc,
737
+ whatsappVideoPreviewImg: previewUrl,
735
738
  });
736
739
  setKarixFileHandle(data?.fileHandle);
737
740
  updateAssetList(data);
@@ -783,8 +786,10 @@ export const Whatsapp = (props) => {
783
786
  onVideoUploadUpdateAssestList={setUpdateWhatsappVideoSrc}
784
787
  videoData={editData}
785
788
  className="cap-custom-video-upload"
789
+ formClassName={"whatsapp-video-upload"}
786
790
  channel={WHATSAPP}
787
791
  errorMessage={formatMessage(messages.videoErrorMessage)}
792
+ showVideoNameAndDuration={false}
788
793
  />
789
794
  );
790
795
  const docPreview = ( whatsappDocSource !== '' &&
@@ -807,8 +812,8 @@ export const Whatsapp = (props) => {
807
812
  setWhatsappDocParams={setWhatsappDocParams}
808
813
  channel={WHATSAPP}
809
814
  docPreview={docPreview}
810
- supportedMaxSize={'16 MB'}
811
- supportedFormat={'PDF'}
815
+ supportedMaxSize={DOCUMENT_SIZE}
816
+ supportedFormat={DOCUMENT_FORMAT}
812
817
  />
813
818
  );
814
819
 
@@ -950,6 +955,7 @@ export const Whatsapp = (props) => {
950
955
 
951
956
  const createPayload = () => {
952
957
  let mediaParams = {};
958
+ const { whatsappVideoSrc = '', whatsappVideoPreviewImg = '' } = whatsappVideoSrcAndPreview;
953
959
  switch (templateMediaType) {
954
960
  case WHATSAPP_MEDIA_TYPES.IMAGE:
955
961
  mediaParams = {
@@ -959,8 +965,8 @@ export const Whatsapp = (props) => {
959
965
  break;
960
966
  case WHATSAPP_MEDIA_TYPES.VIDEO:
961
967
  mediaParams = {
962
- videoUrl: getCdnUrl({url: whatsappVideoSrcAndPreview?.whatsappVideoSrc, channelName: WHATSAPP }),
963
- videoPreviewImg: getCdnUrl({url: whatsappVideoSrcAndPreview?.whatsappVideoPreviewImg, channelName: WHATSAPP}),
968
+ videoUrl: getCdnUrl({url: whatsappVideoSrc, channelName: WHATSAPP }),
969
+ videoPreviewImg: getCdnUrl({url: whatsappVideoPreviewImg, channelName: WHATSAPP}),
964
970
  karixFileHandle,
965
971
  };
966
972
  break;
@@ -1477,18 +1483,16 @@ export const Whatsapp = (props) => {
1477
1483
  )}
1478
1484
  </>
1479
1485
  );
1480
- let mediaPreview = {};
1486
+ const mediaPreview = {};
1481
1487
  switch (templateMediaType) {
1482
1488
  case WHATSAPP_MEDIA_TYPES.IMAGE:
1483
- mediaPreview = {whatsappImageSrc};
1489
+ mediaPreview.whatsappImageSrc = whatsappImageSrc;
1484
1490
  break;
1485
1491
  case WHATSAPP_MEDIA_TYPES.VIDEO:
1486
- mediaPreview = {
1487
- whatsappVideoPreviewImg: whatsappVideoSrcAndPreview?.whatsappVideoPreviewImg,
1488
- };
1492
+ mediaPreview.whatsappVideoPreviewImg = whatsappVideoSrcAndPreview?.whatsappVideoPreviewImg;
1489
1493
  break;
1490
1494
  case WHATSAPP_MEDIA_TYPES.DOCUMENT:
1491
- mediaPreview = {docPreview};
1495
+ mediaPreview.docPreview = docPreview;
1492
1496
  break;
1493
1497
  default:
1494
1498
  break;
@@ -300,6 +300,18 @@ export default defineMessages({
300
300
  id: `${prefix}.videoErrorMessage`,
301
301
  defaultMessage: 'Please upload the video with allowed file extension, size, dimension and aspect ratio',
302
302
  },
303
+ pdf: {
304
+ id: `${prefix}.pdf`,
305
+ defaultMessage: 'PDF',
306
+ },
307
+ pages: {
308
+ id: `${prefix}.pages`,
309
+ defaultMessage: 'pages',
310
+ },
311
+ page: {
312
+ id: `${prefix}.page`,
313
+ defaultMessage: 'page',
314
+ },
303
315
 
304
316
  afrikaans: {
305
317
  id: `${prefix}.afrikaans`,
@@ -61,7 +61,7 @@ Object {
61
61
  Hey {{1}}, Easier implementation, tracking, reporting and planning of promotions is now live! Check it out at {{2}}
62
62
  Click {{unsubscribe}} to unsubscribe
63
63
  </CapLabel>,
64
- "whatsappVideoSrc": "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/c9edc114-923b-4ac7-82d0-d6682213/1040",
64
+ "whatsappVideoPreviewImg": "https://crm-nightly-new-fileservice.s3.amazonaws.com/intouch_creative_assets/c9edc114-923b-4ac7-82d0-d6682213/1040",
65
65
  }
66
66
  `;
67
67
 
@@ -89,6 +89,7 @@ Object {
89
89
  <CapImage
90
90
  alt="upload-document-src"
91
91
  className="pdf-preview-img"
92
+ src=""
92
93
  />
93
94
  </div>
94
95
  <div
@@ -106,7 +107,9 @@ Object {
106
107
  <CapLabel
107
108
  className="pdf-name"
108
109
  type="label9"
109
- />
110
+ >
111
+
112
+ </CapLabel>
110
113
  <CapLabel
111
114
  type="label9"
112
115
  >
@@ -117,7 +120,19 @@ Object {
117
120
  className="pdf-info-sec"
118
121
  type="label1"
119
122
  >
120
- undefined page · 0 bytes · PDF
123
+ 0
124
+
125
+ <FormattedMessage
126
+ defaultMessage="page"
127
+ id="creatives.containersV2.Whatsapp.page"
128
+ values={Object {}}
129
+ />
130
+ · 0 bytes ·
131
+ <FormattedMessage
132
+ defaultMessage="PDF"
133
+ id="creatives.containersV2.Whatsapp.pdf"
134
+ values={Object {}}
135
+ />
121
136
  </CapLabel>
122
137
  </div>
123
138
  </div>
@@ -63,14 +63,16 @@ describe('Test utils', () => {
63
63
  whatsappDocPages: 2,
64
64
  whatsappDocImg: "https://play-lh.googleusercontent.com/BkRfMfIRPR9hUnmIYGDgHHKjow-g18-ouP6B2ko__VnyUHSi1spcc78UtZ4sVUtBH4g",
65
65
  };
66
- expect(getWhatsappDocPreview(whatsappDocParams)).toEqual(
67
- getWhatsappDocPreviewOutput,
66
+ expect(JSON.stringify(getWhatsappDocPreview(whatsappDocParams))).toEqual(
67
+ JSON.stringify(getWhatsappDocPreviewOutput),
68
68
  );
69
- expect(getWhatsappDocPreview({
69
+ //getWhatsappDocPreviewOutput is the output when page number is greater than 1
70
+ //getWhatsappDocPreviewOutput1 is the output when page number is equal than 1
71
+ expect(JSON.stringify(getWhatsappDocPreview({
70
72
  ...whatsappDocParams,
71
73
  whatsappDocPages: 1,
72
- })).toEqual(
73
- getWhatsappDocPreviewOutput1,
74
+ }))).toStrictEqual(
75
+ JSON.stringify(getWhatsappDocPreviewOutput1),
74
76
  );
75
77
  });
76
78
  });
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { FormattedMessage } from 'react-intl';
2
3
  import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
3
4
  import CapIcon from '@capillarytech/cap-ui-library/CapIcon';
4
5
  import CapImage from '@capillarytech/cap-ui-library/CapImage';
@@ -15,49 +16,46 @@ import {
15
16
  WHATSAPP_MEDIA_TYPES,
16
17
  HOST_KARIX,
17
18
  SIZE_UNITS,
18
- PAGES,
19
- PAGE,
20
- PDF,
21
19
  } from '../Whatsapp/constants';
22
20
  import './styles.scss';
23
21
  import pdfIcon from "../../assets/pdfIcon.svg";
22
+ import messages from './messages';
24
23
 
25
24
  export function bytesConversion(x) {
26
25
  // the function accepts bytes and convert in appropriate size following the,
27
26
  // l variable, this variable holds the size_unit index and displays the
28
27
  // respective size, eg : 5120 bytes gives 5 KB and 5242880 gives 5 MB
29
- let l;
30
- l = 0;
31
- let n;
32
- n = parseInt(x, 10) || 0;
28
+ let l = 0;
29
+ let n = parseInt(x, 10) || 0;
33
30
  // eslint-disable-next-line no-plusplus
34
31
  while (n >= 1024 && ++l) {
35
32
  n /= 1024;
36
33
  }
37
34
  return (`${n.toFixed(n < 10 && l > 0 ? 1 : 0)} ${SIZE_UNITS[l]}`);
38
35
  }
39
- export const getWhatsappDocPreview = (whatsappDocParams) =>
40
- (
36
+ export const getWhatsappDocPreview = (whatsappDocParams) => {
37
+ const { whatsappDocImg = '', whatsappDocName = '', whatsappDocPages = 0} = whatsappDocParams;
38
+ return (
41
39
  <>
42
40
  <div className="pdf-img-box">
43
- <CapImage src={whatsappDocParams?.whatsappDocImg} alt="upload-document-src" className="pdf-preview-img" />
41
+ <CapImage src={whatsappDocImg} alt="upload-document-src" className="pdf-preview-img" />
44
42
  </div>
45
43
  <div className="pdf-label">
46
44
  <CapImage src={pdfIcon} />
47
45
  <div className="pdf-info">
48
46
  <div className="pdf-name-div">
49
- <CapLabel type="label9" className="pdf-name">{whatsappDocParams?.whatsappDocName?.slice(0, -13)}</CapLabel>
47
+ <CapLabel type="label9" className="pdf-name">{whatsappDocName?.slice(0, -13)}</CapLabel>
50
48
  <CapLabel type="label9">{".pdf"}</CapLabel>
51
49
  </div>
52
50
  <CapLabel className="pdf-info-sec">
53
- {
54
- `${whatsappDocParams?.whatsappDocPages} ${whatsappDocParams?.whatsappDocPages > 1 ? PAGES : PAGE} · ${bytesConversion(whatsappDocParams?.whatsappDocSize)} · ${PDF}`
55
- }
51
+ {whatsappDocPages} {whatsappDocPages > 1 ? <FormattedMessage {...messages.pages} /> : <FormattedMessage {...messages.page} />}{` · ${bytesConversion(whatsappDocParams?.whatsappDocSize)} · `}
52
+ <FormattedMessage {...messages.pdf} />
56
53
  </CapLabel>
57
54
  </div>
58
55
  </div>
59
56
  </>
60
57
  );
58
+ };
61
59
 
62
60
  export const getWhatsappContent = (template, isPreview) => {
63
61
  const {
@@ -96,7 +94,7 @@ export const getWhatsappContent = (template, isPreview) => {
96
94
  mediaParams = {whatsappImageSrc: imageUrl};
97
95
  break;
98
96
  case WHATSAPP_MEDIA_TYPES.VIDEO:
99
- mediaParams = {whatsappVideoSrc: videoPreviewImg};
97
+ mediaParams = {whatsappVideoPreviewImg: videoPreviewImg};
100
98
  break;
101
99
  case WHATSAPP_MEDIA_TYPES.DOCUMENT:
102
100
  mediaParams = {docPreview: getWhatsappDocPreview(whatsappDocParams)};
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { FormattedMessage } from 'react-intl';
3
3
  import { CapImage, CapLabel } from '@capillarytech/cap-ui-library';
4
4
  import pdfIcon from '../assets/pdfIcon.svg';
5
+ import messages from './Whatsapp/messages';
5
6
 
6
7
  export default {
7
8
  whatsappTemplates: {
@@ -973,9 +974,8 @@ export default {
973
974
  <CapLabel type="label9">{".pdf"}</CapLabel>
974
975
  </div>
975
976
  <CapLabel className="pdf-info-sec">
976
- {
977
- `2 pages · 1.0 MB · PDF`
978
- }
977
+ {2} {<FormattedMessage {...messages.pages} />}{` · 1.0 MB · `}
978
+ <FormattedMessage {...messages.pdf} />
979
979
  </CapLabel>
980
980
  </div>
981
981
  </div>
@@ -995,9 +995,8 @@ export default {
995
995
  <CapLabel type="label9">{".pdf"}</CapLabel>
996
996
  </div>
997
997
  <CapLabel className="pdf-info-sec">
998
- {
999
- `1 page · 1.0 MB · PDF`
1000
- }
998
+ {1} {<FormattedMessage {...messages.page} />}{` · 1.0 MB · `}
999
+ <FormattedMessage {...messages.pdf} />
1001
1000
  </CapLabel>
1002
1001
  </div>
1003
1002
  </div>