@capillarytech/creatives-library 6.10.0 → 6.10.2

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.
Files changed (36) hide show
  1. package/components/CapTagList/index.js +1 -1
  2. package/components/Edmeditor/index.js +1 -1
  3. package/components/FormBuilder/index.js +0 -1
  4. package/containers/TagList/index.js +3 -3
  5. package/index.html +3 -0
  6. package/package.json +2 -1
  7. package/services/api.js +19 -4
  8. package/translations/en.json +117 -4
  9. package/translations/zh.json +113 -0
  10. package/v2Components/BeeEditor/index.js +263 -0
  11. package/v2Components/BeeEditor/index.scss +11 -0
  12. package/v2Components/BeeEditor/messages.js +71 -0
  13. package/v2Components/BeeEditor/tests/index.test.js +10 -0
  14. package/v2Components/CapTagList/index.js +55 -26
  15. package/v2Components/CmsTemplatesComponent/index.js +4 -4
  16. package/v2Components/Edmeditor/index.js +1 -1
  17. package/v2Components/EmailPreview/_emailPreview.scss +2 -2
  18. package/v2Components/FormBuilder/index.js +78 -43
  19. package/v2Containers/App/constants.js +1 -0
  20. package/v2Containers/CreativesContainer/SlideBoxFooter.js +2 -2
  21. package/v2Containers/CreativesContainer/index.js +7 -2
  22. package/v2Containers/Email/constants.js +1 -0
  23. package/v2Containers/Email/index.js +170 -116
  24. package/v2Containers/Email/initialSchema.js +18 -3
  25. package/v2Containers/Email/sagas.js +2 -2
  26. package/v2Containers/Email/selectors.js +5 -0
  27. package/v2Containers/EmailWrapper/index.js +19 -3
  28. package/v2Containers/Line/Container/Image/index.js +1 -1
  29. package/v2Containers/TagList/index.js +13 -6
  30. package/v2Containers/Templates/actions.js +8 -3
  31. package/v2Containers/Templates/constants.js +6 -4
  32. package/v2Containers/Templates/index.js +36 -20
  33. package/v2Containers/Templates/messages.js +8 -0
  34. package/v2Containers/Templates/reducer.js +13 -5
  35. package/v2Containers/Templates/sagas.js +7 -7
  36. package/v2Containers/Templates/selectors.js +19 -1
@@ -31,9 +31,8 @@ import * as creativesContainerActions from '../CreativesContainer/actions';
31
31
  import withCreatives from '../../hoc/withCreatives';
32
32
  import { EMAIL } from '../CreativesContainer/constants';
33
33
  import { GA } from '@capillarytech/cap-ui-utils';
34
- import { TRACK_CREATE_EMAIL, TRACK_EDIT_EMAIL } from '../App/constants';
34
+ import { TRACK_CREATE_EMAIL, TRACK_EDIT_EMAIL, BEE_PLUGIN } from '../App/constants';
35
35
  import { FONT_COLOR_05 } from '@capillarytech/cap-ui-library/styled/variables';
36
-
37
36
  const {CapCustomCardList} = CapCustomCard;
38
37
  export class Email extends React.Component { // eslint-disable-line react/prefer-stateless-function
39
38
  constructor(props) {
@@ -179,24 +178,23 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
179
178
  // "template-content": (this.props.Templates.selectedEmailLayout ? this.props.Templates.selectedEmailLayout : ''),
180
179
  // };
181
180
  // if (this.props.Templates.CmsSettings) {}
182
- const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
181
+
183
182
  if (this.props.location.query.module === "library" && this.props.templateData) {
184
183
  this.props.templatesActions.resetTemplateData();
185
184
  }
186
- if (!_.isEmpty(this.props.Templates.edmTemplate)) {
187
- if (this.props.Templates.edmTemplate.versions.base.is_drag_drop) {
185
+ const isBEESupport = (this.props.location.query.isBEESupport !== "false") || false;
186
+
187
+ if (!_.isEmpty(this.props.Templates.BEETemplate) ) {
188
+ if (this.props.Templates.BEETemplate.versions.base.is_drag_drop) {
188
189
  this.setState({isDragDrop: true});
189
190
  }
190
191
  if (this.props.params.id) {
191
- this.props.actions.getCmsSetting('edm', this.props.Templates.edmTemplate.versions.base.drag_drop_id, 'open', undefined, isEdmSupport);
192
+ this.props.actions.getCmsSetting(BEE_PLUGIN, this.props.Templates.BEETemplate._id, 'open', undefined, isBEESupport);
192
193
  } else if (this.props.location.query.module !== "library" || (this.props.location.query.module === "library" && !this.props.templateData)) {
193
- this.props.actions.getCmsSetting('edm', this.props.Templates.edmTemplate.versions.base.drag_drop_id, 'create', undefined, isEdmSupport);
194
+ this.props.actions.getCmsSetting(BEE_PLUGIN, this.props.Templates.BEETemplate._id, 'create', undefined, isBEESupport);
194
195
  }
195
196
  }
196
-
197
- this.setState({ content: (this.props.Templates.selectedEmailLayout ? this.props.Templates.selectedEmailLayout : ''), formData}, () => {
198
- // this.injectEvents(this.state.schema);
199
- });
197
+ this.setState({ content: (this.props.Templates.selectedEmailLayout ? this.props.Templates.selectedEmailLayout : ''), formData});
200
198
 
201
199
  // setTimeout(() => {
202
200
  // // this.getFormData();
@@ -216,7 +214,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
216
214
  this.showNext();
217
215
  }
218
216
  }
219
-
220
217
  componentWillReceiveProps(nextProps) {
221
218
  // if (this.props.location.query.type === 'embedded') {
222
219
  // this.showNext();
@@ -316,16 +313,16 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
316
313
  this.startTemplateCreation(nextProps.templateData);
317
314
  }
318
315
  if (nextProps.location.query.module === 'library' && nextProps.isGetFormData) {
316
+ const formData = this.state.formData;
317
+ let isBeeEditor = false;
318
+ _.forEach(formData[0].selectedLanguages, (language) => {
319
+ if (formData[0][language].is_drag_drop) {
320
+ isBeeEditor = true;
321
+ }
322
+ });
319
323
  if (this.props.isFullMode) {
320
324
  let triggerGetFormData = true;
321
- let isEdmEditor = false;
322
- const formData = this.state.formData;
323
- _.forEach(formData[0].selectedLanguages, (language) => {
324
- if (formData[0][language].is_drag_drop) {
325
- isEdmEditor = true;
326
- }
327
- });
328
- triggerGetFormData = isEdmEditor ? (!nextProps.Email.fetchingCmsData && _.isEmpty(nextProps.Email.cmsData)) : !nextProps.Email.createTemplateInProgress && _.isEmpty(nextProps.Email.createResponse); // if edm editor selected check for getCmsData call in progress or not before triggering save
325
+ triggerGetFormData = isBeeEditor ? (!nextProps.Email.fetchingCmsData && _.isEmpty(nextProps.Email.cmsData)) : !nextProps.Email.createTemplateInProgress && _.isEmpty(nextProps.Email.createResponse); // if edm editor selected check for getCmsData call in progress or not before triggering save
329
326
  if (triggerGetFormData) {
330
327
  this.getFormData();
331
328
  }
@@ -335,6 +332,9 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
335
332
  }
336
333
  this.getFormData();
337
334
  }
335
+ if (!nextProps.Email.createTemplateInProgress && isBeeEditor) {
336
+ this.beeInstance && this.beeInstance.save();
337
+ }
338
338
  }
339
339
 
340
340
  if (!_.isEmpty(nextProps.Email.CmsSettings) && !_.isEqual(this.props.Email.CmsSettings, nextProps.Email.CmsSettings) && !_.isEmpty(this.state.schema)) {
@@ -348,16 +348,26 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
348
348
 
349
349
  const temp = schema.containers[this.state.currentTab - 1];
350
350
 
351
-
351
+ const { currentTab } = this.state;
352
352
  if (nextProps.Email.CmsSettings.isDragDrop) {
353
- formData[`${this.state.currentTab - 1}`][langId][`edmeditor${this.state.currentTab > 1 ? this.state.currentTab : ''}src`] = nextProps.Email.CmsSettings.url;
354
- formData[`${this.state.currentTab - 1}`][langId][`drag_drop_id`] = this.getParameterByName("projectId", nextProps.Email.CmsSettings.url);
355
- formData[`${this.state.currentTab - 1}`][langId][`is_drag_drop`] = true;
356
- if (formData[`${this.state.currentTab - 1}`].base) {
357
- formData.base[langId][`edmeditor${this.state.currentTab > 1 ? this.state.currentTab : ''}src`] = nextProps.Email.CmsSettings.url;
358
- formData.base[langId][`drag_drop_id`] = this.getParameterByName("projectId", nextProps.Email.CmsSettings.url);
359
- formData.base[langId][`is_drag_drop`] = true;
353
+ const beeJson = `BEEeditor${currentTab > 1 ? currentTab : ''}json`;
354
+ const beeToken = `BEEeditor${currentTab > 1 ? currentTab : ''}token`;
355
+ let beeJsonValue = _.get(nextProps, 'Templates.BEETemplate.versions.base.json-content', '');
356
+ const selectedId = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate._id', '');
357
+ if (this.state.isEdit) {
358
+ if (this.props.location.query.module === "library") {
359
+ beeJsonValue = _.get(this.state, `formData[${currentTab - 1}][${langId}].json-content`, '');
360
+ } else {
361
+ beeJsonValue = _.get(nextProps, `Email.templateDetails.versions.base[${langId}].json-content`, '');
362
+ }
360
363
  }
364
+ formData[`${currentTab - 1}`][langId] = {
365
+ ...formData[`${currentTab - 1}`][langId],
366
+ is_drag_drop: true,
367
+ [beeJson]: beeJsonValue,
368
+ [beeToken]: nextProps.Email.CmsSettings.tokenData,
369
+ id: selectedId,
370
+ };
361
371
  _.forEach(temp.panes, (pane, index) => {
362
372
  const tempPane = pane;
363
373
  //
@@ -367,7 +377,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
367
377
  tempPane.sections[0].inputFields[0].cols[0].colStyle = {display: "none"};
368
378
  }
369
379
  });
370
-
371
380
  this.setState({schema, isSchemaChanged: true, loadingStatus: this.state.loadingStatus + 1});
372
381
  } else {
373
382
  _.forEach(temp.panes, (pane, index) => {
@@ -384,7 +393,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
384
393
  html = html.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/\\&quot;/g, '"');
385
394
 
386
395
  formData[this.state.currentTab - 1][langId]["template-content"] = html;
387
- if (window.CKEDITOR && apiLangId !== "undefined") {
396
+ if (window.CKEDITOR && apiLangId !== "undefined" && !this.props.Email.fetchingCmsSettings && !this.props.Email.getTemplateDetailsInProgress) {
388
397
  const instanceName = `template-content${(langIndex + 1) > 1 ? (langIndex + 1) : ''}`;
389
398
 
390
399
  _.forEach(window.CKEDITOR.instances, (winInstance) => {
@@ -422,23 +431,26 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
422
431
  if (formData[`${this.state.currentTab - 1}`].base) {
423
432
  formData.base[formData.base.activeTab]['template-content'] = decodeURIComponent(nextProps.Email.cmsData);
424
433
  }
425
- } else {
434
+ } else if (!nextProps.Email.getTemplateDetailsInProgress) {
426
435
  const langIndex = formData[this.state.currentTab - 1].selectedLanguages.indexOf(formData[this.state.currentTab - 1].activeTab);
427
436
  const instanceName = `template-content${(langIndex + 1) > 1 ? (langIndex + 1) : ''}`;
428
437
 
429
- _.forEach(window.CKEDITOR.instances, (winInstance) => {
430
- const temp = winInstance;
438
+ if (window.CKEDITOR) {
439
+ _.forEach(window.CKEDITOR.instances, (winInstance) => {
440
+ const temp = winInstance;
431
441
 
432
- if (winInstance.name === instanceName) {
433
- temp.setData(decodeURIComponent(nextProps.Email.cmsData));
434
- } else if (winInstance.name.indexOf('editor') !== -1) {
435
- temp.setData(decodeURIComponent(nextProps.Email.cmsData));
436
- }
437
- });
442
+ if (winInstance.name === instanceName) {
443
+ temp.setData(decodeURIComponent(nextProps.Email.cmsData));
444
+ } else if (winInstance.name.indexOf('editor') !== -1) {
445
+ temp.setData(decodeURIComponent(nextProps.Email.cmsData));
446
+ }
447
+ });
448
+ }
438
449
  formData[`${this.state.currentTab - 1}`][formData[`${this.state.currentTab - 1}`].activeTab]['template-content'] = decodeURIComponent(nextProps.Email.cmsData);
439
450
  formData[`${this.state.currentTab - 1}`][formData[`${this.state.currentTab - 1}`].activeTab].is_drag_drop = false;
440
451
  formData[`${this.state.currentTab - 1}`][formData[`${this.state.currentTab - 1}`].activeTab].drag_drop_id = "";
441
452
  delete formData[`${this.state.currentTab - 1}`][formData[`${this.state.currentTab - 1}`].activeTab].edmeditorsrc;
453
+ // from edm to ck editor
442
454
  if (formData[`${this.state.currentTab - 1}`].base) {
443
455
  formData.base[formData.base.activeTab]['template-content'] = decodeURIComponent(nextProps.Email.cmsData);
444
456
  formData.base[formData.base.activeTab].is_drag_drop = false;
@@ -456,8 +468,8 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
456
468
 
457
469
  if ( !_.isEqual(nextProps.Email.uploadAssetSuccess, this.props.Email.uploadAssetSuccess) && nextProps.Email.uploadAssetSuccess) {
458
470
  const isDragDrop = this.state.formData[`${this.state.currentTab - 1}`][this.state.formData[`${this.state.currentTab - 1}`].activeTab].is_drag_drop;
459
- const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
460
- if (isDragDrop && isEdmSupport) {
471
+ const isBEESupport = (this.props.location.query.isBEESupport !== "false") || false;
472
+ if (isDragDrop && isBEESupport) {
461
473
  const evtData = JSON.parse(this.edmEvent.data);
462
474
  if (evtData.action === 'editBackground') {
463
475
  this.edmEvent.source.postMessage(JSON.stringify({
@@ -501,6 +513,12 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
501
513
  this.setState({totalCount: nextProps.Email.assetList[0].totalCount});
502
514
  }
503
515
  }
516
+ if (!_.isEmpty(nextProps.Email.templateDetails) && _.isEmpty(this.props.Email.templateDetails) ) {
517
+ const base = nextProps.Email.templateDetails.versions.base;
518
+ if (nextProps.Email.templateDetails.versions.base[base.activeTab].is_drag_drop) {
519
+ this.setState({isDragDrop: true});
520
+ }
521
+ }
504
522
  }
505
523
 
506
524
  componentWillUnmount() {
@@ -585,9 +603,9 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
585
603
  onTagSelect = (data) => {
586
604
  const isDragDrop = this.state.formData[`${this.state.currentTab - 1}`][this.state.formData[`${this.state.currentTab - 1}`].activeTab].is_drag_drop;
587
605
  const formData = _.cloneDeep(this.state.formData);
588
- const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
606
+ const isBEESupport = (this.props.location.query.isBEESupport !== "false") || false;
589
607
 
590
- if (isDragDrop && isEdmSupport) {
608
+ if (isDragDrop && isBEESupport) {
591
609
  let msg = {};
592
610
  if (data === "unsubscribe") {
593
611
  const anchor = `<a href='{{${data}}}'>${data}</a>`;
@@ -628,10 +646,12 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
628
646
  onUpdateTemplateComplete = (createResponse) => {
629
647
  const {isEdit, formData = {} } = this.state || {};
630
648
  const base = formData.base || {};
631
- const isDragDrop = _.get(base[base.activeTab], 'is_drag_drop', false);
632
- let editorType = 'ckEditor';
633
- if ( isDragDrop ) {
649
+ const isDragDrop = _.get(base[base.activeTab], 'is_drag_drop');
650
+ let editorType = '';
651
+ if ( isDragDrop === true) {
634
652
  editorType = 'edmEditor';
653
+ } else if (isDragDrop === false) {
654
+ editorType = 'ckEditor';
635
655
  }
636
656
  GA.timeTracker.stopTimer(isEdit ? TRACK_EDIT_EMAIL : TRACK_CREATE_EMAIL, {
637
657
  category: 'Creatives',
@@ -650,14 +670,14 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
650
670
  const module = this.props.location.query.module ? this.props.location.query.module : 'default';
651
671
  const type = this.props.location.query.type;
652
672
  const isLanguageSupport = this.props.location.query.isLanguageSupport || false;
653
- const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
673
+ const isBEESupport = (this.props.location.query.isBEESupport !== "false") || false;
654
674
  if (this.props.isFullMode) {
655
675
  const {versions, ...rest} = createResponse.templateId;
656
676
  this.props.getFormSubscriptionData({ value: versions, ...rest, validity: true});
657
677
  } else {
658
678
  this.props.router.push({
659
679
  pathname: `/email`,
660
- query: type === 'embedded' ? {type: 'embedded', module, isLanguageSupport, isEdmSupport} : {module, isLanguageSupport, isEdmSupport},
680
+ query: type === 'embedded' ? {type: 'embedded', module, isLanguageSupport, isBEESupport} : {module, isLanguageSupport, isBEESupport},
661
681
  });
662
682
  }
663
683
  }
@@ -675,6 +695,10 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
675
695
  }
676
696
  getValidationData = () => {
677
697
  const that = this;
698
+ let id = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate._id', '');
699
+ if (!id) {
700
+ id = _.get(formData, `base[${formData.base.activeTab}].id`, '');
701
+ }
678
702
  const formData = _.cloneDeep(this.state.formData);
679
703
  if (!this.props.Email.fetchingCmsData) {
680
704
  // checking wheather getCmsData in progress or not cuz getValidationData gets called multiple times from handleEdmSave
@@ -682,7 +706,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
682
706
  if (!isNaN(index)) {
683
707
  _.forEach(val.selectedLanguages, (language) => {
684
708
  if (val[language].is_drag_drop) {
685
- that.props.actions.getCmsData('edm', val[language].drag_drop_id, language);
709
+ that.props.actions.getCmsData(BEE_PLUGIN, id, language);
686
710
  }
687
711
  });
688
712
  }
@@ -747,7 +771,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
747
771
  }
748
772
 
749
773
  setEditData(editData) {
750
- const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
774
+ const isBEESupport = (this.props.location.query.isBEESupport !== "false") || false;
751
775
  const formData = _.cloneDeep(this.state.formData);
752
776
 
753
777
  const schema = (this.props.location.query.type === 'embedded') ? this.removeStandAlone(this.state.schema) : _.cloneDeep(this.state.schema);
@@ -890,7 +914,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
890
914
  // formData.base.activeTab = language;
891
915
  // }
892
916
  if (language && editData.versions.base[language].is_drag_drop) {
893
- this.props.actions.getCmsSetting('edm', editData.versions.base[language].drag_drop_id, 'open', language, isEdmSupport);
917
+ this.props.actions.getCmsSetting(BEE_PLUGIN, editData._id, 'open', language, isBEESupport);
894
918
  }
895
919
  });
896
920
 
@@ -907,7 +931,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
907
931
  value: 'edit',
908
932
  direction: e.value,
909
933
  };
910
- parent.postMessage(JSON.stringify(response), '*');
911
934
  }
912
935
 
913
936
  getEditorInstanse = () => {
@@ -987,17 +1010,8 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
987
1010
  if (saveCount === 0) {
988
1011
  //gets exicuted when ck editor is used
989
1012
  this.startValidation(true);
990
- return;
991
1013
  }
992
- this.setState({targetSaveCount: saveCount, mode: "save", saveCount: 0, cmsDataCount: 0}, () => {
993
- const data = this.state.formData[this.state.currentTab - 1];
994
- _.forEach(data.selectedLanguages, (language, langIndex) => {
995
- if (data[language].is_drag_drop) {
996
- const win = document.getElementById(`edmeditor${(langIndex + 1) > 1 ? (langIndex + 1) : ''}`).contentWindow;
997
- win.postMessage("saveProject", '*');
998
- }
999
- });
1000
- });
1014
+ this.setState({targetSaveCount: saveCount, mode: "save", saveCount: 0, cmsDataCount: 0});
1001
1015
  });
1002
1016
  }
1003
1017
 
@@ -1111,7 +1125,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1111
1125
  const currentTab = this.state.currentTab - 1;
1112
1126
  const baseLanguage = this.props.currentOrgDetails.basic_details.base_language ? this.props.currentOrgDetails.basic_details.base_language : 'en';
1113
1127
  if (formData[currentTab][baseLanguage].is_drag_drop) {
1114
- this.props.actions.getCmsSetting('edm', formData[currentTab][baseLanguage].drag_drop_id, 'duplicate', baseLanguage, isEdmSupport);
1128
+ this.props.actions.getCmsSetting(BEE_PLUGIN, formData[currentTab][baseLanguage].drag_drop_id, 'duplicate', baseLanguage, isEdmSupport);
1115
1129
  }
1116
1130
  });
1117
1131
  }
@@ -1240,7 +1254,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1240
1254
  const languageObject = this.supportedLanguages[_.findIndex(this.supportedLanguages, {iso_code: baseLanguage})] || {iso_code: baseLanguage || 'en', lang_id: -1, language: baseLanguage || "English"};
1241
1255
  baseData.activeTab = baseLanguage;
1242
1256
  baseData[languageObject.iso_code] = {};
1243
- baseData[languageObject.iso_code].is_drag_drop = false;
1257
+ baseData[languageObject.iso_code].is_drag_drop = undefined;
1244
1258
  baseData[languageObject.iso_code].lang_id = languageObject.lang_id;
1245
1259
  baseData[languageObject.iso_code].iso_code = languageObject.iso_code;
1246
1260
  baseData[languageObject.iso_code].language = languageObject.language;
@@ -1270,12 +1284,13 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1270
1284
  return;
1271
1285
  }
1272
1286
  tmpData.html_content = content['template-content'];
1287
+ tmpData.json_content = content['json-content'];
1273
1288
  tmpData.is_drag_drop = content.is_drag_drop;
1274
1289
  tmpData.lang_id = content.lang_id;
1275
1290
  tmpData.iso_code = content.iso_code;
1276
1291
  tmpData.language = content.language;
1277
- if (content.is_drag_drop) {
1278
- tmpData.drag_drop_id = (content.drag_drop_id ? content.drag_drop_id : "");
1292
+ if (content.id) {
1293
+ tmpData.id = content.id;
1279
1294
  }
1280
1295
 
1281
1296
  if (index === this.props.currentOrgDetails.basic_details.base_language) {
@@ -1313,9 +1328,10 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1313
1328
  this.onImageSelect();
1314
1329
  }
1315
1330
  break;
1316
- case "create":
1331
+ case "create": {
1317
1332
  this.edmEvent = e;
1318
1333
  break;
1334
+ }
1319
1335
  case "select":
1320
1336
  //this.edmEvent = e;
1321
1337
  break;
@@ -1383,10 +1399,14 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1383
1399
  }
1384
1400
  });
1385
1401
  } else if (this.state.mode === 'preview' || this.state.mode === 'switchEditor') {
1386
- this.props.actions.getCmsData('edm', this.state.formData[`${this.state.currentTab - 1}`][this.state.formData[`${this.state.currentTab - 1}`].activeTab].drag_drop_id);
1402
+ let id = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate._id', '');
1403
+ const formData = _.cloneDeep(this.state.formData);
1404
+ if (!id) {
1405
+ id = _.get(formData, `base[${formData.base.activeTab}].id`, '');
1406
+ }
1407
+ this.props.actions.getCmsData(BEE_PLUGIN, id);
1387
1408
  if (this.state.mode === 'switchEditor') {
1388
1409
  let schema = _.cloneDeep(this.state.schema);
1389
- const formData = _.cloneDeep(this.state.formData);
1390
1410
  _.forEach(schema.containers, (container, index) => {
1391
1411
  if (parseInt(index, 10) === (this.state.currentTab - 1)) {
1392
1412
  const temp = container;
@@ -1528,14 +1548,8 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1528
1548
  toggleEmailPreview = () => {
1529
1549
  const isDragDrop = this.state.formData[`${this.state.currentTab - 1}`][this.state.formData[`${this.state.currentTab - 1}`].activeTab].is_drag_drop;
1530
1550
  if (isDragDrop && !this.state.showEmailPreview) {
1531
- const activeLangTab = this.state.formData[`${this.state.currentTab - 1}`].activeTab;
1532
- const langIndex = this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages.indexOf(activeLangTab);
1533
- const win = document.getElementById(`edmeditor${(langIndex + 1) > 1 ? (langIndex + 1) : ''}`).contentWindow;
1534
- win.postMessage("saveProject", '*');
1551
+ this.handleEdmSave();
1535
1552
  this.setState({mode: "preview", gettingPreviewData: true});
1536
- // this.setState({gettingPreviewData: true}, () => {
1537
- // this.props.actions.getCmsData('edm', this.state.formData[`${this.state.currentTab - 1}`][this.state.formData[`${this.state.currentTab - 1}`].activeTab].drag_drop_id);
1538
- // });
1539
1553
  } else if (this.state.showEmailPreview) {
1540
1554
  const formData = _.cloneDeep(this.state.formData);
1541
1555
  formData[`${this.state.currentTab - 1}`][formData[`${this.state.currentTab - 1}`].activeTab]['template-content'] = "";
@@ -1737,7 +1751,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1737
1751
  schema.containers[`${this.state.currentTab - 1}`].panes.push(firstPane);
1738
1752
  // schema.containers[0].tabContent.sections.push(tabContent);
1739
1753
  }
1740
- //this.props.templatesActions.getEdmDefaultTemplates();
1741
1754
  const container = schema.containers[this.state.currentTab - 1];
1742
1755
  const temp = container;
1743
1756
  if (this.state.addLanguageType === "upload") {
@@ -1838,7 +1851,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1838
1851
  action: "showNext",
1839
1852
  value: true,
1840
1853
  };
1841
- parent.postMessage(JSON.stringify(response), '*');
1854
+
1842
1855
  }
1843
1856
 
1844
1857
  moveToTemplates = () => {
@@ -1993,7 +2006,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1993
2006
  const response = {
1994
2007
  action: 'startTemplateCreation',
1995
2008
  };
1996
- parent.postMessage(JSON.stringify(response), '*');
2009
+ parent && parent.postMessage(JSON.stringify(response), '*');
1997
2010
  }
1998
2011
  });
1999
2012
  return temp;
@@ -2086,6 +2099,8 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2086
2099
  "iso_code": this.supportedLanguages[languageIndex].iso_code,
2087
2100
  "language": this.supportedLanguages[languageIndex].language,
2088
2101
  "template-content": !data.base.is_drag_drop && data.base.is_drag_drop !== 1 ? data.base.html_content : "",
2102
+ "json-content": data.base.json_content,
2103
+ "id": data.base.id,
2089
2104
  };
2090
2105
  const dragDropId = _.get(data, 'base.drag_drop_id');
2091
2106
  if (dragDropId) {
@@ -2114,7 +2129,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2114
2129
  };
2115
2130
  if (templates.drag_drop_id) {
2116
2131
  tempData.drag_drop_id = templates.drag_drop_id;
2117
- this.props.actions.getCmsSetting('edm', tempData.drag_drop_id, 'open', tempData.iso_code, isEdmSupport);
2132
+ this.props.actions.getCmsSetting(BEE_PLUGIN, tempData._id, 'open', tempData.iso_code, isEdmSupport);
2118
2133
  }
2119
2134
  // formData.usingTabContainer = true;
2120
2135
  // formData.tabCount = 1;
@@ -2140,7 +2155,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2140
2155
  // this.setState({tabKey: ''});
2141
2156
  _.forEach(formData[0].selectedLanguages, (language) => {
2142
2157
  if (formData[0][language].is_drag_drop) {
2143
- this.props.actions.getCmsSetting('edm', formData[0][language].drag_drop_id, 'open', language, isEdmSupport);
2158
+ this.props.actions.getCmsSetting(BEE_PLUGIN, formData[0][language].drag_drop_id, 'open', language, isEdmSupport);
2144
2159
  }
2145
2160
  });
2146
2161
  });
@@ -2333,7 +2348,6 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2333
2348
 
2334
2349
  saveFormData = (passedData) => {
2335
2350
  //saveFormData gets called only when validation result is true
2336
-
2337
2351
  if (this.state.gettingFormData && !this.props.isFullMode) {
2338
2352
  const response = {
2339
2353
  action: "getFormData",
@@ -2347,12 +2361,13 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2347
2361
  if (this.props.location.query.module === 'library' && this.props.isGetFormData) {
2348
2362
  this.props.getFormSubscriptionData(response);
2349
2363
  }
2350
- parent.postMessage(JSON.stringify(response), "*");
2351
2364
  this.setState({gettingFormData: false, startValidation: false, loading: true});
2352
2365
  return;
2353
2366
  }
2354
2367
  const formData = _.cloneDeep(passedData);
2355
-
2368
+ const { currentTab } = _.cloneDeep(this.state);
2369
+ delete formData[currentTab - 1][formData[currentTab - 1].activeTab][`BEEeditor${currentTab > 1 ? currentTab : ''}json`];
2370
+ delete formData[currentTab - 1][formData[currentTab - 1].activeTab][`BEEeditor${currentTab > 1 ? currentTab : ''}token`];
2356
2371
  const obj = {};
2357
2372
  obj.versions = {
2358
2373
  base: {},
@@ -2422,8 +2437,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2422
2437
  const langIndex = formData[`${this.state.currentTab - 1}`].selectedLanguages.indexOf(activeLangTab);
2423
2438
 
2424
2439
  this.setState({mode: "switchEditor"}, () => {
2425
- const win = document.getElementById(`edmeditor${(langIndex + 1) > 1 ? (langIndex + 1) : ''}`).contentWindow;
2426
- win.postMessage("saveProject", '*');
2440
+ this.handleEdmSave();
2427
2441
  });
2428
2442
  }
2429
2443
 
@@ -2465,7 +2479,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2465
2479
  this.setState( (prevState) => ({
2466
2480
  showEdmEmailTemplates: !prevState.showEdmEmailTemplates}), () => {
2467
2481
  if (this.state.showEdmEmailTemplates) {
2468
- this.props.templatesActions.getEdmDefaultTemplates();
2482
+ this.props.templatesActions.getDefaultBeeTemplates();
2469
2483
  }
2470
2484
  });
2471
2485
  };
@@ -2479,7 +2493,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2479
2493
  // let getQuery = '';
2480
2494
  const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
2481
2495
 
2482
- this.props.actions.getCmsSetting('edm', data.versions.base.drag_drop_id, 'create', this.state.formData[this.state.currentTab - 1].activeTab, isEdmSupport);
2496
+ this.props.actions.getCmsSetting(BEE_PLUGIN, data._id, 'create', this.state.formData[this.state.currentTab - 1].activeTab, isEdmSupport);
2483
2497
  // this.props.templatesActions.setEdmTemplate(data);
2484
2498
  this.toggleEdmEmailTemplateSelection();
2485
2499
  // if (type && type.toLowerCase() === 'email') {
@@ -2495,7 +2509,22 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2495
2509
  };
2496
2510
  isEmailLoading = () => {
2497
2511
  //let {isLoading} = this.props;
2498
- let isLoading = this.props.isLoadingMetaEntities || this.state.loading || (this.props.Email && "createTemplateInProgress" in this.props.Email && this.props.Email.createTemplateInProgress) || (this.props.Email.assetUploading !== undefined && this.props.Email.assetUploading);
2512
+ const { Email, isLoadingMetaEntities, setIsLoadingContent } = this.props;
2513
+ const {
2514
+ fetchingCmsData,
2515
+ getTemplateDetailsInProgress,
2516
+ assetUploading,
2517
+ createTemplateInProgress,
2518
+ } = this.props.Email;
2519
+ let isLoading =
2520
+ isLoadingMetaEntities ||
2521
+ this.state.loading || (
2522
+ Email && "createTemplateInProgress" in Email && createTemplateInProgress
2523
+ ) || (
2524
+ assetUploading !== undefined && assetUploading
2525
+ ) || (
2526
+ Email && (fetchingCmsData || getTemplateDetailsInProgress)
2527
+ );
2499
2528
 
2500
2529
  if (!isLoading) {
2501
2530
  isLoading = this.state.loadingStatus < 2;
@@ -2503,7 +2532,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2503
2532
  // if (isLoading) {
2504
2533
  // this.props.creativesContainerActions.hideCreativesContanerLoader();
2505
2534
  // }
2506
- if (!isLoading && this.props.setIsLoadingContent) {
2535
+ if (!isLoading && setIsLoadingContent) {
2507
2536
  this.props.setIsLoadingContent(isLoading);
2508
2537
  }
2509
2538
  return isLoading;
@@ -2552,30 +2581,26 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2552
2581
  </div>
2553
2582
  </div>
2554
2583
  );
2555
- getImagePreviewContent = () => (
2556
- <div key="creatives-email-add-image-container">
2557
- {this.getFilterContent()}
2558
- <Pagination onPageChange={() => { this.fetchAllAssets({getNextPage: true}); }} paginationSelector="pagination-container">
2559
- {/* <CardGrid
2560
- listItem={this.prepareImageData()}
2561
- filterContent={filterContent}
2562
- onHoverItem={this.handleOnHoverItem}
2563
- onItemClick={this.handleOnItemClick}
2564
- colNumber={2}
2565
- enablePagination
2566
- isLoading={}
2567
- /> */}
2568
- {this.props.Email.assetList && this.props.Email.assetList.length ? this.getTemplateDataForGrid({
2569
- isLoading: this.props.Email.fetchingAllAssets,
2570
- loadingTip: <FormattedMessage {...messages.loadingImages}/>,
2571
- channel: this.state.channel,
2572
- templates: this.props.Email.assetList,
2573
- handlers: {onItemClick: this.handleOnItemClick}})
2574
- : <FormattedMessage {...messages.noImgInGallery}/>}
2575
-
2576
- </Pagination>
2577
- </div>
2578
- );
2584
+ getImagePreviewContent = () => {
2585
+ const { assetList = [], fetchingAllAssets, fetchAllAssetSuccess } = this.props.Email || {};
2586
+ return (
2587
+ <div key="creatives-email-add-image-container">
2588
+ {this.getFilterContent()}
2589
+ <Pagination onPageChange={() => { this.fetchAllAssets({getNextPage: true}); }} paginationSelector="pagination-container">
2590
+ {(!fetchingAllAssets && (!fetchAllAssetSuccess || (fetchAllAssetSuccess && !assetList.length))) ? (
2591
+ <FormattedMessage {...messages.noImgInGallery}/>
2592
+ ) : this.getTemplateDataForGrid({
2593
+ isLoading: fetchingAllAssets,
2594
+ loadingTip: <FormattedMessage {...messages.loadingImages}/>,
2595
+ channel: this.state.channel,
2596
+ templates: assetList,
2597
+ handlers: {onItemClick: this.handleOnItemClick}})
2598
+ }
2599
+
2600
+ </Pagination>
2601
+ </div>
2602
+ );
2603
+ };
2579
2604
 
2580
2605
  showTestAndPreviewIcons = (action) => {
2581
2606
  const { formData = [] } = this.state;
@@ -2602,6 +2627,29 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2602
2627
  </CapButton>
2603
2628
  );
2604
2629
  };
2630
+ saveBeeInstance = (instance) => {
2631
+ this.beeInstance = instance;
2632
+ }
2633
+ saveBeeData = (json, html) => {
2634
+ this.setState((prevState) => {
2635
+ const { currentTab, formData } = _.cloneDeep(prevState);
2636
+ const activeTab = formData[currentTab - 1].activeTab;
2637
+ formData[currentTab - 1][activeTab]['template-content'] = html;
2638
+ formData[currentTab - 1][activeTab]['json-content'] = json;
2639
+
2640
+ formData.base[activeTab]['template-content'] = html;
2641
+ formData.base[activeTab]['json-content'] = json;
2642
+
2643
+ return {
2644
+ ...prevState,
2645
+ formData,
2646
+ };
2647
+ }, () => {
2648
+ this.setState({
2649
+ startValidation: true,
2650
+ });
2651
+ });
2652
+ }
2605
2653
 
2606
2654
  render() {
2607
2655
  // const pageHeading = (this.state.isEdit) ? this.props.intl.formatMessage(messages.editHeading) : this.props.intl.formatMessage(messages.createHeading);
@@ -2611,7 +2659,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2611
2659
  const previewHeader = (<h3>{this.props.intl.formatMessage(messages.h3emailPreview)}</h3>);
2612
2660
  const imagePreviewHeader = (<h3>{this.props.intl.formatMessage(messages.h3imageSelection)}</h3>);
2613
2661
  const imagePreviewContent = this.getImagePreviewContent();
2614
- const { selectedOfferDetails, getDefaultTags } = this.props;
2662
+ const { selectedOfferDetails, getDefaultTags, Email: { CmsSettings = {} } = {} } = this.props;
2615
2663
  if (!this.props.currentOrgDetails || !this.props.currentOrgDetails.basic_details) {
2616
2664
  return (<div>Loading...</div>);
2617
2665
  }
@@ -2672,6 +2720,11 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2672
2720
  saveForm={this.state.saveForm}
2673
2721
  stopValidation={this.stopValidation}
2674
2722
  selectedOfferDetails={selectedOfferDetails}
2723
+ saveBeeInstance={this.saveBeeInstance}
2724
+ saveBeeData={this.saveBeeData}
2725
+ uuid={CmsSettings.uuid}
2726
+ type={CmsSettings.type}
2727
+ isEmailLoading={isLoading}
2675
2728
  /> : ''}
2676
2729
  </Col>
2677
2730
  </Row>
@@ -2690,8 +2743,9 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2690
2743
  show={this.state.showImageSelectionBox}
2691
2744
  handleClose={this.handleImagePreviewClose}
2692
2745
  isLoading={this.props.Email.fetchingAllAssets}
2693
- size="size-l"
2746
+ size="size-xl"
2694
2747
  />
2748
+ {/* <div id="bee-plugin-container" style={{ height: '600px'}}></div> */}
2695
2749
  {this.state.showConfirmationModal && this.renderConfirmationModal()}
2696
2750
  </div>
2697
2751
  );