@capillarytech/creatives-library 7.17.197 → 7.17.198

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": "7.17.197",
4
+ "version": "7.17.198",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -1,8 +1,11 @@
1
1
  import React from 'react';
2
2
  import { FormattedMessage } from 'react-intl';
3
+ import { get } from 'lodash';
4
+ import { EMBEDDED } from '../v2Containers/Whatsapp/constants';
5
+ import { EDIT, PREVIEW } from '../v2Containers/App/constants';
3
6
 
4
7
  export const apiMessageFormatHandler = (id, fallback) => (
5
- <FormattedMessage id={id} defaultMessage={fallback} />
8
+ <FormattedMessage id={id} defaultMessage={fallback} />
6
9
  );
7
10
 
8
11
  export const addBaseToTemplate = (template) => {
@@ -20,3 +23,10 @@ export const addBaseToTemplate = (template) => {
20
23
  }
21
24
  return template;
22
25
  };
26
+
27
+ export const isEmbeddedEditOrPreview = (props) => {
28
+ const queryType = String(get(props, 'location.query.type', '')).toLowerCase();
29
+ const creativesMode = String(get(props, 'creativesMode', '')).toLowerCase();
30
+ return queryType === EMBEDDED.toLowerCase() &&
31
+ (creativesMode === EDIT.toLowerCase() || creativesMode === PREVIEW.toLowerCase());
32
+ };
@@ -1,7 +1,10 @@
1
1
  import "@testing-library/jest-dom";
2
+ import get from 'lodash/get';
2
3
  import { getTreeStructuredTags } from "../common";
3
4
  import * as mockdata from "./common.mockdata";
4
- import { addBaseToTemplate } from "../commonUtils";
5
+ import { addBaseToTemplate, isEmbeddedEditOrPreview } from "../commonUtils";
6
+ import { EMBEDDED, FULL } from "../../v2Containers/Whatsapp/constants";
7
+ import { CREATE, EDIT, PREVIEW } from "../../v2Containers/App/constants";
5
8
 
6
9
  jest.mock('@capillarytech/cap-ui-utils', () => ({
7
10
  Auth: {
@@ -12,6 +15,8 @@ jest.mock('@capillarytech/cap-ui-utils', () => ({
12
15
  },
13
16
  }));
14
17
 
18
+ jest.mock('lodash/get');
19
+
15
20
  describe("common utils test", () => {
16
21
  it("test for getTreeStructuredTags when tagsList is not empty", () => {
17
22
  expect(getTreeStructuredTags({tagsList: mockdata.tagsList})).toEqual(mockdata.output2);
@@ -77,3 +82,58 @@ describe('addBaseToTemplate', () => {
77
82
  expect(template).toEqual(originalTemplateCopy);
78
83
  });
79
84
  });
85
+
86
+ describe('isEmbeddedEditOrPreview', () => {
87
+ beforeEach(() => {
88
+ get.mockClear();
89
+ });
90
+
91
+ it('should return true when query type is embedded and creatives mode is edit', () => {
92
+ const props = {
93
+ location: {
94
+ query: {
95
+ type: EMBEDDED,
96
+ },
97
+ },
98
+ creativesMode: EDIT,
99
+ };
100
+ expect(isEmbeddedEditOrPreview(props)).toBe(true);
101
+ });
102
+
103
+ it('should return true when query type is embedded and creatives mode is preview', () => {
104
+
105
+ const props = {
106
+ location: {
107
+ query: {
108
+ type: EMBEDDED,
109
+ },
110
+ },
111
+ creativesMode: PREVIEW,
112
+ };
113
+ expect(isEmbeddedEditOrPreview(props)).toBe(true);
114
+ });
115
+
116
+ it('should return false when query type is not embedded', () => {
117
+ const props = {
118
+ location: {
119
+ query: {
120
+ type: FULL,
121
+ },
122
+ },
123
+ creativesMode: EDIT,
124
+ };
125
+ expect(isEmbeddedEditOrPreview(props)).toBe(false);
126
+ });
127
+
128
+ it('should return false when creatives mode is not edit or preview', () => {
129
+ const props = {
130
+ location: {
131
+ query: {
132
+ type: EMBEDDED,
133
+ },
134
+ },
135
+ creativesMode: CREATE,
136
+ };
137
+ expect(isEmbeddedEditOrPreview(props)).toBe(false);
138
+ });
139
+ });
@@ -154,6 +154,7 @@ export function SlideBoxContent(props) {
154
154
  getCmsTemplatesInProgress = false,
155
155
  moduleType,
156
156
  showLiquidErrorInFooter,
157
+ creativesMode,
157
158
  } = props;
158
159
  const type = (messageDetails.type || '').toLowerCase(); // type is context in get tags values : outbound | dvs | referral | loyalty | coupons
159
160
  const query = { type: !isFullMode && 'embedded', module: isFullMode ? 'default' : 'library', isEditFromCampaigns: (templateData || {}).isEditFromCampaigns};
@@ -655,6 +656,7 @@ export function SlideBoxContent(props) {
655
656
  onTestContentClicked={onTestContentClicked}
656
657
  type={type}
657
658
  hideTestAndPreviewBtn={hideTestAndPreviewBtn}
659
+ creativesMode={creativesMode}
658
660
  />
659
661
  }
660
662
  {isCreateMPush &&
@@ -921,5 +923,6 @@ SlideBoxContent.propTypes = {
921
923
  getCmsTemplatesInProgress: PropTypes.bool,
922
924
  moduleType: PropTypes.string,
923
925
  showLiquidErrorInFooter: PropTypes.bool,
926
+ creativesMode: PropTypes.string,
924
927
  };
925
928
  export default SlideBoxContent;
@@ -1312,7 +1312,8 @@ export class Creatives extends React.Component {
1312
1312
  getCmsTemplatesInProgress={this.props.Templates?.getCmsTemplatesInProgress}
1313
1313
  moduleType={this.props.messageDetails?.type}
1314
1314
  showLiquidErrorInFooter={this.showLiquidErrorInFooter}
1315
- />
1315
+ creativesMode={creativesMode}
1316
+ />
1316
1317
  }
1317
1318
  footer={this.shouldShowFooter() &&
1318
1319
  <SlideBoxFooter
@@ -33,3 +33,5 @@ export const GET_WECRM_ACCOUNTS_FAILURE = "app/v2Containers/MobilePush/GET_WECRM
33
33
  export const GET_MOBILEPUSH_TEMPLATES_LIST_REQUEST = 'app/v2Containers/WeChat/GET_MOBILEPUSH_TEMPLATES_LIST_REQUEST';
34
34
  export const GET_MOBILEPUSH_TEMPLATES_LIST_SUCCESS = 'app/v2Containers/WeChat/GET_MOBILEPUSH_TEMPLATES_LIST_SUCCESS';
35
35
  export const GET_MOBILEPUSH_TEMPLATES_LIST_FAILURE = 'app/v2Containers/WeChat/GET_MOBILEPUSH_TEMPLATES_LIST_FAILURE';
36
+
37
+ export const MAPP_SDK = 'MAPP_SDK';
@@ -34,6 +34,8 @@ import { GA } from '@capillarytech/cap-ui-utils';
34
34
  import { EDIT, TRACK_EDIT_MPUSH } from '../../App/constants';
35
35
  import { MOBILE_PUSH } from '../../CreativesContainer/constants';
36
36
  import { getCdnUrl } from '../../../utils/cdnTransformation';
37
+ import { MAPP_SDK } from './constants';
38
+ import { isEmbeddedEditOrPreview } from '../../../utils/commonUtils';
37
39
 
38
40
  const PrefixWrapper = styled.div`
39
41
  margin-right: 16px;
@@ -105,11 +107,23 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
105
107
  } else if (nextProps.isGetFormData && this.props.isGetFormData !== nextProps.isGetFormData && this.props.isFullMode && !this.props.Create.createTemplateInProgress) {
106
108
  this.startValidation();
107
109
  }
108
- const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount :
109
- (!_.isEmpty(this.props.Edit.selectedWeChatAccount) ? this.props.Edit.selectedWeChatAccount : nextProps.Edit.selectedWeChatAccount));
110
+ let selectedWeChatAccount = {};
111
+ if (isEmbeddedEditOrPreview(this.props)) {
112
+ selectedWeChatAccount = !_.isEmpty(this.props.Edit.selectedWeChatAccount)
113
+ ? this.props.Edit.selectedWeChatAccount
114
+ : nextProps.Edit.selectedWeChatAccount;
115
+ } else if (!_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
116
+ selectedWeChatAccount = this.props.Templates.selectedWeChatAccount;
117
+ }
118
+
110
119
  if (this.props.location.query.type === 'embedded' && !nextProps.Edit.fetchingWeCrmAccounts && !_.isEqual(this.props.Edit.weCrmAccounts, nextProps.Edit.weCrmAccounts) && (!selectedWeChatAccount || _.isEmpty(selectedWeChatAccount))) {
111
120
  this.setMobilePushAccountOptions(nextProps.Edit.weCrmAccounts, get(this.props, "templateData.definition.accountId"));
112
121
  }
122
+ // Check if the query type is 'embedded' and the creatives mode is either 'edit' or 'preview'. Also, ensure that the selected WeChat account ID is not equal to the account ID in the template details.
123
+ // If all conditions are met, set the mobile push account options using the provided weCrmAccounts and the account ID from templateData.
124
+ if (isEmbeddedEditOrPreview(this.props) && !_.isEqual(this.props.Edit.selectedWeChatAccount?.id, this.props.Edit.templateDetails?.definition?.accountId)) {
125
+ this.setMobilePushAccountOptions(nextProps.Edit.weCrmAccounts, get(this.props, "templateData.definition.accountId"));
126
+ }
113
127
  if (!_.isEmpty(nextProps.Edit.selectedWeChatAccount) && !_.isEqual(this.props.Edit.selectedWeChatAccount, nextProps.Edit.selectedWeChatAccount) && (this.props.location.query.type === 'embedded') && this.props.location.query.module === "loyalty") {
114
128
  const params = {
115
129
  name: '',
@@ -213,8 +227,23 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
213
227
  }
214
228
  };
215
229
 
230
+ getWeChatAccount = () => {
231
+ let selectedWeChatAccount = {};
232
+
233
+ if (isEmbeddedEditOrPreview(this.props)) {
234
+ if (!_.isEmpty(this.props.Edit.selectedWeChatAccount)) {
235
+ selectedWeChatAccount = this.props.Edit.selectedWeChatAccount;
236
+ } else {
237
+ selectedWeChatAccount = this.props.Templates.selectedWeChatAccount;
238
+ }
239
+ } else if (!_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
240
+ selectedWeChatAccount = this.props.Templates.selectedWeChatAccount;
241
+ }
242
+ return selectedWeChatAccount;
243
+ }
244
+
216
245
  onLinkTypeChange = (eventTriggered, formData, field, currentTab, inputSchema) => {
217
- const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
246
+ const selectedWeChatAccount = this.getWeChatAccount();
218
247
  const schema = inputSchema ? _.cloneDeep(inputSchema) : _.cloneDeep(this.state.schema);
219
248
  const tabIndex = currentTab || this.state.currentTab;
220
249
  const inputFields = get(schema, `containers[0].panes[${tabIndex - 1}].sections[0].childSections[0].childSections[0].inputFields`);
@@ -330,27 +359,40 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
330
359
  this.setState({formData, accountsOptions: accounts.map((acc) => ({key: acc.id, label: acc.name, value: acc.id}))});
331
360
  };
332
361
 
362
+ createDefinition = (account) => ({
363
+ accountId: account?.id,
364
+ licenseCode: account?.sourceAccountIdentifier,
365
+ gatewayId: account?.configs?.gatewayId,
366
+ gatewayAccountId: account?.configs?.gatewayAccountId,
367
+ sourceType: account?.sourceTypeName,
368
+ });
369
+
333
370
  getTransformedData = (formData) => {
334
- const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
371
+ const selectedWeChatAccount = this.getWeChatAccount();
335
372
  const obj = _.cloneDeep(this.state.editData);
336
373
  obj.versions = {
337
374
  base: {},
338
375
  };
339
376
  obj.type = 'MOBILEPUSH';
340
377
  obj.name = formData['template-name'];
341
- if(this.props?.Templates?.selectedWeChatAccount?.sourceTypeName === 'MAPP_SDK') {
342
- obj.definition = {
343
- accountId: selectedWeChatAccount.id,
344
- licenseCode: selectedWeChatAccount.sourceAccountIdentifier,
345
- gatewayId: selectedWeChatAccount.configs.gatewayId,
346
- gatewayAccountId: selectedWeChatAccount.configs.gatewayAccountId,
347
- sourceType: selectedWeChatAccount.sourceTypeName,
348
- };
378
+
379
+ if (isEmbeddedEditOrPreview(this.props)) {
380
+ if (get(this.props, 'Edit.selectedWeChatAccount.sourceTypeName') === MAPP_SDK) {
381
+ obj.definition = this.createDefinition(selectedWeChatAccount);
382
+ } else {
383
+ obj.definition = {
384
+ accountId: selectedWeChatAccount?.id,
385
+ licenseCode: selectedWeChatAccount?.sourceAccountIdentifier,
386
+ sourceType: selectedWeChatAccount?.sourceTypeName,
387
+ };
388
+ }
389
+ } else if (get(this.props, 'Templates.selectedWeChatAccount.sourceTypeName') === MAPP_SDK) {
390
+ obj.definition = this.createDefinition(selectedWeChatAccount);
349
391
  } else {
350
392
  obj.definition = {
351
393
  accountId: selectedWeChatAccount?.id,
352
- licenseCode: selectedWeChatAccount.sourceAccountIdentifier,
353
- sourceType: selectedWeChatAccount.sourceTypeName,
394
+ licenseCode: selectedWeChatAccount?.sourceAccountIdentifier,
395
+ sourceType: selectedWeChatAccount?.sourceTypeName,
354
396
  };
355
397
  }
356
398
  if (this.props.location.query && this.props.location.query.module !== 'dvs') {
@@ -561,7 +603,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
561
603
  };
562
604
 
563
605
  getLinkName = (link) => {
564
- const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
606
+ const selectedWeChatAccount = this.getWeChatAccount();
565
607
  const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
566
608
  const deepLinkOptions = _.filter(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (l) => l.link === link);
567
609
  if (deepLinkOptions[0]) {
@@ -960,7 +1002,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
960
1002
  showSelectedIosCta = (inputSchema, field, tab, selectedConfig) => {
961
1003
  const currentTab = tab || this.state.currentTab;
962
1004
  const schema = inputSchema ? _.cloneDeep(inputSchema) : _.cloneDeep(this.state.schema);
963
- const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1005
+ const selectedWeChatAccount = this.getWeChatAccount();
964
1006
  const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
965
1007
  const deepLinkOptions = _.map(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (link) => ({label: link.name, value: link.link, title: link.link }) );
966
1008
 
@@ -1088,7 +1130,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
1088
1130
  };
1089
1131
 
1090
1132
  deletePrimaryCTA = (event) => {
1091
- const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1133
+ const selectedWeChatAccount = this.getWeChatAccount();
1092
1134
  const id = event.currentTarget.id;
1093
1135
  const schema = _.cloneDeep(this.state.schema);
1094
1136
  // const eventsMap = _.cloneDeep(this.state.eventsMap);
@@ -1188,7 +1230,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
1188
1230
  };
1189
1231
 
1190
1232
  deleteSecondaryCTA = (event) => {
1191
- const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1233
+ const selectedWeChatAccount = this.getWeChatAccount();
1192
1234
  const id = event.currentTarget.id;
1193
1235
  if (id === "secondary-cta-0-delete") {
1194
1236
  const secCta2 = document.getElementById("secondary-cta-1-delete");
@@ -1475,8 +1517,12 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
1475
1517
  if (this.props.location.query.type === 'embedded' && temp.id === "mobilepush-accounts" ) {
1476
1518
  temp.options = this.state.templateOptions ? this.state.accountsOptions : [];
1477
1519
  }
1478
- if (temp.id === "mobile-push-preview" && this.props.Templates.selectedWeChatAccount && !_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
1479
- temp.content.appName = this.props.Templates.selectedWeChatAccount.name;
1520
+ if (temp.id === "mobile-push-preview") {
1521
+ if (isEmbeddedEditOrPreview(this.props) && this.props.Edit.selectedWeChatAccount && !_.isEmpty(this.props.Edit.selectedWeChatAccount)) {
1522
+ temp.content.appName = this.props.Edit.selectedWeChatAccount.name;
1523
+ } else if (this.props.Templates.selectedWeChatAccount && !_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
1524
+ temp.content.appName = this.props.Templates.selectedWeChatAccount.name;
1525
+ }
1480
1526
  }
1481
1527
  _.forEach(col.supportedEvents, (event) => {
1482
1528
  temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
@@ -1561,7 +1607,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
1561
1607
  };
1562
1608
 
1563
1609
  showCtaKeys = (eventTriggered, formData, field, tabIndex, schemaInput) => {
1564
- const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1610
+ const selectedWeChatAccount = this.getWeChatAccount();
1565
1611
  const currentTab = tabIndex || this.state.currentTab;
1566
1612
  const schema = _.cloneDeep(schemaInput || this.state.schema);
1567
1613
  const eventsMap = _.cloneDeep(this.state.eventsMap);
@@ -1616,7 +1662,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
1616
1662
  return schema;
1617
1663
  };
1618
1664
  addPrimaryCta = (flag, formData, field, inputSchema, currentTab) => {
1619
- const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1665
+ const selectedWeChatAccount = this.getWeChatAccount();
1620
1666
  const id = field.id;
1621
1667
  const schema = inputSchema ? _.cloneDeep(inputSchema) : _.cloneDeep(this.state.schema);
1622
1668
  const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
@@ -1649,7 +1695,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
1649
1695
  const tabIndex = currentTab || this.state.currentTab;
1650
1696
  const formDataCopy = cloneDeep(formData);
1651
1697
  const schema = inputSchema ? _.cloneDeep(inputSchema) : _.cloneDeep(this.state.schema);
1652
- const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1698
+ const selectedWeChatAccount = this.getWeChatAccount();
1653
1699
  const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
1654
1700
  const deepLinkOptions = selectedWeChatAccount ? _.map(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (link) => ({label: link.name, value: link.link, title: link.link }) ) : [];
1655
1701
  const inputFields = get(schema, `containers[0].panes[${tabIndex - 1}].sections[0].childSections[0].childSections[0].inputFields`);
@@ -1698,7 +1744,12 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
1698
1744
  if (!_.isEmpty(actionText)) {
1699
1745
  this.deleteSecondaryCtaIos();
1700
1746
  }
1701
- this.props.actions.getIosCtas(this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier);//TODO: need to get license code of accoutn and send as arg
1747
+ if (isEmbeddedEditOrPreview(this.props)) {
1748
+ this.props.actions.getIosCtas(this.props.Edit.selectedWeChatAccount.sourceAccountIdentifier);
1749
+ } else {
1750
+ this.props.actions.getIosCtas(this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier);
1751
+ }
1752
+ //TODO: need to get license code of accoutn and send as arg
1702
1753
  } else {
1703
1754
  this.deleteSecondaryCtaIos(() => { // oncick of change
1704
1755
  this.setState({showIosCtaTable: true});
@@ -1953,6 +2004,7 @@ Edit.propTypes = {
1953
2004
  onValidationFail: PropTypes.bool,
1954
2005
  onPreviewContentClicked: PropTypes.func,
1955
2006
  onTestContentClicked: PropTypes.func,
2007
+ creativesMode: PropTypes.string,
1956
2008
  };
1957
2009
 
1958
2010
  const mapStateToProps = createStructuredSelector({