@capillarytech/creatives-library 7.17.169-alpha.1 → 7.17.169-alpha.3
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,5 +1,5 @@
|
|
|
1
1
|
import { expectSaga } from 'redux-saga-test-plan';
|
|
2
|
-
import { take, call, takeLatest, takeEvery } from 'redux-saga/effects';
|
|
2
|
+
import { take, call, takeLatest, takeEvery, put } from 'redux-saga/effects';
|
|
3
3
|
import * as matchers from 'redux-saga-test-plan/matchers';
|
|
4
4
|
import * as api from '../../../services/api';
|
|
5
5
|
import * as types from '../constants';
|
|
@@ -10,9 +10,12 @@ import {
|
|
|
10
10
|
getAllTemplates,
|
|
11
11
|
watchGetCdnTransformationConfig,
|
|
12
12
|
watchGetAllTemplates,
|
|
13
|
+
getSenderDetails,
|
|
13
14
|
} from '../sagas';
|
|
14
15
|
|
|
15
16
|
import * as mockData from './mockData';
|
|
17
|
+
import { ZALO } from '../../CreativesContainer/constants';
|
|
18
|
+
import { VIET_GUYS } from '../../Zalo/constants';
|
|
16
19
|
|
|
17
20
|
describe('getCdnTransformationConfig saga', () => {
|
|
18
21
|
it("handle valid response from api", () => {
|
|
@@ -134,3 +137,53 @@ describe('watchForTemplates saga', () => {
|
|
|
134
137
|
);
|
|
135
138
|
});
|
|
136
139
|
});
|
|
140
|
+
|
|
141
|
+
describe('getSenderDetails Saga', () => {
|
|
142
|
+
const channel = 'someChannel';
|
|
143
|
+
const orgUnitId = 'someOrgUnitId';
|
|
144
|
+
const action = { channel, orgUnitId };
|
|
145
|
+
|
|
146
|
+
it('should handle apiResponse with hostName', () => {
|
|
147
|
+
const apiResponse = {
|
|
148
|
+
entity: {
|
|
149
|
+
[channel]: [
|
|
150
|
+
{
|
|
151
|
+
domainProperties: {
|
|
152
|
+
hostName: 'example.com',
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const generator = getSenderDetails(action);
|
|
160
|
+
expect(generator.next().value).toEqual(call(api.getSenderDetails, channel, orgUnitId));
|
|
161
|
+
expect(generator.next(apiResponse).value).toEqual(
|
|
162
|
+
put({
|
|
163
|
+
type: types.GET_SENDER_DETAILS_SUCCESS,
|
|
164
|
+
payload: 'example.com',
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should handle apiResponse without hostName', () => {
|
|
170
|
+
const apiResponse = {
|
|
171
|
+
entity: {
|
|
172
|
+
[channel]: [
|
|
173
|
+
{
|
|
174
|
+
domainProperties: {},
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const generator = getSenderDetails(action);
|
|
181
|
+
expect(generator.next().value).toEqual(call(api.getSenderDetails, channel, orgUnitId));
|
|
182
|
+
expect(generator.next(apiResponse).value).toEqual(
|
|
183
|
+
put({
|
|
184
|
+
type: types.GET_SENDER_DETAILS_SUCCESS,
|
|
185
|
+
payload: '',
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -4,7 +4,7 @@ import React, { useState, useEffect } from 'react';
|
|
|
4
4
|
import { bindActionCreators } from 'redux';
|
|
5
5
|
import { createStructuredSelector } from 'reselect';
|
|
6
6
|
import { injectIntl, FormattedMessage } from 'react-intl';
|
|
7
|
-
import { get, isEmpty } from 'lodash';
|
|
7
|
+
import { get, isEmpty, update } from 'lodash';
|
|
8
8
|
import styled from 'styled-components';
|
|
9
9
|
import CapSpin from '@capillarytech/cap-ui-library/CapSpin';
|
|
10
10
|
import CapRow from '@capillarytech/cap-ui-library/CapRow';
|
|
@@ -66,21 +66,23 @@ export const Zalo = (props) => {
|
|
|
66
66
|
injectedTags,
|
|
67
67
|
getFormData,
|
|
68
68
|
selectedOfferDetails,
|
|
69
|
+
gapItTemplateData,
|
|
69
70
|
} = props || {};
|
|
71
|
+
const {hostName = ''} = senderDetails;
|
|
70
72
|
const { formatMessage } = intl;
|
|
71
73
|
const [oa_id, setOaId] = useState('');
|
|
72
74
|
const [token, setToken] = useState('');
|
|
73
75
|
const [username, setUsername] = useState('');
|
|
74
76
|
const [templateName, setTemplateName] = useState('');
|
|
75
77
|
const [templateId, setTemplateId] = useState('');
|
|
76
|
-
const [templateListParams, setTemplateListParams] = useState([]);
|
|
78
|
+
const [templateListParams, setTemplateListParams] = useState(templateData?.versions?.base?.content?.zalo?.listParams || ((hostName === VIET_GUYS && templateData?.templateConfigs?.varMapped ? Object.entries(templateData?.templateConfigs?.varMapped) : templateData?.templateConfigs?.varMapped) ?? []) || []);
|
|
77
79
|
const [templatePreviewUrl, setTemplatePreviewUrl] = useState('');
|
|
78
80
|
const [templateStatus, setZaloTemplateStatus] = useState(
|
|
79
81
|
ZALO_STATUSES.ENABLE,
|
|
80
82
|
);
|
|
83
|
+
const [gapitAllTemplateData, setGapitAllTemplateData] = useState([]);
|
|
81
84
|
const [tags, updateTags] = useState([]);
|
|
82
85
|
const [textAreaId, updateTextAreaId] = useState('');
|
|
83
|
-
const [host, setHost] = useState('');
|
|
84
86
|
const { zaloTemplateInfoValue = {}, zaloTemplateInfoStatus = REQUEST } =
|
|
85
87
|
editData;
|
|
86
88
|
const {
|
|
@@ -114,18 +116,26 @@ export const Zalo = (props) => {
|
|
|
114
116
|
configs: { token: accessToken = '' } = {},
|
|
115
117
|
name = '',
|
|
116
118
|
} = selectedZaloAccount;
|
|
117
|
-
const {hostName = ''} = senderDetails;
|
|
118
119
|
const oaId = getDefaultTags === OUTBOUND ? zaloAccountId : accountId;
|
|
119
120
|
setOaId(sourceAccountIdentifier || oaId);
|
|
120
121
|
setToken(accessToken || zaloToken);
|
|
121
122
|
setUsername(name || accountName);
|
|
122
|
-
setHost(hostName);
|
|
123
123
|
}
|
|
124
|
-
|
|
124
|
+
setGapitAllTemplateData(gapItTemplateData);
|
|
125
|
+
}, [selectedZaloAccount, templateData, gapItTemplateData]);
|
|
126
|
+
|
|
127
|
+
const updateTemplateData = (gapitTemplateId, templateName, listParams, previewUrl, status) => {
|
|
128
|
+
setTemplateName(templateName);
|
|
129
|
+
setTemplateId(gapitTemplateId);
|
|
130
|
+
setTemplateListParams(listParams);
|
|
131
|
+
setTemplatePreviewUrl(previewUrl);
|
|
132
|
+
setZaloTemplateStatus(status);
|
|
133
|
+
updateTextAreaId(listParams[0]?.name);
|
|
134
|
+
};
|
|
125
135
|
|
|
126
136
|
//gets template details
|
|
127
137
|
useEffect(() => {
|
|
128
|
-
if (zaloTempId && oa_id && token && username &&
|
|
138
|
+
if (zaloTempId && oa_id && token && username && hostName === VIET_GUYS) {
|
|
129
139
|
actions.getTemplateInfoById({
|
|
130
140
|
username,
|
|
131
141
|
oa_id,
|
|
@@ -133,26 +143,26 @@ export const Zalo = (props) => {
|
|
|
133
143
|
id: zaloTempId,
|
|
134
144
|
actionCallback,
|
|
135
145
|
});
|
|
136
|
-
} else {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
} else if (hostName !== VIET_GUYS) {
|
|
147
|
+
const { _id: gapitTemplateId = '' } = templateData;
|
|
148
|
+
if (gapitTemplateId) {
|
|
149
|
+
const data = gapitAllTemplateData.find(template => template._id == gapitTemplateId);
|
|
150
|
+
const { templateName = "", listParams = [], previewUrl = "", status = "" } = data?.versions?.base?.content?.zalo || {};
|
|
151
|
+
updateTemplateData(gapitTemplateId, templateName, listParams, previewUrl, status);
|
|
152
|
+
} else {
|
|
153
|
+
const { id: gapitTemplateId = '', name: templateName = '', template: previewUrl = '', varMapped: listParams = {} } = templateData?.templateConfigs || {};
|
|
154
|
+
const handledListParams = handleSetValues(Object.entries(listParams));
|
|
155
|
+
updateTemplateData(gapitTemplateId, templateName, handledListParams, previewUrl, ZALO_STATUSES.ENABLE);
|
|
156
|
+
}
|
|
147
157
|
}
|
|
148
158
|
//cleanup code
|
|
149
159
|
return () => {
|
|
150
160
|
actions.resetTemplateInfoData();
|
|
151
161
|
};
|
|
152
|
-
}, [zaloTempId, oa_id, token, username
|
|
162
|
+
}, [zaloTempId, oa_id, token, username]);
|
|
153
163
|
|
|
154
164
|
const handleSetValues = (paramsData = []) =>
|
|
155
|
-
paramsData
|
|
165
|
+
paramsData?.map((paramData) => {
|
|
156
166
|
for (const key in varMapped) {
|
|
157
167
|
if (paramData?.name === key) {
|
|
158
168
|
paramData.value = varMapped[key];
|
|
@@ -162,7 +172,7 @@ export const Zalo = (props) => {
|
|
|
162
172
|
});
|
|
163
173
|
|
|
164
174
|
const setDataForEdit = (setValues) => {
|
|
165
|
-
if(
|
|
175
|
+
if(senderDetails?.hostName === VIET_GUYS) {
|
|
166
176
|
const {
|
|
167
177
|
name = '',
|
|
168
178
|
_id: zaloId = '',
|
|
@@ -178,22 +188,19 @@ export const Zalo = (props) => {
|
|
|
178
188
|
} = {},
|
|
179
189
|
} = {},
|
|
180
190
|
} = zaloTemplateInfoValue;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
setTemplateListParams(setValues ? handleSetValues(paramsData) : paramsData);
|
|
184
|
-
setTemplatePreviewUrl(previewUrl);
|
|
185
|
-
setZaloTemplateStatus(status);
|
|
186
|
-
updateTextAreaId(paramsData[0]?.name);
|
|
191
|
+
const handledListParams = setValues ? handleSetValues(paramsData) : paramsData;
|
|
192
|
+
updateTemplateData(zaloId, name, handledListParams, previewUrl, status);
|
|
187
193
|
} else {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
if (setValues) {
|
|
195
|
+
const { id: gapitTemplateId = '', name: templateName = '', template: previewUrl = '', varMapped: listParams = {} } = templateData?.templateConfigs || {};
|
|
196
|
+
const handledListParams = handleSetValues(listParams);
|
|
197
|
+
updateTemplateData(gapitTemplateId, templateName, handledListParams, previewUrl, ZALO_STATUSES.ENABLE);
|
|
198
|
+
} else {
|
|
199
|
+
const { _id: gapitTemplateId = '' } = templateData;
|
|
200
|
+
let data = gapitAllTemplateData.find(template => template._id == gapitTemplateId);
|
|
201
|
+
const { templateName = "", listParams = [], previewUrl = "", status = "" } = data?.versions?.base?.content?.zalo || {};
|
|
202
|
+
updateTemplateData(gapitTemplateId, templateName, listParams, previewUrl, status);
|
|
203
|
+
}
|
|
197
204
|
}
|
|
198
205
|
};
|
|
199
206
|
|
|
@@ -366,7 +373,7 @@ export const Zalo = (props) => {
|
|
|
366
373
|
|
|
367
374
|
const isEditDoneDisabled = () => {
|
|
368
375
|
let disableCheck = false;
|
|
369
|
-
templateListParams
|
|
376
|
+
templateListParams?.forEach((listParams) => {
|
|
370
377
|
const { error, value } = listParams;
|
|
371
378
|
const errorMessage = !error
|
|
372
379
|
? handleErrorValidation(value, listParams)
|
|
@@ -378,11 +385,16 @@ export const Zalo = (props) => {
|
|
|
378
385
|
return disableCheck;
|
|
379
386
|
};
|
|
380
387
|
const createPayload = () => {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
388
|
+
let varMap = {};
|
|
389
|
+
if (hostName !== VIET_GUYS) {
|
|
390
|
+
varMap = templateListParams;
|
|
391
|
+
} else {
|
|
392
|
+
templateListParams?.forEach((listParam) => {
|
|
393
|
+
const { name, value } = listParam;
|
|
394
|
+
varMap[name] = value;
|
|
395
|
+
}
|
|
396
|
+
);
|
|
397
|
+
}
|
|
386
398
|
const payload = {
|
|
387
399
|
channel: ZALO,
|
|
388
400
|
accountId: oa_id,
|
|
@@ -397,7 +409,7 @@ export const Zalo = (props) => {
|
|
|
397
409
|
varMapped: varMap,
|
|
398
410
|
},
|
|
399
411
|
token,
|
|
400
|
-
host,
|
|
412
|
+
host: hostName,
|
|
401
413
|
};
|
|
402
414
|
return payload;
|
|
403
415
|
};
|
|
@@ -435,7 +447,7 @@ export const Zalo = (props) => {
|
|
|
435
447
|
});
|
|
436
448
|
|
|
437
449
|
return (
|
|
438
|
-
<CapSpin spinning={zaloTemplateInfoStatus === REQUEST &&
|
|
450
|
+
<CapSpin spinning={zaloTemplateInfoStatus === REQUEST && hostName === VIET_GUYS}>
|
|
439
451
|
<CapRow type="flex" className="cap-zalo-creatives">
|
|
440
452
|
<CapColumn span={14}>
|
|
441
453
|
{templateStatus && (
|
|
@@ -11462,6 +11462,9 @@ export const accountData = {
|
|
|
11462
11462
|
modifiedDate: '2023-10-16T00:00:00+05:30',
|
|
11463
11463
|
},
|
|
11464
11464
|
},
|
|
11465
|
+
senderDetails: {
|
|
11466
|
+
hostName: 'vietguyszalotrans',
|
|
11467
|
+
},
|
|
11465
11468
|
};
|
|
11466
11469
|
|
|
11467
11470
|
export const templateData = {
|
|
@@ -11479,3 +11482,46 @@ export const templateConfigs = {
|
|
|
11479
11482
|
ma_so1: '4',
|
|
11480
11483
|
},
|
|
11481
11484
|
};
|
|
11485
|
+
|
|
11486
|
+
export const mockGapItTemplateData = [
|
|
11487
|
+
{
|
|
11488
|
+
_id: '354701',
|
|
11489
|
+
versions: {
|
|
11490
|
+
base: {
|
|
11491
|
+
content: {
|
|
11492
|
+
zalo: {
|
|
11493
|
+
templateName: 'Test',
|
|
11494
|
+
listParams: [
|
|
11495
|
+
{
|
|
11496
|
+
name: "Name",
|
|
11497
|
+
type: "STRING",
|
|
11498
|
+
require: true,
|
|
11499
|
+
maxLength: 80,
|
|
11500
|
+
minLength: 0,
|
|
11501
|
+
acceptNull: false,
|
|
11502
|
+
},
|
|
11503
|
+
{
|
|
11504
|
+
name: "So_dien_thoai",
|
|
11505
|
+
type: "STRING",
|
|
11506
|
+
require: true,
|
|
11507
|
+
maxLength: 30,
|
|
11508
|
+
minLength: 0,
|
|
11509
|
+
acceptNull: false,
|
|
11510
|
+
},
|
|
11511
|
+
{
|
|
11512
|
+
name: "so_du",
|
|
11513
|
+
type: "STRING",
|
|
11514
|
+
require: true,
|
|
11515
|
+
maxLength: 30,
|
|
11516
|
+
minLength: 0,
|
|
11517
|
+
acceptNull: false,
|
|
11518
|
+
},
|
|
11519
|
+
],
|
|
11520
|
+
previewUrl: 'https://account.zalo.cloud/znspreview/h84m64E6ST_owPQVFzTilg==',
|
|
11521
|
+
status: 'ENABLE',
|
|
11522
|
+
},
|
|
11523
|
+
},
|
|
11524
|
+
},
|
|
11525
|
+
},
|
|
11526
|
+
},
|
|
11527
|
+
];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fromJS } from "immutable";
|
|
2
|
-
import { makeSelectZalo, makeSelectAccount } from "../selectors";
|
|
2
|
+
import { makeSelectZalo, makeSelectAccount, makeSelectGapitTemplates } from "../selectors";
|
|
3
3
|
|
|
4
4
|
describe("makeSelectZalo", () => {
|
|
5
5
|
it("returns the expected object with default values when substate is empty", () => {
|
|
@@ -25,4 +25,27 @@ describe("makeSelectZalo", () => {
|
|
|
25
25
|
// Assert
|
|
26
26
|
expect(result).toEqual(expected);
|
|
27
27
|
});
|
|
28
|
-
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('makeSelectGapitTemplates', () => {
|
|
31
|
+
it('should return an empty array if templates are not present', () => {
|
|
32
|
+
const state = fromJS({ templates: {} });
|
|
33
|
+
const selector = makeSelectGapitTemplates();
|
|
34
|
+
const result = selector(state);
|
|
35
|
+
expect(result).toEqual([]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should return an array of templates if present', () => {
|
|
39
|
+
const state = fromJS({ templates: { templates: ['template1', 'template2'] } });
|
|
40
|
+
const selector = makeSelectGapitTemplates();
|
|
41
|
+
const result = selector(state);
|
|
42
|
+
expect(result).toEqual(['template1', 'template2']);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should return an empty array if templates is null', () => {
|
|
46
|
+
const state = fromJS({ templates: {} });
|
|
47
|
+
const selector = makeSelectGapitTemplates();
|
|
48
|
+
const result = selector(state);
|
|
49
|
+
expect(result).toEqual([]);
|
|
50
|
+
});
|
|
51
|
+
});
|