@capillarytech/creatives-library 7.17.170 → 7.17.171-alpha.0

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.170",
4
+ "version": "7.17.171-alpha.0",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
package/services/api.js CHANGED
@@ -525,8 +525,8 @@ export const getS3UrlFileSizes = (data) => {
525
525
  return request(url, getAPICallObject('POST', data));
526
526
  };
527
527
 
528
- export const getTemplateInfoById = ({id, username, oa_id, token}) => {
529
- const url = `${API_ENDPOINT}/templates/v1/${id}/Zalo?username=${username}&oa_id=${oa_id}&token=${token}`;
528
+ export const getTemplateInfoById = ({id, username, oa_id, token, host}) => {
529
+ const url = `${API_ENDPOINT}/templates/v1/${id}/Zalo?username=${username}&oa_id=${oa_id}&token=${token}&host=${host}`;
530
530
  const compressedTemplatesData = request(url, getAPICallObject('GET'));
531
531
  return compressedTemplatesData.then((data) => {
532
532
  const { response = '' } = data || {};
@@ -41,7 +41,6 @@ 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';
45
44
 
46
45
  const classPrefix = 'add-creatives-section';
47
46
  const CREATIVES_CONTAINER = 'creativesContainer';
@@ -126,18 +125,15 @@ export class Creatives extends React.Component {
126
125
  configs: { token = "" } = {},
127
126
  } = get(this.props, "Templates.selectedZaloAccount", {});
128
127
  const { hostName = ''} = get(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(get(template, 'versions.base.content.zalo.previewUrl'), '_blank');
140
- }
128
+ this.props.zaloActions.getTemplateInfoById({
129
+ username: name,
130
+ oa_id: sourceAccountIdentifier,
131
+ token,
132
+ host: hostName,
133
+ id: template?._id,
134
+ preview: true,
135
+ actionCallback: this.actionCallback,
136
+ });
141
137
  }
142
138
  };
143
139
  onEditTemplate = () => {
@@ -110,7 +110,7 @@ import {
110
110
  HOST_GUPSHUP,
111
111
  } from '../Whatsapp/constants';
112
112
  import { INAPP_LAYOUT_DETAILS } from '../InApp/constants';
113
- import { VIET_GUYS, ZALO_STATUS_OPTIONS, ZALO_STATUSES } from '../Zalo/constants';
113
+ import { ZALO_STATUS_OPTIONS, ZALO_STATUSES } from '../Zalo/constants';
114
114
  import { getWhatsappContent, getWhatsappStatus, getWhatsappCategory, getWhatsappCta, getWhatsappQuickReply, getWhatsappAutoFill } from '../Whatsapp/utils';
115
115
  import { getRCSContent } from '../Rcs/utils';
116
116
  import zaloMessages from '../Zalo/messages';
@@ -706,7 +706,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
706
706
  params.oa_id = sourceAccountIdentifier;
707
707
  params.token = token;
708
708
  params.isAccountSelection = true;
709
- params.host = hostName;
709
+ params.host = hostName || this.state.hostName;
710
710
  }
711
711
  }
712
712
 
@@ -806,6 +806,8 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
806
806
  if(this.state.channel.toLowerCase() !== ZALO_LOWERCASE) {
807
807
  queryParams.name = this.state.searchText;
808
808
  queryParams.sortBy = this.state.sortBy;
809
+ } else {
810
+ queryParams.host = this.props.Templates?.senderDetails?.hostName;
809
811
  }
810
812
  queryParams.page = this.state.page;
811
813
  queryParams.perPage = this.state.perPageLimit;
@@ -865,11 +867,12 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
865
867
  queryParams.username = name;
866
868
  queryParams.oa_id = sourceAccountIdentifier;
867
869
  queryParams.token = token;
868
- queryParams.host = hostName;
870
+ queryParams.host = hostName || this.state.hostName;
869
871
  }
870
872
  this.setState({ page, templatesCount }, () => {
871
873
  queryParams.page = page;
872
874
  queryParams.perPage = this.state.perPageLimit;
875
+ queryParams.host = this.state.hostName;
873
876
  const channel = this.state.channel;
874
877
  this.props.actions.getAllTemplates(channel, queryParams, `${copyOf}`);
875
878
  });
@@ -2112,14 +2115,15 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
2112
2115
  sourceAccountIdentifier = "",
2113
2116
  configs: { token = "" } = {},
2114
2117
  } = get(this.props, "Templates.selectedZaloAccount", {});
2115
- this.state.hostName === VIET_GUYS ? this.props.zaloActions.getTemplateInfoById({
2118
+ this.props.zaloActions.getTemplateInfoById({
2116
2119
  username: name,
2117
2120
  oa_id: sourceAccountIdentifier,
2118
2121
  token: token,
2122
+ host: this.state.hostName,
2119
2123
  id: template?._id,
2120
2124
  preview: true,
2121
2125
  actionCallback: this.actionCallback,
2122
- }) : window.open(get(template, 'versions.base.content.zalo.previewUrl'), '_blank');
2126
+ });
2123
2127
  }
2124
2128
  }
2125
2129
 
@@ -18,7 +18,6 @@ export const LIBRARY = 'library';
18
18
  export const FULL = 'full';
19
19
  export const ALL = 'all';
20
20
  export const OUTBOUND = 'outbound';
21
- export const VIET_GUYS = 'vietguyszalotrans';
22
21
 
23
22
  const prefix = 'app/v2Containers/Zalo';
24
23
  export const ZALO_TEMPLATE_INFO_REQUEST = `${prefix}/ZALO_TEMPLATE_INFO_REQUEST`;
@@ -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, update } from 'lodash';
7
+ import { get, isEmpty } 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';
@@ -23,7 +23,7 @@ import {
23
23
  CAP_SPACE_32,
24
24
  CAP_WHITE,
25
25
  } from '@capillarytech/cap-ui-library/styled/variables';
26
- import { makeSelectZalo, makeSelectAccount, makeSelectGapitTemplates } from './selectors';
26
+ import { makeSelectZalo, makeSelectAccount } from './selectors';
27
27
  import { makeSelectMetaEntities, setInjectedTags } from '../Cap/selectors';
28
28
  import * as zaloActions from './actions';
29
29
  import './index.scss';
@@ -40,7 +40,6 @@ import {
40
40
  ERROR_ALERT,
41
41
  WARNING_ALERT,
42
42
  ZALO_STATUSES,
43
- VIET_GUYS,
44
43
  } from './constants';
45
44
  import { SMS, ZALO } from '../CreativesContainer/constants';
46
45
  import messages from './messages';
@@ -66,7 +65,6 @@ export const Zalo = (props) => {
66
65
  injectedTags,
67
66
  getFormData,
68
67
  selectedOfferDetails,
69
- gapItTemplateData,
70
68
  } = props || {};
71
69
  const {hostName = ''} = senderDetails;
72
70
  const { formatMessage } = intl;
@@ -75,21 +73,11 @@ export const Zalo = (props) => {
75
73
  const [username, setUsername] = useState('');
76
74
  const [templateName, setTemplateName] = useState('');
77
75
  const [templateId, setTemplateId] = useState('');
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
- );
76
+ const [templateListParams, setTemplateListParams] = useState([]);
88
77
  const [templatePreviewUrl, setTemplatePreviewUrl] = useState('');
89
78
  const [templateStatus, setZaloTemplateStatus] = useState(
90
79
  ZALO_STATUSES.ENABLE,
91
80
  );
92
- const [gapitAllTemplateData, setGapitAllTemplateData] = useState([]);
93
81
  const [tags, updateTags] = useState([]);
94
82
  const [textAreaId, updateTextAreaId] = useState('');
95
83
  const { zaloTemplateInfoValue = {}, zaloTemplateInfoStatus = REQUEST } =
@@ -130,44 +118,25 @@ export const Zalo = (props) => {
130
118
  setToken(accessToken || zaloToken);
131
119
  setUsername(name || accountName);
132
120
  }
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
- };
121
+ }, [selectedZaloAccount, templateData]);
144
122
 
145
123
  //gets template details
146
124
  useEffect(() => {
147
- if (zaloTempId && oa_id && token && username && hostName === VIET_GUYS) {
125
+ if (zaloTempId && oa_id && token && username && hostName) {
148
126
  actions.getTemplateInfoById({
149
127
  username,
150
128
  oa_id,
151
129
  token,
130
+ host: hostName,
152
131
  id: zaloTempId,
153
132
  actionCallback,
154
133
  });
155
- } else if (hostName !== VIET_GUYS) {
156
- const { _id: gapitTemplateId = '' } = templateData;
157
- if (gapitTemplateId) {
158
- const data = gapitAllTemplateData.find(template => template._id == gapitTemplateId);
159
- const { templateName = "", listParams = [], previewUrl = "", status = "" } = data?.versions?.base?.content?.zalo || {};
160
- updateTemplateData(gapitTemplateId, templateName, listParams, previewUrl, status);
161
- } else {
162
- const { id: gapitTemplateId = '', name: templateName = '', template: previewUrl = '', varMapped: listParams = {} } = templateData?.templateConfigs || {};
163
- updateTemplateData(gapitTemplateId, templateName, listParams, previewUrl, ZALO_STATUSES.ENABLE);
164
- }
165
134
  }
166
135
  //cleanup code
167
136
  return () => {
168
137
  actions.resetTemplateInfoData();
169
138
  };
170
- }, [zaloTempId, oa_id, token, username]);
139
+ }, [zaloTempId, oa_id, token, username, hostName]);
171
140
 
172
141
  const handleSetValues = (paramsData = []) =>
173
142
  paramsData?.map((paramData) => {
@@ -180,36 +149,27 @@ export const Zalo = (props) => {
180
149
  });
181
150
 
182
151
  const setDataForEdit = (setValues) => {
183
- if(hostName === VIET_GUYS) {
184
- const {
185
- name = '',
186
- _id: zaloId = '',
187
- versions: {
188
- base: {
189
- content: {
190
- zalo: {
191
- listParams: paramsData = [],
192
- previewUrl = '',
193
- status = '',
194
- } = {},
152
+ const {
153
+ name = '',
154
+ _id: zaloId = '',
155
+ versions: {
156
+ base: {
157
+ content: {
158
+ zalo: {
159
+ listParams: paramsData = [],
160
+ previewUrl = '',
161
+ status = '',
195
162
  } = {},
196
163
  } = {},
197
164
  } = {},
198
- } = zaloTemplateInfoValue;
199
- const handledListParams = setValues ? handleSetValues(paramsData) : paramsData;
200
- updateTemplateData(zaloId, name, handledListParams, previewUrl, status);
201
- } else {
202
- if (setValues) {
203
- const { id: gapitTemplateId = '', name: templateName = '', template: previewUrl = '', varMapped: listParams = {} } = templateData?.templateConfigs || {};
204
- const handledListParams = handleSetValues(listParams);
205
- updateTemplateData(gapitTemplateId, templateName, handledListParams, previewUrl, ZALO_STATUSES.ENABLE);
206
- } else {
207
- const { _id: gapitTemplateId = '' } = templateData;
208
- let data = gapitAllTemplateData?.find(template => template?._id == gapitTemplateId);
209
- const { templateName = "", listParams = [], previewUrl = "", status = "" } = data?.versions?.base?.content?.zalo || {};
210
- updateTemplateData(gapitTemplateId, templateName, listParams, previewUrl, status);
211
- }
212
- }
165
+ } = {},
166
+ } = zaloTemplateInfoValue;
167
+ setTemplateName(name);
168
+ setTemplateId(zaloId);
169
+ setTemplateListParams(setValues ? handleSetValues(paramsData) : paramsData);
170
+ setTemplatePreviewUrl(previewUrl);
171
+ setZaloTemplateStatus(status);
172
+ updateTextAreaId(paramsData[0]?.name);
213
173
  };
214
174
 
215
175
  useEffect(() => {
@@ -393,16 +353,12 @@ export const Zalo = (props) => {
393
353
  return disableCheck;
394
354
  };
395
355
  const createPayload = () => {
396
- let varMap = {};
397
- if (hostName !== VIET_GUYS) {
398
- varMap = templateListParams;
399
- } else {
400
- templateListParams?.forEach((listParam) => {
401
- const { name = '', value = '' } = listParam;
402
- varMap[name] = value;
403
- }
404
- );
356
+ const varMap = {};
357
+ templateListParams?.forEach((listParam) => {
358
+ const { name = '', value = '' } = listParam;
359
+ varMap[name] = value;
405
360
  }
361
+ );
406
362
  const payload = {
407
363
  channel: ZALO,
408
364
  accountId: oa_id,
@@ -417,7 +373,6 @@ export const Zalo = (props) => {
417
373
  varMapped: varMap,
418
374
  },
419
375
  token,
420
- host: hostName,
421
376
  };
422
377
  return payload;
423
378
  };
@@ -455,7 +410,7 @@ export const Zalo = (props) => {
455
410
  });
456
411
 
457
412
  return (
458
- <CapSpin spinning={zaloTemplateInfoStatus === REQUEST && hostName === VIET_GUYS}>
413
+ <CapSpin spinning={zaloTemplateInfoStatus === REQUEST}>
459
414
  <CapRow type="flex" className="cap-zalo-creatives">
460
415
  <CapColumn span={14}>
461
416
  {templateStatus && (
@@ -533,7 +488,6 @@ const mapStateToProps = createStructuredSelector({
533
488
  accountData: makeSelectAccount(),
534
489
  metaEntities: makeSelectMetaEntities(),
535
490
  injectedTags: setInjectedTags(),
536
- gapItTemplateData: makeSelectGapitTemplates(),
537
491
  });
538
492
 
539
493
  const mapDispatchToProps = (dispatch) => ({
@@ -9,11 +9,4 @@ const makeSelectZalo = () =>
9
9
  const makeSelectAccount = () =>
10
10
  createSelector(selectAccountDomain(), (substate) => substate && substate.toJS());
11
11
 
12
- const makeSelectGapitTemplates = () =>
13
- createSelector(selectAccountDomain(), (substate) => {
14
- const getAllTemplates = substate && substate.toJS();
15
- const { templates = []} = getAllTemplates;
16
- return templates;
17
- });
18
-
19
- export { makeSelectZalo, makeSelectAccount, makeSelectGapitTemplates };
12
+ export { makeSelectZalo, makeSelectAccount};
@@ -1,11 +1,11 @@
1
1
  import { fromJS } from "immutable";
2
- import { makeSelectZalo, makeSelectAccount, makeSelectGapitTemplates } from "../selectors";
2
+ import { makeSelectZalo, makeSelectAccount } from "../selectors";
3
3
 
4
4
  describe("makeSelectZalo", () => {
5
5
  it("returns the expected object with default values when substate is empty", () => {
6
6
  // Arrange
7
7
  const state = fromJS({ zalo: {} });
8
- const expected = {}
8
+ const expected = {};
9
9
  const selector = makeSelectZalo();
10
10
 
11
11
  // Act
@@ -17,7 +17,7 @@ describe("makeSelectZalo", () => {
17
17
  it("returns the expected object with default values when substate is empty for makeSelectAccount", () => {
18
18
  // Arrange
19
19
  const state = fromJS({ templates: {} });
20
- const expected = {}
20
+ const expected = {};
21
21
  const selector = makeSelectAccount();
22
22
 
23
23
  // Act
@@ -26,26 +26,3 @@ describe("makeSelectZalo", () => {
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
- });