@capillarytech/creatives-library 7.17.169-alpha.2 → 7.17.169-alpha.4
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
|
@@ -125,7 +125,7 @@ export class Creatives extends React.Component {
|
|
|
125
125
|
sourceAccountIdentifier = "",
|
|
126
126
|
configs: { token = "" } = {},
|
|
127
127
|
} = get(this.props, "Templates.selectedZaloAccount", {});
|
|
128
|
-
const { hostName = ''} = this.props
|
|
128
|
+
const { hostName = ''} = get(this.props, "Templates.senderDetails", {});
|
|
129
129
|
if (hostName === VIET_GUYS) {
|
|
130
130
|
this.props.zaloActions.getTemplateInfoById({
|
|
131
131
|
username: name,
|
|
@@ -136,7 +136,7 @@ export class Creatives extends React.Component {
|
|
|
136
136
|
actionCallback: this.actionCallback,
|
|
137
137
|
});
|
|
138
138
|
} else {
|
|
139
|
-
window.open(template
|
|
139
|
+
window.open(get(template, 'versions.base.content.zalo.previewUrl'), '_blank');
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
};
|
|
@@ -2119,7 +2119,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
|
|
|
2119
2119
|
id: template?._id,
|
|
2120
2120
|
preview: true,
|
|
2121
2121
|
actionCallback: this.actionCallback,
|
|
2122
|
-
}) : window.open(template
|
|
2122
|
+
}) : window.open(get(template, 'versions.base.content.zalo.previewUrl'), '_blank');
|
|
2123
2123
|
}
|
|
2124
2124
|
}
|
|
2125
2125
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import get from 'lodash/get';
|
|
1
2
|
import { call, put, takeLatest, take, cancel, select } from 'redux-saga/effects';
|
|
2
3
|
import { LOCATION_CHANGE } from 'react-router-redux';
|
|
3
4
|
// import { schema, normalize } from 'normalizr';
|
|
@@ -176,7 +177,7 @@ export function* getSenderDetails({
|
|
|
176
177
|
if (!apiResponse?.errors?.length) {
|
|
177
178
|
yield put({
|
|
178
179
|
type: types.GET_SENDER_DETAILS_SUCCESS,
|
|
179
|
-
payload: apiResponse
|
|
180
|
+
payload: get(apiResponse, `entity.${channel}[0].domainProperties.hostName`, ''),
|
|
180
181
|
});
|
|
181
182
|
} else {
|
|
182
183
|
yield put({
|
|
@@ -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,18 +66,30 @@ 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
|
-
|
|
78
|
+
// Initialize the state for templateListParams based on the nested properties of templateData.
|
|
79
|
+
// If templateData.versions.base.content.zalo.listParams is available, use it.
|
|
80
|
+
// Otherwise, if hostName is VIET_GUYS and templateData.templateConfigs.varMapped is available,
|
|
81
|
+
// convert it to an array of entries. If not, use templateData.templateConfigs.varMapped or an empty array.
|
|
82
|
+
const [templateListParams, setTemplateListParams] = useState(
|
|
83
|
+
(templateData?.versions?.base?.content?.zalo?.listParams ||
|
|
84
|
+
((hostName === VIET_GUYS && templateData?.templateConfigs?.varMapped)
|
|
85
|
+
? Object.entries(templateData?.templateConfigs?.varMapped)
|
|
86
|
+
: templateData?.templateConfigs?.varMapped)) ?? []
|
|
87
|
+
);
|
|
77
88
|
const [templatePreviewUrl, setTemplatePreviewUrl] = useState('');
|
|
78
89
|
const [templateStatus, setZaloTemplateStatus] = useState(
|
|
79
90
|
ZALO_STATUSES.ENABLE,
|
|
80
91
|
);
|
|
92
|
+
const [gapitAllTemplateData, setGapitAllTemplateData] = useState([]);
|
|
81
93
|
const [tags, updateTags] = useState([]);
|
|
82
94
|
const [textAreaId, updateTextAreaId] = useState('');
|
|
83
95
|
const { zaloTemplateInfoValue = {}, zaloTemplateInfoStatus = REQUEST } =
|
|
@@ -113,17 +125,26 @@ export const Zalo = (props) => {
|
|
|
113
125
|
configs: { token: accessToken = '' } = {},
|
|
114
126
|
name = '',
|
|
115
127
|
} = selectedZaloAccount;
|
|
116
|
-
const {hostName = ''} = senderDetails;
|
|
117
128
|
const oaId = getDefaultTags === OUTBOUND ? zaloAccountId : accountId;
|
|
118
129
|
setOaId(sourceAccountIdentifier || oaId);
|
|
119
130
|
setToken(accessToken || zaloToken);
|
|
120
131
|
setUsername(name || accountName);
|
|
121
132
|
}
|
|
122
|
-
|
|
133
|
+
setGapitAllTemplateData(gapItTemplateData);
|
|
134
|
+
}, [selectedZaloAccount, templateData, gapItTemplateData]);
|
|
135
|
+
|
|
136
|
+
const updateTemplateData = (gapitTemplateId, templateName, listParams, previewUrl, status) => {
|
|
137
|
+
setTemplateName(templateName);
|
|
138
|
+
setTemplateId(gapitTemplateId);
|
|
139
|
+
setTemplateListParams(listParams);
|
|
140
|
+
setTemplatePreviewUrl(previewUrl);
|
|
141
|
+
setZaloTemplateStatus(status);
|
|
142
|
+
updateTextAreaId(listParams[0]?.name);
|
|
143
|
+
};
|
|
123
144
|
|
|
124
145
|
//gets template details
|
|
125
146
|
useEffect(() => {
|
|
126
|
-
if (zaloTempId && oa_id && token && username &&
|
|
147
|
+
if (zaloTempId && oa_id && token && username && hostName === VIET_GUYS) {
|
|
127
148
|
actions.getTemplateInfoById({
|
|
128
149
|
username,
|
|
129
150
|
oa_id,
|
|
@@ -131,25 +152,16 @@ export const Zalo = (props) => {
|
|
|
131
152
|
id: zaloTempId,
|
|
132
153
|
actionCallback,
|
|
133
154
|
});
|
|
134
|
-
} else {
|
|
155
|
+
} else if (hostName !== VIET_GUYS) {
|
|
135
156
|
const { _id: gapitTemplateId = '' } = templateData;
|
|
136
|
-
if (gapitTemplateId
|
|
137
|
-
const data =
|
|
157
|
+
if (gapitTemplateId) {
|
|
158
|
+
const data = gapitAllTemplateData.find(template => template._id == gapitTemplateId);
|
|
138
159
|
const { templateName = "", listParams = [], previewUrl = "", status = "" } = data?.versions?.base?.content?.zalo || {};
|
|
139
|
-
|
|
140
|
-
setTemplateId(gapitTemplateId);
|
|
141
|
-
setTemplateListParams(listParams);
|
|
142
|
-
setTemplatePreviewUrl(previewUrl);
|
|
143
|
-
setZaloTemplateStatus(status);
|
|
144
|
-
updateTextAreaId(listParams[0]?.name);
|
|
160
|
+
updateTemplateData(gapitTemplateId, templateName, listParams, previewUrl, status);
|
|
145
161
|
} else {
|
|
146
162
|
const { id: gapitTemplateId = '', name: templateName = '', template: previewUrl = '', varMapped: listParams = {} } = templateData?.templateConfigs || {};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
setTemplateListParams(handleSetValues(Object.entries(listParams)));
|
|
150
|
-
setTemplatePreviewUrl(previewUrl);
|
|
151
|
-
setZaloTemplateStatus(ZALO_STATUSES.ENABLE);
|
|
152
|
-
updateTextAreaId(listParams[0]?.name);
|
|
163
|
+
const handledListParams = handleSetValues(Object.entries(listParams));
|
|
164
|
+
updateTemplateData(gapitTemplateId, templateName, handledListParams, previewUrl, ZALO_STATUSES.ENABLE);
|
|
153
165
|
}
|
|
154
166
|
}
|
|
155
167
|
//cleanup code
|
|
@@ -159,7 +171,7 @@ export const Zalo = (props) => {
|
|
|
159
171
|
}, [zaloTempId, oa_id, token, username]);
|
|
160
172
|
|
|
161
173
|
const handleSetValues = (paramsData = []) =>
|
|
162
|
-
paramsData
|
|
174
|
+
paramsData?.map((paramData) => {
|
|
163
175
|
for (const key in varMapped) {
|
|
164
176
|
if (paramData?.name === key) {
|
|
165
177
|
paramData.value = varMapped[key];
|
|
@@ -169,7 +181,7 @@ export const Zalo = (props) => {
|
|
|
169
181
|
});
|
|
170
182
|
|
|
171
183
|
const setDataForEdit = (setValues) => {
|
|
172
|
-
if(
|
|
184
|
+
if(hostName === VIET_GUYS) {
|
|
173
185
|
const {
|
|
174
186
|
name = '',
|
|
175
187
|
_id: zaloId = '',
|
|
@@ -185,31 +197,18 @@ export const Zalo = (props) => {
|
|
|
185
197
|
} = {},
|
|
186
198
|
} = {},
|
|
187
199
|
} = zaloTemplateInfoValue;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
setTemplateListParams(setValues ? handleSetValues(paramsData) : paramsData);
|
|
191
|
-
setTemplatePreviewUrl(previewUrl);
|
|
192
|
-
setZaloTemplateStatus(status);
|
|
193
|
-
updateTextAreaId(paramsData[0]?.name);
|
|
200
|
+
const handledListParams = setValues ? handleSetValues(paramsData) : paramsData;
|
|
201
|
+
updateTemplateData(zaloId, name, handledListParams, previewUrl, status);
|
|
194
202
|
} else {
|
|
195
203
|
if (setValues) {
|
|
196
204
|
const { id: gapitTemplateId = '', name: templateName = '', template: previewUrl = '', varMapped: listParams = {} } = templateData?.templateConfigs || {};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
setTemplateListParams(handleSetValues(Object.entries(listParams)));
|
|
200
|
-
setTemplatePreviewUrl(previewUrl);
|
|
201
|
-
setZaloTemplateStatus(ZALO_STATUSES.ENABLE);
|
|
202
|
-
updateTextAreaId(listParams[0]?.name);
|
|
205
|
+
const handledListParams = handleSetValues(listParams);
|
|
206
|
+
updateTemplateData(gapitTemplateId, templateName, handledListParams, previewUrl, ZALO_STATUSES.ENABLE);
|
|
203
207
|
} else {
|
|
204
208
|
const { _id: gapitTemplateId = '' } = templateData;
|
|
205
|
-
let data =
|
|
209
|
+
let data = gapitAllTemplateData?.find(template => template?._id == gapitTemplateId);
|
|
206
210
|
const { templateName = "", listParams = [], previewUrl = "", status = "" } = data?.versions?.base?.content?.zalo || {};
|
|
207
|
-
|
|
208
|
-
setTemplateId(gapitTemplateId);
|
|
209
|
-
setTemplateListParams(listParams);
|
|
210
|
-
setTemplatePreviewUrl(previewUrl);
|
|
211
|
-
setZaloTemplateStatus(status);
|
|
212
|
-
updateTextAreaId(listParams[0]?.name);
|
|
211
|
+
updateTemplateData(gapitTemplateId, templateName, listParams, previewUrl, status);
|
|
213
212
|
}
|
|
214
213
|
}
|
|
215
214
|
};
|
|
@@ -383,7 +382,7 @@ export const Zalo = (props) => {
|
|
|
383
382
|
|
|
384
383
|
const isEditDoneDisabled = () => {
|
|
385
384
|
let disableCheck = false;
|
|
386
|
-
templateListParams
|
|
385
|
+
templateListParams?.forEach((listParams) => {
|
|
387
386
|
const { error, value } = listParams;
|
|
388
387
|
const errorMessage = !error
|
|
389
388
|
? handleErrorValidation(value, listParams)
|
|
@@ -395,11 +394,16 @@ export const Zalo = (props) => {
|
|
|
395
394
|
return disableCheck;
|
|
396
395
|
};
|
|
397
396
|
const createPayload = () => {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
397
|
+
let varMap = {};
|
|
398
|
+
if (hostName !== VIET_GUYS) {
|
|
399
|
+
varMap = templateListParams;
|
|
400
|
+
} else {
|
|
401
|
+
templateListParams?.forEach((listParam) => {
|
|
402
|
+
const { name = '', value = '' } = listParam;
|
|
403
|
+
varMap[name] = value;
|
|
404
|
+
}
|
|
405
|
+
);
|
|
406
|
+
}
|
|
403
407
|
const payload = {
|
|
404
408
|
channel: ZALO,
|
|
405
409
|
accountId: oa_id,
|
|
@@ -414,7 +418,7 @@ export const Zalo = (props) => {
|
|
|
414
418
|
varMapped: varMap,
|
|
415
419
|
},
|
|
416
420
|
token,
|
|
417
|
-
host:
|
|
421
|
+
host: hostName,
|
|
418
422
|
};
|
|
419
423
|
return payload;
|
|
420
424
|
};
|
|
@@ -452,7 +456,7 @@ export const Zalo = (props) => {
|
|
|
452
456
|
});
|
|
453
457
|
|
|
454
458
|
return (
|
|
455
|
-
<CapSpin spinning={zaloTemplateInfoStatus === REQUEST &&
|
|
459
|
+
<CapSpin spinning={zaloTemplateInfoStatus === REQUEST && hostName === VIET_GUYS}>
|
|
456
460
|
<CapRow type="flex" className="cap-zalo-creatives">
|
|
457
461
|
<CapColumn span={14}>
|
|
458
462
|
{templateStatus && (
|