@capillarytech/creatives-library 8.0.81 → 8.0.82-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.
@@ -1199,13 +1199,11 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1199
1199
  }
1200
1200
 
1201
1201
  getValidationData = () => {
1202
-
1203
1202
  const that = this;
1204
1203
  const formData = _.cloneDeep(this.state.formData);
1205
1204
  _.forEach(formData, (val, index) => {
1206
1205
  if (!isNaN(index)) {
1207
1206
  _.forEach(val.selectedLanguages, (language) => {
1208
-
1209
1207
  if (val[language].is_drag_drop) {
1210
1208
  that.props.actions.getCmsData('edm', val[language].drag_drop_id, language);
1211
1209
  }
@@ -1933,6 +1931,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1933
1931
  if (this.state.saveEdmDataMode === 'validation') {
1934
1932
  this.getValidationData();
1935
1933
  } else if (this.state.saveEdmDataMode === 'save') {
1934
+ console.log('***handleEdmSave -1935', this.state.saveObj);
1936
1935
  this.props.actions.createTemplate(this.state.saveObj);
1937
1936
  }
1938
1937
  }
@@ -3005,7 +3004,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
3005
3004
  });
3006
3005
 
3007
3006
  // if (saveCount === 0) {
3008
-
3009
3007
  this.props.actions.createTemplate(obj);
3010
3008
  // } else {
3011
3009
  // this.setState({saveObj: obj, targetSaveCount: saveCount, mode: "save", saveEdmDataMode: 'save'}, () => {
@@ -8,7 +8,6 @@ import * as types from './constants';
8
8
  export function* createTemplate(template) {
9
9
  let errorMsg;
10
10
  try {
11
-
12
11
  const result = yield call(Api.createEmailTemplate, template);
13
12
  if (result.message || result.status.code === 500) {
14
13
  errorMsg = result.message;
@@ -55,9 +54,7 @@ export function* getAllAssets(assetType, queryParams) {
55
54
 
56
55
  export function* getCmsSetting({cmsType, projectId, cmsMode, langId, isEdmSupport}) {
57
56
  try {
58
-
59
57
  const result = yield call(Api.getCmsTemplateSettings, cmsType, projectId, cmsMode, langId, isEdmSupport);
60
-
61
58
  yield put({ type: types.GET_CMS_EDITOR_DETAILS_SUCCESS, settings: result.data.response.cmsDetails });
62
59
  } catch (error) {
63
60
  yield put({ type: types.GET_CMS_EDITOR_DETAILS_FAILURE, error });
@@ -67,7 +64,6 @@ export function* getCmsSetting({cmsType, projectId, cmsMode, langId, isEdmSuppor
67
64
  export function* getCmsData({cmsType, projectId, langId}) {
68
65
  try {
69
66
  const result = yield call(Api.getCmsTemplateData, cmsType, projectId, langId);
70
-
71
67
  yield put({ type: types.GET_CMS_EDITOR_DATA_SUCCESS, data: result.data.response.data, langId: result.data.response.langId });
72
68
  } catch (error) {
73
69
  yield put({ type: types.GET_CMS_EDITOR_DATA_FAILURE, error });
@@ -85,44 +81,30 @@ export function* uploadAsset(file, assetType, fileParams) {
85
81
 
86
82
  function* watchCreateTemplate() {
87
83
  yield takeLatest(types.CREATE_TEMPLATE_REQUEST, createTemplate);
88
-
89
-
90
84
  }
91
85
 
92
86
  function* watchGetTemplateDetails() {
93
87
  yield takeLatest(types.GET_TEMPLATE_DETAILS_REQUEST, getTemplateDetails);
94
-
95
-
96
88
  }
97
89
 
98
90
  function* watchGetAllAssets() {
99
91
  yield takeLatest(types.GET_ALL_ASSETS_REQUEST, getAllAssets);
100
-
101
-
102
92
  }
103
93
 
104
94
  function* watchGetCmsSetting() {
105
95
  yield takeEvery(types.GET_CMS_EDITOR_DETAILS_REQUEST, getCmsSetting);
106
-
107
-
108
96
  }
109
97
 
110
98
  function* watchGetCmsData() {
111
99
  yield takeEvery(types.GET_CMS_EDITOR_DATA_REQUEST, getCmsData);
112
-
113
-
114
100
  }
115
101
 
116
102
  function* watchUploadAsset() {
117
103
  yield takeLatest(types.UPLOAD_ASSET_REQUEST, uploadAsset);
118
-
119
-
120
104
  }
121
105
 
122
106
  function* watchDuplicateTemplate() {
123
107
  yield takeLatest(types.DUPLICATE_TEMPLATE_REQUEST, duplicateTemplate);
124
-
125
-
126
108
  }
127
109
 
128
110
  // All sagas to be loaded
@@ -146,4 +128,4 @@ export function* emailSaga() {
146
128
  watchUploadAsset(),
147
129
  watchDuplicateTemplate(),
148
130
  ]);
149
- }
131
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "8.0.81",
4
+ "version": "8.0.82-alpha.0",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
package/services/api.js CHANGED
@@ -2,12 +2,13 @@
2
2
  * Created by vivek on 3/5/17.
3
3
  */
4
4
  import 'whatwg-fetch';
5
+ import { GA, decompressJsonObject } from '@capillarytech/cap-ui-utils';
6
+ import get from 'lodash/get';
5
7
  import { loadItem, clearItem } from './localStorageApi';
6
8
  import config from '../config/app';
7
9
  import pathConfig from '../config/path';
8
10
  import getSchema from './getSchema';
9
11
  import * as API from '../utils/ApiCaller';
10
- import { GA, decompressJsonObject } from '@capillarytech/cap-ui-utils';
11
12
  import { addBaseToTemplate } from '../utils/commonUtils';
12
13
  import { EMAIL, SMS } from '../v2Containers/CreativesContainer/constants';
13
14
  let API_ENDPOINT = config.development.api_endpoint;
@@ -300,15 +301,17 @@ export const getAllAssets = ({assetType, queryParams = {}}) => {
300
301
  });
301
302
  // const url = `https://nightly.capillary.in/arya/api/v1/creatives/assets/${assetType}?query=${JSON.stringify(queryParams)}`;
302
303
  return request(url, getAPICallObject('GET'));
303
- }
304
- ;
304
+ };
305
+
305
306
  export const deleteAssetById = ({assetId, assetType}) => {
306
307
  const url = `${API_ENDPOINT}/assets/${assetId}/${assetType}`;
307
308
  return request(url, getAPICallObject('DELETE'));
308
309
  // return API.deleteResource(url);
309
310
  };
310
311
 
311
- export const uploadFile = ({file, assetType, fileParams, mode, wechatParams, whatsappParams}) => {
312
+ export const uploadFile = ({
313
+ file, assetType, fileParams, mode, wechatParams, whatsappParams,
314
+ }) => {
312
315
  const data = new FormData();
313
316
  let fileName = '';
314
317
  try {
@@ -403,14 +406,20 @@ export const getCmsData = (cmsType, projectId, langId) => {
403
406
  return API.get(url);
404
407
  };
405
408
 
406
- export const getEdmTemplates = () => {
409
+ export const getEdmTemplates = async () => {
407
410
  const url = `${API_ENDPOINT}/templates/email/default`;
408
- return request(url, getAPICallObject('GET'));
411
+ const compressedEdmTemplates = await request(url, getAPICallObject('GET'));
412
+ const response = get(compressedEdmTemplates, 'response', '');
413
+ const decompressedEdmTemplates = decompressJsonObject(response);
414
+ return { ...compressedEdmTemplates, response: addBaseToTemplate(decompressedEdmTemplates) };
409
415
  };
410
416
 
411
- export const getDefaultBeeTemplates = () => {
417
+ export const getDefaultBeeTemplates = async () => {
412
418
  const url = `${API_ENDPOINT}/templates/v2/email/default`;
413
- return request(url, getAPICallObject('GET'));
419
+ const compressedDefaultBeeTemplates = await request(url, getAPICallObject('GET'));
420
+ const response = get(compressedDefaultBeeTemplates, 'response', '');
421
+ const decompressedBeeTemplates = decompressJsonObject(response);
422
+ return { ...compressedDefaultBeeTemplates, response: addBaseToTemplate(decompressedBeeTemplates) };
414
423
  };
415
424
 
416
425
  // All about line
@@ -12,17 +12,22 @@ import {
12
12
  askAiraForLiquid,
13
13
  getLiquidTags,
14
14
  fetchSchemaForEntity,
15
+ getDefaultBeeTemplates,
16
+ getEdmTemplates,
15
17
  } from '../api';
16
18
  import { mockData } from './mockData';
17
19
  import getSchema from '../getSchema';
18
20
  const sampleFile = require('../../assets/line.png');
19
21
 
20
22
  let mockDecompressJsonObject;
23
+ let mockAddBaseToTemplate;
21
24
  jest.mock('@capillarytech/cap-ui-utils', () => {
22
25
  mockDecompressJsonObject = jest.fn();
26
+ mockAddBaseToTemplate = jest.fn();
23
27
  return {
24
28
  ...jest.requireActual('@capillarytech/cap-ui-utils'),
25
29
  decompressJsonObject: mockDecompressJsonObject,
30
+ addBaseToTemplate: mockAddBaseToTemplate,
26
31
  };
27
32
  });
28
33
 
@@ -136,7 +141,7 @@ describe('getAllTemplates -- Test with valid responses', () => {
136
141
  global.fetch.mockReturnValue(Promise.resolve({json: () => Promise.resolve(),}));
137
142
  mockDecompressJsonObject.mockReturnValue();
138
143
  expect(await getAllTemplates({channel: 'email'})).toEqual({
139
- "response": undefined,
144
+ response: undefined,
140
145
  });
141
146
  });
142
147
 
@@ -493,3 +498,114 @@ describe('fetchSchemaForEntity', () => {
493
498
  expect(console.error).toHaveBeenCalledWith(mockError);
494
499
  });
495
500
  });
501
+
502
+ describe('Email Template APIs', () => {
503
+ beforeEach(() => {
504
+ global.fetch = jest.fn();
505
+ });
506
+
507
+ afterEach(() => {
508
+ jest.restoreAllMocks();
509
+ });
510
+
511
+ const sharedTests = (apiFunction, functionName) => {
512
+ it('should handle successful response', async () => {
513
+ const mockResponse = { response: 'compressed-data' };
514
+ const mockDecompressed = { template: 'decompressed-data' };
515
+ const mockWithBase = { template: 'data-with-base' };
516
+
517
+ global.fetch.mockReturnValue(Promise.resolve({
518
+ status: 200,
519
+ json: () => Promise.resolve(mockResponse),
520
+ }));
521
+ mockDecompressJsonObject.mockReturnValue(mockDecompressed);
522
+ mockAddBaseToTemplate.mockReturnValue(mockWithBase);
523
+
524
+ const result = await apiFunction();
525
+ expect(result).toEqual({
526
+ ...mockResponse,
527
+ response: mockDecompressed,
528
+ });
529
+ });
530
+
531
+ it('should handle response property as empty object', async () => {
532
+ const mockResponse = { response: {} };
533
+
534
+ global.fetch.mockReturnValue(Promise.resolve({
535
+ status: 200,
536
+ json: () => Promise.resolve(mockResponse),
537
+ }));
538
+ mockDecompressJsonObject.mockReturnValue({});
539
+ mockAddBaseToTemplate.mockReturnValue({});
540
+
541
+ const result = await apiFunction();
542
+ expect(result).toEqual({
543
+ ...mockResponse,
544
+ response: {},
545
+ });
546
+ });
547
+
548
+ it('should handle missing response property', async () => {
549
+ const mockResponse = {};
550
+
551
+ global.fetch.mockReturnValue(Promise.resolve({
552
+ status: 200,
553
+ json: () => Promise.resolve(mockResponse),
554
+ }));
555
+ mockDecompressJsonObject.mockReturnValue('');
556
+ mockAddBaseToTemplate.mockReturnValue('');
557
+
558
+ const result = await apiFunction();
559
+ expect(result).toEqual({
560
+ response: '',
561
+ });
562
+ });
563
+
564
+ it('should handle null response', async () => {
565
+ global.fetch.mockReturnValue(Promise.resolve({
566
+ json: () => Promise.resolve(null),
567
+ }));
568
+ mockDecompressJsonObject.mockReturnValue('');
569
+ mockAddBaseToTemplate.mockReturnValue('');
570
+
571
+ const result = await apiFunction();
572
+ expect(result).toEqual({
573
+ response: '',
574
+ });
575
+ });
576
+
577
+ it('should handle undefined response', async () => {
578
+ global.fetch.mockReturnValue(Promise.resolve({
579
+ json: () => Promise.resolve(undefined),
580
+ }));
581
+ mockDecompressJsonObject.mockReturnValue('');
582
+ mockAddBaseToTemplate.mockReturnValue('');
583
+
584
+ const result = await apiFunction();
585
+ expect(result).toEqual({
586
+ response: '',
587
+ });
588
+ });
589
+
590
+ it('should handle fetch failure', async () => {
591
+ global.fetch.mockRejectedValue(new Error('Network error'));
592
+ mockDecompressJsonObject.mockReturnValue(undefined);
593
+ mockAddBaseToTemplate.mockReturnValue(undefined);
594
+ console.error = jest.fn();
595
+
596
+ const result = await apiFunction();
597
+
598
+ expect(result).toEqual({
599
+ response: undefined,
600
+ });
601
+ });
602
+ };
603
+
604
+ describe('getEdmTemplates', () => {
605
+ sharedTests(getEdmTemplates, 'getEdmTemplates');
606
+ });
607
+
608
+ describe('getDefaultBeeTemplates', () => {
609
+ sharedTests(getDefaultBeeTemplates, 'getDefaultBeeTemplates');
610
+ });
611
+ });
@@ -31,7 +31,6 @@ export function* getTemplateDetails(id, channel) {
31
31
  export function* getCmsData({cmsType, projectId}) {
32
32
  try {
33
33
  const result = yield call(Api.getCmsData, cmsType, projectId);
34
-
35
34
  yield put({ type: types.GET_CMS_EDITOR_DATA_SUCCESS, data: decodeURIComponent(result.data.response.cmsData.htmlContent) });
36
35
  } catch (error) {
37
36
  yield put({ type: types.GET_CMS_EDITOR_DATA_FAILURE, error });
@@ -36,7 +36,7 @@ import { TRACK_CREATE_EMAIL, TRACK_EDIT_EMAIL, BEE_PLUGIN, CREATE, EDIT } from '
36
36
  import { FONT_COLOR_05 } from '@capillarytech/cap-ui-library/styled/variables';
37
37
  import { gtmPush } from '../../utils/gtmTrackers';
38
38
  const {CapCustomCardList} = CapCustomCard;
39
- import {transformEmailTemplates, storeS3FileSizeDetails, CREATIVES_S3_ASSET_FILESIZES} from '../../utils/cdnTransformation';
39
+ import {storeS3FileSizeDetails, CREATIVES_S3_ASSET_FILESIZES} from '../../utils/cdnTransformation';
40
40
  import { CUSTOMER_BARCODE_TAG } from '../../containers/App/constants';
41
41
  import injectReducer from '../../utils/injectReducer';
42
42
  import v2EmailReducer from './reducer';
@@ -199,9 +199,9 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
199
199
  this.setState({isDragDrop: true});
200
200
  }
201
201
  if (this.props.params.id) {
202
- this.props.actions.getCmsSetting(BEE_PLUGIN, this.props.Templates.BEETemplate._id, 'open', undefined, isBEESupport, isBEEAppEnable);
202
+ this.props.actions.getCmsSetting(BEE_PLUGIN, _.get(this.props.Templates.BEETemplate, 'versions.base.drag_drop_id', this.props.Templates.BEETemplate?._id), 'open', undefined, isBEESupport, isBEEAppEnable);
203
203
  } else if (this.props.location.query.module !== "library" || (this.props.location.query.module === "library" && !this.props.templateData)) {
204
- this.props.actions.getCmsSetting(BEE_PLUGIN, this.props.Templates.BEETemplate._id, 'create', undefined, isBEESupport, isBEEAppEnable);
204
+ this.props.actions.getCmsSetting(BEE_PLUGIN, _.get(this.props.Templates.BEETemplate, 'versions.base.drag_drop_id', this.props.Templates.BEETemplate?._id), 'create', undefined, isBEESupport, isBEEAppEnable);
205
205
  }
206
206
  }
207
207
  this.setState({ content: (this.props.Templates.selectedEmailLayout ? this.props.Templates.selectedEmailLayout : ''), formData});
@@ -376,7 +376,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
376
376
  const beeJson = `BEEeditor${currentTab > 1 ? currentTab : ''}json`;
377
377
  const beeToken = `BEEeditor${currentTab > 1 ? currentTab : ''}token`;
378
378
  let beeJsonValue = _.get(nextProps, 'Templates.BEETemplate.versions.base.json-content', '');
379
- const selectedId = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate._id', '');
379
+ const selectedId = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate.versions.base.drag_drop_id', '');
380
380
  if (this.state.isEdit) {
381
381
  if (this.props.location.query.module === "library") {
382
382
  beeJsonValue = _.get(this.state, `formData[${currentTab - 1}][${langId}].json-content`, '');
@@ -748,7 +748,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
748
748
  }
749
749
  getValidationData = () => {
750
750
  const that = this;
751
- let id = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate._id', '');
751
+ let id = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate.versions.base.drag_drop_id', '');
752
752
  const formData = _.cloneDeep(this.state.formData);
753
753
  if (!id) {
754
754
  id = _.get(formData, `base[${formData.base.activeTab}].id`, '');
@@ -1405,7 +1405,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1405
1405
  }
1406
1406
  });
1407
1407
  } else if (this.state.mode === 'preview' || this.state.mode === 'switchEditor') {
1408
- let id = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate._id', '');
1408
+ let id = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate.versions.base.drag_drop_id', '');
1409
1409
  const formData = _.cloneDeep(this.state.formData);
1410
1410
  if (!id) {
1411
1411
  id = _.get(formData, `base[${formData.base.activeTab}].id`, '');
@@ -2397,7 +2397,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2397
2397
 
2398
2398
  _.forEach(formData, (data, index) => {
2399
2399
  const newdata = data;
2400
-
2401
2400
  if (!isNaN(index) && newdata) {
2402
2401
  // as baseLanguage & created template language are not same than it will pick from template language
2403
2402
  const baseLangTabKey = newdata[baseLanguage]?.tabKey || newdata.tabKey;
@@ -2431,7 +2430,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2431
2430
  });
2432
2431
 
2433
2432
  // if (saveCount === 0) {
2434
-
2435
2433
  this.props.actions.transformEmailTemplate(obj, (newEmail) => {
2436
2434
  this.props.actions.createTemplate(newEmail, this.onUpdateTemplateComplete);
2437
2435
  });