@capillarytech/creatives-library 8.0.80-alpha.0 → 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.
@@ -1205,7 +1205,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1205
1205
  if (!isNaN(index)) {
1206
1206
  _.forEach(val.selectedLanguages, (language) => {
1207
1207
  if (val[language].is_drag_drop) {
1208
- console.log('***getValidationData -1210', val[language].drag_drop_id, language);
1209
1208
  that.props.actions.getCmsData('edm', val[language].drag_drop_id, language);
1210
1209
  }
1211
1210
  });
@@ -1932,12 +1931,12 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1932
1931
  if (this.state.saveEdmDataMode === 'validation') {
1933
1932
  this.getValidationData();
1934
1933
  } else if (this.state.saveEdmDataMode === 'save') {
1934
+ console.log('***handleEdmSave -1935', this.state.saveObj);
1935
1935
  this.props.actions.createTemplate(this.state.saveObj);
1936
1936
  }
1937
1937
  }
1938
1938
  });
1939
1939
  } else if (this.state.mode === 'preview' || this.state.mode === 'switchEditor') {
1940
- console.log('***HandleEdmSave -1940', this.state.formData[`${this.state.currentTab - 1}`][this.state.formData[`${this.state.currentTab - 1}`].activeTab].drag_drop_id);
1941
1940
  this.props.actions.getCmsData('edm', this.state.formData[`${this.state.currentTab - 1}`][this.state.formData[`${this.state.currentTab - 1}`].activeTab].drag_drop_id);
1942
1941
  if (this.state.mode === 'switchEditor') {
1943
1942
  let schema = _.cloneDeep(this.state.schema);
@@ -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;
@@ -82,44 +81,30 @@ export function* uploadAsset(file, assetType, fileParams) {
82
81
 
83
82
  function* watchCreateTemplate() {
84
83
  yield takeLatest(types.CREATE_TEMPLATE_REQUEST, createTemplate);
85
-
86
-
87
84
  }
88
85
 
89
86
  function* watchGetTemplateDetails() {
90
87
  yield takeLatest(types.GET_TEMPLATE_DETAILS_REQUEST, getTemplateDetails);
91
-
92
-
93
88
  }
94
89
 
95
90
  function* watchGetAllAssets() {
96
91
  yield takeLatest(types.GET_ALL_ASSETS_REQUEST, getAllAssets);
97
-
98
-
99
92
  }
100
93
 
101
94
  function* watchGetCmsSetting() {
102
95
  yield takeEvery(types.GET_CMS_EDITOR_DETAILS_REQUEST, getCmsSetting);
103
-
104
-
105
96
  }
106
97
 
107
98
  function* watchGetCmsData() {
108
99
  yield takeEvery(types.GET_CMS_EDITOR_DATA_REQUEST, getCmsData);
109
-
110
-
111
100
  }
112
101
 
113
102
  function* watchUploadAsset() {
114
103
  yield takeLatest(types.UPLOAD_ASSET_REQUEST, uploadAsset);
115
-
116
-
117
104
  }
118
105
 
119
106
  function* watchDuplicateTemplate() {
120
107
  yield takeLatest(types.DUPLICATE_TEMPLATE_REQUEST, duplicateTemplate);
121
-
122
-
123
108
  }
124
109
 
125
110
  // All sagas to be loaded
@@ -143,4 +128,4 @@ export function* emailSaga() {
143
128
  watchUploadAsset(),
144
129
  watchDuplicateTemplate(),
145
130
  ]);
146
- }
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.80-alpha.0",
4
+ "version": "8.0.82-alpha.0",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -998,7 +998,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
998
998
  if (tagValidationResponse?.isContentEmpty) {
999
999
  errorString += this.props.intl.formatMessage(messages.emailBodyEmptyError);
1000
1000
  // Adds a bypass for cases where content is initially empty in the creation flow.
1001
- if(this.liquidFlow && !this.props.isEdit){
1001
+ if(this.liquidFlow){
1002
1002
  errorString = "";
1003
1003
  isLiquidValid = true;
1004
1004
  }
@@ -1102,13 +1102,16 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
1102
1102
  const handleResult = (result) => {
1103
1103
  const {formatMessage} = this.props.intl;
1104
1104
  // Checks for errors in the result and displays them if any are found.
1105
- if (result?.errors?.length > 0) {
1105
+ const validString = /\S/.test(content);
1106
+ // If the content is empty or there are errors in the result, display the necessary validation messages.
1107
+ if (result?.errors?.length > 0 || !validString) {
1106
1108
  this.setState((prevState) => ({
1107
1109
  liquidErrorMessage: {
1108
1110
  ...prevState.liquidErrorMessage,
1111
+ STANDARD_ERROR_MSG: !validString ? [...(prevState.liquidErrorMessage?.STANDARD_ERROR_MSG || []), formatMessage(messages.emailBodyEmptyError)] : prevState.liquidErrorMessage?.STANDARD_ERROR_MSG,
1109
1112
  LIQUID_ERROR_MSG: result?.errors?.map(error => error?.message) ?? [formatMessage(messages.somethingWentWrong)],
1110
- },
1111
- }) , () => {
1113
+ }
1114
+ }), () => {
1112
1115
  this.props.showLiquidErrorInFooter(this.state.liquidErrorMessage);
1113
1116
  });
1114
1117
  this.props.stopValidation();
@@ -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`, '');
@@ -497,7 +497,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
497
497
  const isDragDrop = this.state.formData[`${this.state.currentTab - 1}`][this.state.formData[`${this.state.currentTab - 1}`].activeTab].is_drag_drop;
498
498
  const isBEESupport = (this.props.location.query.isBEESupport !== "false") || false;
499
499
  if (isDragDrop && isBEESupport && this.checkBeeEditorAllowedForLibrary()) {
500
- console.log('***Handle EDM -500', this.edmEvent, JSON.parse(this.edmEvent.data));
501
500
  const evtData = JSON.parse(this.edmEvent.data);
502
501
  if (evtData.action === 'editBackground') {
503
502
  this.edmEvent.source.postMessage(JSON.stringify({
@@ -512,7 +511,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
512
511
  },
513
512
  }), "*");
514
513
  } else if (evtData.action === 'edit') {
515
- console.log('***Handle EDM -515', this.edmEvent, JSON.parse(this.edmEvent.data));
516
514
  this.edmEvent.source.postMessage(JSON.stringify({
517
515
  _dynId: JSON.parse(this.edmEvent.data)._dynId,
518
516
  action: "setProps",
@@ -750,7 +748,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
750
748
  }
751
749
  getValidationData = () => {
752
750
  const that = this;
753
- console.log('***getValidationData -753', this.props);
754
751
  let id = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate.versions.base.drag_drop_id', '');
755
752
  const formData = _.cloneDeep(this.state.formData);
756
753
  if (!id) {
@@ -762,7 +759,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
762
759
  if (!isNaN(index)) {
763
760
  _.forEach(val.selectedLanguages, (language) => {
764
761
  if (val[language].is_drag_drop && this.checkBeeEditorAllowedForLibrary()) {
765
- console.log('***getValidationData -764', val[language].drag_drop_id, language, id);
766
762
  that.props.actions.getCmsData(BEE_PLUGIN, id, language);
767
763
  }
768
764
  });
@@ -932,7 +928,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
932
928
  // formData.base.activeTab = language;
933
929
  // }
934
930
  if (language && editData.versions.base[language].is_drag_drop && isBEEAppEnable) {
935
- console.log('***getCmsSetting -934', editData, language);
936
931
  this.props.actions.getCmsSetting(BEE_PLUGIN, editData._id, 'open', language, isBEESupport, isBEEAppEnable);
937
932
  }
938
933
  });
@@ -1410,8 +1405,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1410
1405
  }
1411
1406
  });
1412
1407
  } else if (this.state.mode === 'preview' || this.state.mode === 'switchEditor') {
1413
- let id = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate.versions.base.drag_drop_id', '');
1414
- console.log('***Handle EDM -864', id);
1408
+ let id = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate.versions.base.drag_drop_id', '');
1415
1409
  const formData = _.cloneDeep(this.state.formData);
1416
1410
  if (!id) {
1417
1411
  id = _.get(formData, `base[${formData.base.activeTab}].id`, '');
@@ -1526,7 +1520,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1526
1520
  storeS3FileSizeDetails(data?.metaInfo?.secure_file_path, data?.metaInfo?.file_size);
1527
1521
 
1528
1522
  if (isDragDrop && isEdmSupport && this.checkBeeEditorAllowedForLibrary()) {
1529
- console.log('***Handle EDM -1524', this.edmEvent, JSON.parse(this.edmEvent.data));
1530
1523
  const evtData = JSON.parse(this.edmEvent.data);
1531
1524
  if (evtData.action === 'editBackground') {
1532
1525
  this.edmEvent.source.postMessage(JSON.stringify({
@@ -1541,7 +1534,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1541
1534
  },
1542
1535
  }), "*");
1543
1536
  } else if (evtData.action === 'edit') {
1544
- console.log('***Handle EDM -1539', this.edmEvent, JSON.parse(this.edmEvent.data));
1545
1537
  this.edmEvent.source.postMessage(JSON.stringify({
1546
1538
  _dynId: JSON.parse(this.edmEvent.data)._dynId,
1547
1539
  action: "setProps",
@@ -2405,7 +2397,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2405
2397
 
2406
2398
  _.forEach(formData, (data, index) => {
2407
2399
  const newdata = data;
2408
-
2409
2400
  if (!isNaN(index) && newdata) {
2410
2401
  // as baseLanguage & created template language are not same than it will pick from template language
2411
2402
  const baseLangTabKey = newdata[baseLanguage]?.tabKey || newdata.tabKey;
@@ -2439,7 +2430,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2439
2430
  });
2440
2431
 
2441
2432
  // if (saveCount === 0) {
2442
-
2443
2433
  this.props.actions.transformEmailTemplate(obj, (newEmail) => {
2444
2434
  this.props.actions.createTemplate(newEmail, this.onUpdateTemplateComplete);
2445
2435
  });
@@ -2510,9 +2500,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2510
2500
  };
2511
2501
  handleEdmDefaultTemplateSelection = (isSelected, id) => {
2512
2502
  if (isSelected) {
2513
- console.log('***handleEdmDefaultTemplateSelection -2512', this.props.Templates.cmsTemplates);
2514
2503
  const data = _.find(this.props.Templates.cmsTemplates, {_id: id});
2515
- console.log('***handleEdmDefaultTemplateSelection -2513', data);
2516
2504
  // const type = this.props.location.query.type;
2517
2505
  // const module = this.props.location.query.module ? this.props.location.query.module : 'default';
2518
2506
  // const isLanguageSupport = (this.props.location.query.isLanguageSupport) ? this.props.location.query.isLanguageSupport : true;
@@ -0,0 +1,103 @@
1
+ export const emptyInputs = {
2
+ emptyObject: {},
3
+ nullInput: null,
4
+ undefinedInput: undefined,
5
+ expectedOutput: {}
6
+ };
7
+
8
+ export const noValidPackageIdsInput = {
9
+ input: {
10
+ standard: [
11
+ { _id: '1', definition: { stickerUrl: 'url1' } },
12
+ { _id: '2', definition: {} }
13
+ ],
14
+ custom: [
15
+ { _id: '3', definition: null },
16
+ { _id: '4' }
17
+ ]
18
+ },
19
+ expectedOutput: {}
20
+ };
21
+
22
+ export const singleCategoryInput = {
23
+ input: {
24
+ standard: [
25
+ { _id: '1', definition: { packageId: 'pkg1', stickerUrl: 'url1' } },
26
+ { _id: '2', definition: { packageId: 'pkg1', stickerUrl: 'url2' } },
27
+ { _id: '3', definition: { packageId: 'pkg2', stickerUrl: 'url3' } }
28
+ ]
29
+ },
30
+ expectedOutput: {
31
+ pkg1: [
32
+ { _id: '1', definition: { packageId: 'pkg1', stickerUrl: 'url1' } },
33
+ { _id: '2', definition: { packageId: 'pkg1', stickerUrl: 'url2' } }
34
+ ],
35
+ pkg2: [
36
+ { _id: '3', definition: { packageId: 'pkg2', stickerUrl: 'url3' } }
37
+ ]
38
+ }
39
+ };
40
+
41
+ export const multipleCategoriesInput = {
42
+ input: {
43
+ standard: [
44
+ { _id: '1', definition: { packageId: 'pkg1', stickerUrl: 'url1' } },
45
+ { _id: '2', definition: { packageId: 'pkg2', stickerUrl: 'url2' } }
46
+ ],
47
+ custom: [
48
+ { _id: '3', definition: { packageId: 'pkg1', stickerUrl: 'url3' } },
49
+ { _id: '4', definition: { packageId: 'pkg3', stickerUrl: 'url4' } }
50
+ ],
51
+ extended: [
52
+ { _id: '5', definition: { packageId: 'pkg2', stickerUrl: 'url5' } }
53
+ ]
54
+ },
55
+ expectedOutput: {
56
+ pkg1: [
57
+ { _id: '1', definition: { packageId: 'pkg1', stickerUrl: 'url1' } },
58
+ { _id: '3', definition: { packageId: 'pkg1', stickerUrl: 'url3' } }
59
+ ],
60
+ pkg2: [
61
+ { _id: '2', definition: { packageId: 'pkg2', stickerUrl: 'url2' } },
62
+ { _id: '5', definition: { packageId: 'pkg2', stickerUrl: 'url5' } }
63
+ ],
64
+ pkg3: [
65
+ { _id: '4', definition: { packageId: 'pkg3', stickerUrl: 'url4' } }
66
+ ]
67
+ }
68
+ };
69
+
70
+ export const nonArrayCategoriesInput = {
71
+ input: {
72
+ standard: [
73
+ { _id: '1', definition: { packageId: 'pkg1', stickerUrl: 'url1' } }
74
+ ],
75
+ custom: 'not an array',
76
+ extended: null
77
+ },
78
+ expectedOutput: {
79
+ pkg1: [
80
+ { _id: '1', definition: { packageId: 'pkg1', stickerUrl: 'url1' } }
81
+ ]
82
+ }
83
+ };
84
+
85
+ export const mixedStickerDataInput = {
86
+ input: {
87
+ standard: [
88
+ { _id: '1', definition: { packageId: 'pkg1', stickerUrl: 'url1' } },
89
+ { _id: '2', definition: { stickerUrl: 'url2' } },
90
+ { _id: '3' }
91
+ ],
92
+ custom: [
93
+ { _id: '4', definition: { packageId: 'pkg1', stickerUrl: 'url4' } },
94
+ { _id: '5', definition: { packageId: null, stickerUrl: 'url5' } }
95
+ ]
96
+ },
97
+ expectedOutput: {
98
+ pkg1: [
99
+ { _id: '1', definition: { packageId: 'pkg1', stickerUrl: 'url1' } },
100
+ { _id: '4', definition: { packageId: 'pkg1', stickerUrl: 'url4' } }
101
+ ]
102
+ }
103
+ };
@@ -0,0 +1,37 @@
1
+ import { groupLineStickers } from '../utils';
2
+ import {
3
+ emptyInputs,
4
+ noValidPackageIdsInput,
5
+ singleCategoryInput,
6
+ multipleCategoriesInput,
7
+ nonArrayCategoriesInput,
8
+ mixedStickerDataInput
9
+ } from './mockData';
10
+
11
+ describe('groupLineStickers', () => {
12
+ it('should return empty object when input is empty', () => {
13
+ expect(groupLineStickers(emptyInputs.emptyObject)).toEqual(emptyInputs.expectedOutput);
14
+ expect(groupLineStickers(emptyInputs.nullInput)).toEqual(emptyInputs.expectedOutput);
15
+ expect(groupLineStickers(emptyInputs.undefinedInput)).toEqual(emptyInputs.expectedOutput);
16
+ });
17
+
18
+ it('should handle input with no valid packageIds', () => {
19
+ expect(groupLineStickers(noValidPackageIdsInput.input)).toEqual(noValidPackageIdsInput.expectedOutput);
20
+ });
21
+
22
+ it('should group stickers by packageId within single category', () => {
23
+ expect(groupLineStickers(singleCategoryInput.input)).toEqual(singleCategoryInput.expectedOutput);
24
+ });
25
+
26
+ it('should group stickers by packageId across multiple categories', () => {
27
+ expect(groupLineStickers(multipleCategoriesInput.input)).toEqual(multipleCategoriesInput.expectedOutput);
28
+ });
29
+
30
+ it('should skip non-array categories', () => {
31
+ expect(groupLineStickers(nonArrayCategoriesInput.input)).toEqual(nonArrayCategoriesInput.expectedOutput);
32
+ });
33
+
34
+ it('should handle mixed valid and invalid sticker data', () => {
35
+ expect(groupLineStickers(mixedStickerDataInput.input)).toEqual(mixedStickerDataInput.expectedOutput);
36
+ });
37
+ });
@@ -6,15 +6,26 @@ import CapColumn from '@capillarytech/cap-ui-library/CapColumn';
6
6
 
7
7
  export const groupLineStickers = (lineStickers) => {
8
8
  const stickerGroup = {};
9
- lineStickers.forEach((lineSticker) => {
10
- const packageId = get(lineSticker, 'definition.packageId');
11
- if (packageId) {
12
- const stickerGroupPackageId = stickerGroup[packageId];
13
- if (stickerGroupPackageId && Array.isArray(stickerGroupPackageId)) {
14
- stickerGroup[packageId].push(lineSticker);
15
- } else {
16
- stickerGroup[packageId] = [];
17
- }
9
+ // Return early if lineStickers is null or undefined
10
+ if (!lineStickers) return stickerGroup;
11
+
12
+ // Now we can safely iterate as lineStickers is defined
13
+ Object?.keys(lineStickers)?.forEach((key) => {
14
+ const category = lineStickers[key];
15
+ if (Array.isArray(category)) {
16
+ //iterating over each category [standard, custom, extended]
17
+ category?.forEach((lineSticker) => {
18
+ const packageId = get(lineSticker, 'definition.packageId');
19
+ if (packageId) {
20
+ const stickerGroupPackageId = stickerGroup[packageId];
21
+ if (stickerGroupPackageId && Array.isArray(stickerGroupPackageId)) {
22
+ stickerGroup[packageId].push(lineSticker);
23
+ } else {
24
+ //initialising with first sticker for each package ID
25
+ stickerGroup[packageId] = [lineSticker];
26
+ }
27
+ }
28
+ });
18
29
  }
19
30
  });
20
31
  return stickerGroup;
@@ -35,7 +46,7 @@ export const getContent = ({ lineStickers, onStickerSelect }) => (
35
46
  >
36
47
  <CapImage
37
48
  src={definition.stickerUrl}
38
- rest={{ height: 70 }}
49
+ rest = {{ height: 70 }}
39
50
  rest={{
40
51
  height: 70,
41
52
  onMouseOut: e => (e.currentTarget.src = definition.stickerUrl),