@capillarytech/creatives-library 7.17.203 → 7.17.204
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
package/services/api.js
CHANGED
|
@@ -357,10 +357,11 @@ export const getUserList = () => {
|
|
|
357
357
|
return API.get(url);// request(url, getAPICallObject('GET'));
|
|
358
358
|
};
|
|
359
359
|
|
|
360
|
-
export const fetchSchemaForEntity = ({queryParams}) => {
|
|
360
|
+
export const fetchSchemaForEntity = async ({queryParams}) => {
|
|
361
361
|
if (queryParams.version === "v2" && queryParams.type === "LAYOUT") {
|
|
362
362
|
const schema = getSchema(queryParams.layout);
|
|
363
|
-
|
|
363
|
+
// Added async/await to ensure the schema object is resolved before returning it
|
|
364
|
+
return await schema.then((layout) => layout).catch((err) => {
|
|
364
365
|
console.error(err);
|
|
365
366
|
});
|
|
366
367
|
}
|
|
@@ -11,8 +11,10 @@ import {
|
|
|
11
11
|
getTemplateInfoById,
|
|
12
12
|
askAiraForLiquid,
|
|
13
13
|
getLiquidTags,
|
|
14
|
+
fetchSchemaForEntity,
|
|
14
15
|
} from '../api';
|
|
15
16
|
import { mockData } from './mockData';
|
|
17
|
+
import getSchema from '../getSchema';
|
|
16
18
|
const sampleFile = require('../../assets/line.png');
|
|
17
19
|
|
|
18
20
|
let mockDecompressJsonObject;
|
|
@@ -24,6 +26,8 @@ jest.mock('@capillarytech/cap-ui-utils', () => {
|
|
|
24
26
|
};
|
|
25
27
|
});
|
|
26
28
|
|
|
29
|
+
jest.mock('../getSchema', () => jest.fn());
|
|
30
|
+
|
|
27
31
|
describe('getSenderDetails -- Test with valid responses', () => {
|
|
28
32
|
it('Should return correct response', () =>
|
|
29
33
|
expect(getSenderDetails('WHATSAPP', -1)).toEqual(Promise.resolve()));
|
|
@@ -438,4 +442,33 @@ describe('getLiquidTags -- Test with various responses', () => {
|
|
|
438
442
|
error: 'Internal Server Error',
|
|
439
443
|
});
|
|
440
444
|
});
|
|
441
|
-
});
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
describe('fetchSchemaForEntity', () => {
|
|
448
|
+
it('should fetch schema for version v2 and type LAYOUT', async () => {
|
|
449
|
+
const queryParams = { version: 'v2', type: 'LAYOUT', layout: 'testLayout' };
|
|
450
|
+
const mockLayout = { id: 'layout1', name: 'Test Layout' };
|
|
451
|
+
|
|
452
|
+
getSchema.mockReturnValue(Promise.resolve(mockLayout));
|
|
453
|
+
|
|
454
|
+
const result = await fetchSchemaForEntity({ queryParams });
|
|
455
|
+
|
|
456
|
+
expect(getSchema).toHaveBeenCalledWith(queryParams.layout);
|
|
457
|
+
expect(result).toEqual(mockLayout);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it('should handle errors when fetching schema', async () => {
|
|
461
|
+
const queryParams = { version: 'v2', type: 'LAYOUT', layout: 'testLayout' };
|
|
462
|
+
const mockError = new Error('Failed to fetch schema');
|
|
463
|
+
|
|
464
|
+
getSchema.mockReturnValue(Promise.reject(mockError));
|
|
465
|
+
|
|
466
|
+
console.error = jest.fn();
|
|
467
|
+
|
|
468
|
+
const result = await fetchSchemaForEntity({ queryParams });
|
|
469
|
+
|
|
470
|
+
expect(getSchema).toHaveBeenCalledWith(queryParams.layout);
|
|
471
|
+
expect(result).toBeUndefined();
|
|
472
|
+
expect(console.error).toHaveBeenCalledWith(mockError);
|
|
473
|
+
});
|
|
474
|
+
});
|
|
@@ -36,6 +36,7 @@ import { MOBILE_PUSH } from '../../CreativesContainer/constants';
|
|
|
36
36
|
import { getCdnUrl } from '../../../utils/cdnTransformation';
|
|
37
37
|
import { MAPP_SDK } from './constants';
|
|
38
38
|
import { isEmbeddedEditOrPreview } from '../../../utils/commonUtils';
|
|
39
|
+
import { EMBEDDED } from '../../Whatsapp/constants';
|
|
39
40
|
|
|
40
41
|
const PrefixWrapper = styled.div`
|
|
41
42
|
margin-right: 16px;
|
|
@@ -110,27 +111,35 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
|
|
|
110
111
|
let selectedWeChatAccount = {};
|
|
111
112
|
const queryType = String(get(this.props, 'location.query.type', ''))?.toLowerCase();
|
|
112
113
|
const creativesMode = String(get(this.props, 'creativesMode', ''))?.toLowerCase();
|
|
114
|
+
const { Edit: EditProps, Templates } = this.props || {};
|
|
115
|
+
const { selectedWeChatAccount: editSelectedWeChatAccount, templateDetails } = EditProps || {};
|
|
116
|
+
const { id: selectedWeChatAccountId } = editSelectedWeChatAccount || {};
|
|
117
|
+
const { definition } = templateDetails || {};
|
|
118
|
+
const { accountId: templateAccountId } = definition || {};
|
|
119
|
+
const { Edit: nextEdit } = nextProps || {};
|
|
113
120
|
if (isEmbeddedEditOrPreview(queryType, creativesMode)) {
|
|
114
|
-
selectedWeChatAccount = !_.isEmpty(
|
|
115
|
-
?
|
|
116
|
-
:
|
|
117
|
-
} else if (!_.isEmpty(
|
|
118
|
-
selectedWeChatAccount =
|
|
121
|
+
selectedWeChatAccount = !_.isEmpty(editSelectedWeChatAccount)
|
|
122
|
+
? editSelectedWeChatAccount
|
|
123
|
+
: nextEdit?.selectedWeChatAccount;
|
|
124
|
+
} else if (!_.isEmpty(Templates?.selectedWeChatAccount)) {
|
|
125
|
+
selectedWeChatAccount = Templates?.selectedWeChatAccount;
|
|
119
126
|
}
|
|
120
127
|
|
|
121
|
-
if (
|
|
122
|
-
this.setMobilePushAccountOptions(
|
|
128
|
+
if (queryType === EMBEDDED && !nextEdit?.fetchingWeCrmAccounts && !_.isEqual(EditProps?.weCrmAccounts, nextEdit?.weCrmAccounts) && (!selectedWeChatAccount || _.isEmpty(selectedWeChatAccount))) {
|
|
129
|
+
this.setMobilePushAccountOptions(nextEdit?.weCrmAccounts, get(this.props, "templateData.definition.accountId"));
|
|
123
130
|
}
|
|
124
|
-
// Check if the
|
|
125
|
-
|
|
126
|
-
if
|
|
127
|
-
|
|
131
|
+
// Check if the current mode is either embedded edit or preview, and if the selected WeChat account ID,
|
|
132
|
+
// template account ID, and the next props' weCrmAccounts are available, and if fetchingWeCrmAccounts is false,
|
|
133
|
+
// and if the selected WeChat account ID is not equal to the template account ID.
|
|
134
|
+
// If all conditions are met, set the mobile push account options using the next props' weCrmAccounts and the template account ID.
|
|
135
|
+
if (isEmbeddedEditOrPreview(queryType, creativesMode) && nextEdit?.weCrmAccounts && templateAccountId && selectedWeChatAccountId && !_.isEqual(selectedWeChatAccountId, templateAccountId)) {
|
|
136
|
+
this.setMobilePushAccountOptions(nextEdit?.weCrmAccounts, templateAccountId);
|
|
128
137
|
}
|
|
129
|
-
if (!_.isEmpty(
|
|
138
|
+
if (!_.isEmpty(nextEdit?.selectedWeChatAccount) && !_.isEqual(editSelectedWeChatAccount, nextEdit?.selectedWeChatAccount) && (queryType === EMBEDDED) && this.props.location.query.module === "loyalty") {
|
|
130
139
|
const params = {
|
|
131
140
|
name: '',
|
|
132
141
|
sortBy: 'Most Recent',
|
|
133
|
-
accountId:
|
|
142
|
+
accountId: nextEdit?.selectedWeChatAccount?.id,
|
|
134
143
|
};
|
|
135
144
|
this.props.actions.getMobilepushTemplatesList('mobilepush', params);
|
|
136
145
|
}
|
|
@@ -159,7 +168,6 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
|
|
|
159
168
|
this.setTemplateOptions(nextProps.Edit.mobilepushTemplates);
|
|
160
169
|
}
|
|
161
170
|
}
|
|
162
|
-
|
|
163
171
|
this.handleEditSchemaOnPropsChange(nextProps, selectedWeChatAccount);
|
|
164
172
|
if (nextProps.Edit.uploadedAssetData) {
|
|
165
173
|
const formData = _.cloneDeep(this.state.formData);
|