@capillarytech/creatives-library 7.17.169-alpha.0 → 7.17.169-alpha.2

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.169-alpha.0",
4
+ "version": "7.17.169-alpha.2",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -41,6 +41,7 @@ import { WHATSAPP_STATUSES, WHATSAPP_MEDIA_TYPES } from '../Whatsapp/constants';
41
41
 
42
42
  import { updateImagesInHtml } from '../../utils/cdnTransformation';
43
43
  import { IOS } from '../InApp/constants';
44
+ import { VIET_GUYS } from '../Zalo/constants';
44
45
 
45
46
  const classPrefix = 'add-creatives-section';
46
47
  const CREATIVES_CONTAINER = 'creativesContainer';
@@ -124,14 +125,19 @@ export class Creatives extends React.Component {
124
125
  sourceAccountIdentifier = "",
125
126
  configs: { token = "" } = {},
126
127
  } = get(this.props, "Templates.selectedZaloAccount", {});
127
- this.props.zaloActions.getTemplateInfoById({
128
- username: name,
129
- oa_id: sourceAccountIdentifier,
130
- token,
131
- id: template?._id,
132
- preview: true,
133
- actionCallback: this.actionCallback,
134
- });
128
+ const { hostName = ''} = this.props.Templates.senderDetails || {};
129
+ if (hostName === VIET_GUYS) {
130
+ this.props.zaloActions.getTemplateInfoById({
131
+ username: name,
132
+ oa_id: sourceAccountIdentifier,
133
+ token,
134
+ id: template?._id,
135
+ preview: true,
136
+ actionCallback: this.actionCallback,
137
+ });
138
+ } else {
139
+ window.open(template?.versions?.base?.content?.zalo?.previewUrl, '_blank');
140
+ }
135
141
  }
136
142
  };
137
143
  onEditTemplate = () => {
@@ -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
+ });
@@ -80,7 +80,6 @@ export const Zalo = (props) => {
80
80
  );
81
81
  const [tags, updateTags] = useState([]);
82
82
  const [textAreaId, updateTextAreaId] = useState('');
83
- const [host, setHost] = useState('');
84
83
  const { zaloTemplateInfoValue = {}, zaloTemplateInfoStatus = REQUEST } =
85
84
  editData;
86
85
  const {
@@ -119,13 +118,12 @@ export const Zalo = (props) => {
119
118
  setOaId(sourceAccountIdentifier || oaId);
120
119
  setToken(accessToken || zaloToken);
121
120
  setUsername(name || accountName);
122
- setHost(hostName);
123
121
  }
124
122
  }, [selectedZaloAccount, templateData]);
125
123
 
126
124
  //gets template details
127
125
  useEffect(() => {
128
- if (zaloTempId && oa_id && token && username && host === VIET_GUYS) {
126
+ if (zaloTempId && oa_id && token && username && senderDetails?.hostName === VIET_GUYS) {
129
127
  actions.getTemplateInfoById({
130
128
  username,
131
129
  oa_id,
@@ -134,22 +132,31 @@ export const Zalo = (props) => {
134
132
  actionCallback,
135
133
  });
136
134
  } else {
137
- makeSelectGapitTemplates();
138
- const {_id : gapitTemplateId = ''} = templateData;
139
- const data = props.gapItTemplateData.find(template => template._id == gapitTemplateId);
140
- const { templateName = "", listParams = [], previewUrl = "", status = ""} = data?.versions?.base?.content?.zalo || {};
141
- setTemplateName(templateName);
142
- setTemplateId(gapitTemplateId);
143
- setTemplateListParams(listParams);
144
- setTemplatePreviewUrl(previewUrl);
145
- setZaloTemplateStatus(status);
146
- updateTextAreaId(listParams[0]?.name);
135
+ const { _id: gapitTemplateId = '' } = templateData;
136
+ if (gapitTemplateId && senderDetails?.hostName !== VIET_GUYS) {
137
+ const data = props.gapItTemplateData.find(template => template._id == gapitTemplateId);
138
+ const { templateName = "", listParams = [], previewUrl = "", status = "" } = data?.versions?.base?.content?.zalo || {};
139
+ setTemplateName(templateName);
140
+ setTemplateId(gapitTemplateId);
141
+ setTemplateListParams(listParams);
142
+ setTemplatePreviewUrl(previewUrl);
143
+ setZaloTemplateStatus(status);
144
+ updateTextAreaId(listParams[0]?.name);
145
+ } else {
146
+ const { id: gapitTemplateId = '', name: templateName = '', template: previewUrl = '', varMapped: listParams = {} } = templateData?.templateConfigs || {};
147
+ setTemplateName(templateName);
148
+ setTemplateId(gapitTemplateId);
149
+ setTemplateListParams(handleSetValues(Object.entries(listParams)));
150
+ setTemplatePreviewUrl(previewUrl);
151
+ setZaloTemplateStatus(ZALO_STATUSES.ENABLE);
152
+ updateTextAreaId(listParams[0]?.name);
153
+ }
147
154
  }
148
155
  //cleanup code
149
156
  return () => {
150
157
  actions.resetTemplateInfoData();
151
158
  };
152
- }, [zaloTempId, oa_id, token, username, host]);
159
+ }, [zaloTempId, oa_id, token, username]);
153
160
 
154
161
  const handleSetValues = (paramsData = []) =>
155
162
  paramsData.map((paramData) => {
@@ -162,7 +169,7 @@ export const Zalo = (props) => {
162
169
  });
163
170
 
164
171
  const setDataForEdit = (setValues) => {
165
- if(host === VIET_GUYS) {
172
+ if(senderDetails?.hostName === VIET_GUYS) {
166
173
  const {
167
174
  name = '',
168
175
  _id: zaloId = '',
@@ -185,15 +192,25 @@ export const Zalo = (props) => {
185
192
  setZaloTemplateStatus(status);
186
193
  updateTextAreaId(paramsData[0]?.name);
187
194
  } else {
188
- const {_id : gapitTemplateId = ''} = templateData;
189
- const data = props.gapItTemplateData.find(template => template._id == gapitTemplateId);
190
- const { templateName = "", listParams = [], previewUrl = "", status = ""} = data?.versions?.base?.content?.zalo || {};
191
- setTemplateName(templateName);
192
- setTemplateId(gapitTemplateId);
193
- setTemplateListParams(listParams);
194
- setTemplatePreviewUrl(previewUrl);
195
- setZaloTemplateStatus(status);
196
- updateTextAreaId(listParams[0]?.name);
195
+ if (setValues) {
196
+ const { id: gapitTemplateId = '', name: templateName = '', template: previewUrl = '', varMapped: listParams = {} } = templateData?.templateConfigs || {};
197
+ setTemplateName(templateName);
198
+ setTemplateId(gapitTemplateId);
199
+ setTemplateListParams(handleSetValues(Object.entries(listParams)));
200
+ setTemplatePreviewUrl(previewUrl);
201
+ setZaloTemplateStatus(ZALO_STATUSES.ENABLE);
202
+ updateTextAreaId(listParams[0]?.name);
203
+ } else {
204
+ const { _id: gapitTemplateId = '' } = templateData;
205
+ let data = props.gapItTemplateData.find(template => template._id == gapitTemplateId);
206
+ const { templateName = "", listParams = [], previewUrl = "", status = "" } = data?.versions?.base?.content?.zalo || {};
207
+ setTemplateName(templateName);
208
+ setTemplateId(gapitTemplateId);
209
+ setTemplateListParams(listParams);
210
+ setTemplatePreviewUrl(previewUrl);
211
+ setZaloTemplateStatus(status);
212
+ updateTextAreaId(listParams[0]?.name);
213
+ }
197
214
  }
198
215
  };
199
216
 
@@ -397,7 +414,7 @@ export const Zalo = (props) => {
397
414
  varMapped: varMap,
398
415
  },
399
416
  token,
400
- host,
417
+ host: senderDetails?.hostName,
401
418
  };
402
419
  return payload;
403
420
  };
@@ -435,7 +452,7 @@ export const Zalo = (props) => {
435
452
  });
436
453
 
437
454
  return (
438
- <CapSpin spinning={zaloTemplateInfoStatus === REQUEST && host === VIET_GUYS}>
455
+ <CapSpin spinning={zaloTemplateInfoStatus === REQUEST && senderDetails?.hostName === VIET_GUYS}>
439
456
  <CapRow type="flex" className="cap-zalo-creatives">
440
457
  <CapColumn span={14}>
441
458
  {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
+ });