@capillarytech/creatives-library 9.0.23 → 9.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "9.0.23",
4
+ "version": "9.0.26",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -194,10 +194,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
194
194
  // const formData = _.cloneDeep(this.state.formData);
195
195
  if (this.props.params.id || (this.props.location.query.module === "library" && this.props.templateData && !_.isEmpty(this.props.templateData))) {
196
196
  this.setState({isEdit: true}, () => {
197
- // Embedded campaign content is authoritative via the inline templateData
198
- // prop; fetching by id would pull reusable-template data and drop the
199
- // inline BEE json_content. Only fetch for real reusable-template edits.
200
- if (this.props.params.id && this.props.location.query.type !== 'embedded') {
197
+ if (this.props.params.id) {
201
198
  this.props.actions.getTemplateDetails(this.props.params.id, 'email');
202
199
  }
203
200
  });
@@ -240,6 +237,39 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
240
237
  this.props.actions.getCmsSetting(BEE_PLUGIN, dragDropId, 'create', undefined, isBEESupport, isBEEAppEnable);
241
238
  }
242
239
  }
240
+ // The <Email> direct path (SlideBoxContent routes here when
241
+ // templateData.base.is_drag_drop is true) bypasses EmailWrapper/useEmailWrapper,
242
+ // so Templates.BEETemplate is never seeded and a created/edited drag-drop would
243
+ // open as the HTML editor. Seed isDragDrop + the BEE plugin from the inline
244
+ // templateData so it opens as BEE.
245
+ if (_.isEmpty(this.props.Templates.BEETemplate) && !_.isEmpty(this.props.templateData)) {
246
+ const td = this.props.templateData;
247
+ const activeTab = _.get(td, 'versions.base.activeTab', 'en');
248
+ // This path bypasses setEditData, so seed the subject from the inline
249
+ // templateData too (otherwise the title is empty for a created drag-drop).
250
+ const inlineSubject = _.get(td, 'base.subject')
251
+ || _.get(td, `versions.base.${activeTab}.subject`)
252
+ || _.get(td, 'versions.base.subject')
253
+ || _.get(td, 'emailSubject')
254
+ || _.get(td, 'subject');
255
+ if (inlineSubject) {
256
+ formData['template-subject'] = inlineSubject;
257
+ }
258
+ const inlineIsDragDrop = _.get(td, 'base.is_drag_drop')
259
+ || _.get(td, `versions.base.${activeTab}.is_drag_drop`)
260
+ || _.get(td, 'versions.base.is_drag_drop')
261
+ || _.get(td, 'is_drag_drop');
262
+ if ((inlineIsDragDrop === true || inlineIsDragDrop === 1) && isBEEAppEnable) {
263
+ this.setState({ isDragDrop: true });
264
+ const inlineDragDropId = _.get(td, 'base.drag_drop_id')
265
+ || _.get(td, 'base.id')
266
+ || _.get(td, `versions.base.${activeTab}.drag_drop_id`)
267
+ || _.get(td, `versions.base.${activeTab}.id`)
268
+ || _.get(td, 'drag_drop_id')
269
+ || _.get(td, 'id');
270
+ this.props.actions.getCmsSetting(BEE_PLUGIN, inlineDragDropId, this.props.params.id ? 'open' : 'create', undefined, isBEESupport, isBEEAppEnable);
271
+ }
272
+ }
243
273
  const hasUploadedContent = !this.props.params?.id && this.props.Templates?.selectedEmailLayout && !_.isEmpty(formData);
244
274
  this.setState({
245
275
  content: (this.props.Templates.selectedEmailLayout ? this.props.Templates.selectedEmailLayout : ''),
@@ -462,7 +492,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
462
492
  }
463
493
  }
464
494
 
465
- if (this.state.isEdit && !this.state.editDataSet && !_.isEmpty(nextProps.Email.templateDetails) && !_.isEmpty(this.state.schema) && nextProps.location.query.type !== 'embedded') {
495
+ if (this.state.isEdit && !this.state.editDataSet && !_.isEmpty(nextProps.Email.templateDetails) && !_.isEmpty(this.state.schema)) {
466
496
  this.setState({editDataSet: true}, () => {
467
497
  this.setEditData(nextProps.Email.templateDetails);
468
498
  // Update template name in parent if available
@@ -473,7 +503,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
473
503
  }
474
504
  });
475
505
  }
476
- if (this.state.isEdit && nextProps.location.query.module === "library" && !_.isEmpty(nextProps.templateData) && (!nextProps.params.id || nextProps.location.query.type === "embedded") && !nextProps.isGetFormData && _.isEmpty(_.get(this, `state.formData['template-subject']`))) {
506
+ if (this.state.isEdit && nextProps.location.query.module === "library" && !_.isEmpty(nextProps.templateData) && !this.props.params.id && !nextProps.isGetFormData && _.isEmpty(_.get(this, `state.formData['template-subject']`))) {
477
507
  this.startTemplateCreation(nextProps.templateData);
478
508
  }
479
509
  if (nextProps.location.query.module === 'library' && nextProps.isGetFormData && (this.props.isGetFormData !== nextProps.isGetFormData)) {
@@ -556,10 +586,21 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
556
586
  const beeToken = `BEEeditor${currentTab > 1 ? currentTab : ''}token`;
557
587
  let beeJsonValue = '';
558
588
  const selectedId = _.get(this.props, 'Email.templateDetails._id', '') || _.get(this.props, 'Templates.BEETemplate.versions.base.drag_drop_id', '');
559
-
589
+
590
+ // Embedded journey content: the inline templateData carries the user's
591
+ // edited BEE json (base.json_content), which is more current than the
592
+ // reusable template fetched via getTemplateDetails. Prefer it so a
593
+ // re-edit shows the saved edit instead of the original template. For
594
+ // the create/gallery flow this key is absent, so we fall through to the
595
+ // existing sources (template details / BEETemplate) unchanged.
596
+ beeJsonValue = _.get(nextProps, 'templateData.base.json_content', '')
597
+ || _.get(nextProps, 'templateData.json_content', '');
598
+
560
599
  // Get beeJsonValue from template data - check multiple sources
561
600
  // First check if it's already in formData (from setEditData)
562
- beeJsonValue = _.get(this.state, `formData[${currentTab - 1}][${langId}].json-content`, '');
601
+ if (!beeJsonValue) {
602
+ beeJsonValue = _.get(this.state, `formData[${currentTab - 1}][${langId}].json-content`, '');
603
+ }
563
604
 
564
605
  // Also check formData.base
565
606
  if (!beeJsonValue) {
@@ -617,14 +658,9 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
617
658
  'json-content': finalBeeJsonValue,
618
659
  };
619
660
 
620
- // Ensure template-subject is preserved at the top level. For embedded
621
- // content templateDetails isn't fetched, so also read the subject from
622
- // the inline templateData prop (base.subject / subject / emailSubject).
661
+ // Ensure template-subject is preserved at the top level
623
662
  if (formData['template-subject'] === undefined || formData['template-subject'] === '') {
624
- const subjectFromEditData = _.get(nextProps, 'Email.templateDetails.versions.base.subject', '')
625
- || _.get(nextProps, 'templateData.base.subject', '')
626
- || _.get(nextProps, 'templateData.subject', '')
627
- || _.get(nextProps, 'templateData.emailSubject', '');
663
+ const subjectFromEditData = _.get(nextProps, 'Email.templateDetails.versions.base.subject', '');
628
664
  if (subjectFromEditData) {
629
665
  formData['template-subject'] = subjectFromEditData;
630
666
  }
@@ -1147,7 +1183,14 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
1147
1183
  const type = this.props.location.query.type;
1148
1184
 
1149
1185
  formData['template-name'] = editData.name;
1150
- const subject = _.get(editData, 'versions.base.subject', '');
1186
+ // Prefer the inline edited subject (embedded journey content: base.subject /
1187
+ // emailSubject) over the fetched template's subject, so subject edits persist
1188
+ // on re-open. setEditData runs once (guarded by editDataSet), so this is a
1189
+ // one-time load-time override and won't fight typing in the subject field.
1190
+ const inlineSubject = _.get(this.props, 'templateData.base.subject', '')
1191
+ || _.get(this.props, 'templateData.emailSubject', '')
1192
+ || _.get(this.props, 'templateData.subject', '');
1193
+ const subject = inlineSubject || _.get(editData, 'versions.base.subject', '');
1151
1194
  formData['template-subject'] = subject;
1152
1195
  formData.base = editData.versions.base;
1153
1196
 
@@ -2478,11 +2521,8 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
2478
2521
  formData[0].selectedLanguages = [];
2479
2522
  let tabKey;
2480
2523
  if ((this.props.location.query.isLanguageSupport === undefined || this.props.location.query.isLanguageSupport === 'false')) {
2481
- // Prefer the saved subject from the inline templateData (base.subject);
2482
- // fall back to any existing value. The previous `=== '' ? '' :` guard kept
2483
- // an empty subject on open for embedded content (which routes through
2484
- // startTemplateCreation), dropping data.base.subject.
2485
- formData['template-subject'] = data?.base?.subject || formData?.['template-subject'] || '';
2524
+ // If formData['template-subject'] is empty, assign an empty string; otherwise, retain its current value or use data.base.subject.
2525
+ formData['template-subject'] = formData?.['template-subject'] === '' ? '' : (data?.base?.subject || '');
2486
2526
  const baseLanguage = this.props.currentOrgDetails.basic_details.base_language;
2487
2527
  let languageIndex = _.findIndex(this.supportedLanguages, {iso_code: baseLanguage});
2488
2528
 
@@ -234,10 +234,10 @@ const useEmailWrapper = ({
234
234
  // New flow: When template details are loaded and it's a BEE template, set it in Templates.BEETemplate
235
235
  // This allows Email component to properly initialize and call getCmsSetting
236
236
  const hasTemplateDetails = Email?.templateDetails && !isEmpty(Email.templateDetails);
237
- // An inline templateData prop (e.g. library add-creative -> select template)
238
- // is authoritative when template details weren't fetched (the by-id fetch is
239
- // skipped whenever a templateData prop is present). Without seeding from it,
240
- // setBEETemplate never fires for that flow and a BEE template opens as HTML.
237
+ // Inline templateData (e.g. a freshly-created drag-drop content, or a
238
+ // library add-creative -> select-template) is authoritative when no template
239
+ // details were fetched. Without seeding BEETemplate from it, setBEETemplate
240
+ // never fires for that flow and a BEE template opens as the HTML editor.
241
241
  const hasTemplateDataProp = templateData && !isEmpty(templateData);
242
242
  // Note: We check Email?.BEETemplate as a proxy, but the actual BEETemplate is in Templates reducer
243
243
  // The Email component will detect it via this.props.Templates.BEETemplate
@@ -300,7 +300,7 @@ const useEmailWrapper = ({
300
300
  }
301
301
  }
302
302
 
303
- // Reset ref when template changes (template details cleared and no inline prop)
303
+ // Reset ref when template changes (template details cleared)
304
304
  if (!hasTemplateDetails && !hasTemplateDataProp && beeTemplateSetRef.current) {
305
305
  beeTemplateSetRef.current = false;
306
306
  }