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

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.171-alpha.0",
4
+ "version": "7.17.171",
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, host}) => {
529
- const url = `${API_ENDPOINT}/templates/v1/${id}/Zalo?username=${username}&oa_id=${oa_id}&token=${token}&host=${host}`;
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}`;
530
530
  const compressedTemplatesData = request(url, getAPICallObject('GET'));
531
531
  return compressedTemplatesData.then((data) => {
532
532
  const { response = '' } = data || {};
@@ -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';
@@ -125,15 +126,18 @@ export class Creatives extends React.Component {
125
126
  configs: { token = "" } = {},
126
127
  } = get(this.props, "Templates.selectedZaloAccount", {});
127
128
  const { hostName = ''} = get(this.props, "Templates.senderDetails", {});
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
- });
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
+ }
137
141
  }
138
142
  };
139
143
  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 { ZALO_STATUS_OPTIONS, ZALO_STATUSES } from '../Zalo/constants';
113
+ import { VIET_GUYS, 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 || this.state.hostName;
709
+ params.host = hostName;
710
710
  }
711
711
  }
712
712
 
@@ -806,8 +806,6 @@ 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;
811
809
  }
812
810
  queryParams.page = this.state.page;
813
811
  queryParams.perPage = this.state.perPageLimit;
@@ -867,12 +865,11 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
867
865
  queryParams.username = name;
868
866
  queryParams.oa_id = sourceAccountIdentifier;
869
867
  queryParams.token = token;
870
- queryParams.host = hostName || this.state.hostName;
868
+ queryParams.host = hostName;
871
869
  }
872
870
  this.setState({ page, templatesCount }, () => {
873
871
  queryParams.page = page;
874
872
  queryParams.perPage = this.state.perPageLimit;
875
- queryParams.host = this.state.hostName;
876
873
  const channel = this.state.channel;
877
874
  this.props.actions.getAllTemplates(channel, queryParams, `${copyOf}`);
878
875
  });
@@ -2115,15 +2112,14 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
2115
2112
  sourceAccountIdentifier = "",
2116
2113
  configs: { token = "" } = {},
2117
2114
  } = get(this.props, "Templates.selectedZaloAccount", {});
2118
- this.props.zaloActions.getTemplateInfoById({
2115
+ this.state.hostName === VIET_GUYS ? this.props.zaloActions.getTemplateInfoById({
2119
2116
  username: name,
2120
2117
  oa_id: sourceAccountIdentifier,
2121
2118
  token: token,
2122
- host: this.state.hostName,
2123
2119
  id: template?._id,
2124
2120
  preview: true,
2125
2121
  actionCallback: this.actionCallback,
2126
- });
2122
+ }) : window.open(get(template, 'versions.base.content.zalo.previewUrl'), '_blank');
2127
2123
  }
2128
2124
  }
2129
2125
 
@@ -21,6 +21,7 @@ import messages from './messages';
21
21
  import * as actions from './actions';
22
22
  import * as templateActions from '../Templates/actions';
23
23
  import Templates from '../Templates';
24
+ import * as commonUtil from '../../utils/common';
24
25
  import CallTask from '../CallTask';
25
26
  import Facebook from '../Facebook';
26
27
  import Viber from '../Viber';
@@ -60,7 +61,6 @@ export class TemplatesV2 extends React.Component { // eslint-disable-line react/
60
61
  sms: {content: <></>, tab: intl.formatMessage(messages.sms), key: 'sms'},
61
62
  rcs: { content: <></>, tab: intl.formatMessage(messages.rcs), key: RCS },
62
63
  email: {content: <></>, tab: intl.formatMessage(messages.email), key: 'email'},
63
- weChat: {content: <></>, tab: intl.formatMessage(messages.wechat), key: 'wechat'},
64
64
  //'wechat': {content: this.getTemplatesComponent('wechat'), tab: 'Wechat', key: 'wechat'},
65
65
  mPush: {content: <></>, tab: intl.formatMessage(messages.pushNotification), key: 'mobilepush'},
66
66
  inApp: { content: <div></div>, tab: intl.formatMessage(messages.inapp), key: INAPP },
@@ -70,6 +70,15 @@ export class TemplatesV2 extends React.Component { // eslint-disable-line react/
70
70
  whatsapp: { content: <></>, tab: intl.formatMessage(messages.whatsapp), key: WHATSAPP },
71
71
  zalo: { content: <div></div>, tab: intl.formatMessage(messages.zalo), key: ZALO },
72
72
  };
73
+ //Hiding we chat for all orgs across UI for now and enabling it based on feature 'ENABLE_WECHAT'
74
+
75
+ if (commonUtil.hasWechatFeatureEnabled()) {
76
+ defaultPanes.weChat = {
77
+ content: <></>,
78
+ tab: intl.formatMessage(messages.wechat),
79
+ key: 'wechat',
80
+ };
81
+ }
73
82
  let filteredPanes = Object.keys(defaultPanes)
74
83
  .filter((key) => !channelsToHide.includes(key)).reduce((obj = [], key) => {
75
84
  obj.push(defaultPanes[key]);
@@ -153,7 +162,7 @@ export class TemplatesV2 extends React.Component { // eslint-disable-line react/
153
162
  if (queryItems.channel === WHATSAPP) {
154
163
  this.channelChange(WHATSAPP);
155
164
  }
156
- if(this.props?.isFullMode){
165
+ if (this.props?.isFullMode) {
157
166
  this.props.templateActions.getCdnTransformationConfig();
158
167
  }
159
168
  }
@@ -91,7 +91,8 @@ describe("Test TemplatesV2", () => {
91
91
  expect(getByText('Email')).toBeInTheDocument();
92
92
  expect(getByText('Push notification')).toBeInTheDocument();
93
93
  expect(getByText('Line')).toBeInTheDocument();
94
- expect(getByText('Wechat')).toBeInTheDocument();
94
+ //commented for removing wechat in tab
95
+ // expect(getByText('Wechat')).toBeInTheDocument();
95
96
  expect(getByText('Viber')).toBeInTheDocument();
96
97
  expect(getByText('Facebook')).toBeInTheDocument();
97
98
  expect(getByText('WhatsApp')).toBeInTheDocument();
@@ -18,6 +18,7 @@ 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';
21
22
 
22
23
  const prefix = 'app/v2Containers/Zalo';
23
24
  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 } 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';
@@ -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 } from './selectors';
26
+ import { makeSelectZalo, makeSelectAccount, makeSelectGapitTemplates } from './selectors';
27
27
  import { makeSelectMetaEntities, setInjectedTags } from '../Cap/selectors';
28
28
  import * as zaloActions from './actions';
29
29
  import './index.scss';
@@ -40,6 +40,7 @@ import {
40
40
  ERROR_ALERT,
41
41
  WARNING_ALERT,
42
42
  ZALO_STATUSES,
43
+ VIET_GUYS,
43
44
  } from './constants';
44
45
  import { SMS, ZALO } from '../CreativesContainer/constants';
45
46
  import messages from './messages';
@@ -65,6 +66,7 @@ export const Zalo = (props) => {
65
66
  injectedTags,
66
67
  getFormData,
67
68
  selectedOfferDetails,
69
+ gapItTemplateData,
68
70
  } = props || {};
69
71
  const {hostName = ''} = senderDetails;
70
72
  const { formatMessage } = intl;
@@ -73,11 +75,21 @@ export const Zalo = (props) => {
73
75
  const [username, setUsername] = useState('');
74
76
  const [templateName, setTemplateName] = useState('');
75
77
  const [templateId, setTemplateId] = useState('');
76
- const [templateListParams, setTemplateListParams] = 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
+ );
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 } =
@@ -118,25 +130,44 @@ export const Zalo = (props) => {
118
130
  setToken(accessToken || zaloToken);
119
131
  setUsername(name || accountName);
120
132
  }
121
- }, [selectedZaloAccount, templateData]);
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
+ };
122
144
 
123
145
  //gets template details
124
146
  useEffect(() => {
125
- if (zaloTempId && oa_id && token && username && hostName) {
147
+ if (zaloTempId && oa_id && token && username && hostName === VIET_GUYS) {
126
148
  actions.getTemplateInfoById({
127
149
  username,
128
150
  oa_id,
129
151
  token,
130
- host: hostName,
131
152
  id: zaloTempId,
132
153
  actionCallback,
133
154
  });
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
+ }
134
165
  }
135
166
  //cleanup code
136
167
  return () => {
137
168
  actions.resetTemplateInfoData();
138
169
  };
139
- }, [zaloTempId, oa_id, token, username, hostName]);
170
+ }, [zaloTempId, oa_id, token, username]);
140
171
 
141
172
  const handleSetValues = (paramsData = []) =>
142
173
  paramsData?.map((paramData) => {
@@ -149,27 +180,36 @@ export const Zalo = (props) => {
149
180
  });
150
181
 
151
182
  const setDataForEdit = (setValues) => {
152
- const {
153
- name = '',
154
- _id: zaloId = '',
155
- versions: {
156
- base: {
157
- content: {
158
- zalo: {
159
- listParams: paramsData = [],
160
- previewUrl = '',
161
- status = '',
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
+ } = {},
162
195
  } = {},
163
196
  } = {},
164
197
  } = {},
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);
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
+ }
173
213
  };
174
214
 
175
215
  useEffect(() => {
@@ -353,12 +393,16 @@ export const Zalo = (props) => {
353
393
  return disableCheck;
354
394
  };
355
395
  const createPayload = () => {
356
- const varMap = {};
357
- templateListParams?.forEach((listParam) => {
358
- const { name = '', value = '' } = listParam;
359
- varMap[name] = value;
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
+ );
360
405
  }
361
- );
362
406
  const payload = {
363
407
  channel: ZALO,
364
408
  accountId: oa_id,
@@ -373,6 +417,7 @@ export const Zalo = (props) => {
373
417
  varMapped: varMap,
374
418
  },
375
419
  token,
420
+ host: hostName,
376
421
  };
377
422
  return payload;
378
423
  };
@@ -410,7 +455,7 @@ export const Zalo = (props) => {
410
455
  });
411
456
 
412
457
  return (
413
- <CapSpin spinning={zaloTemplateInfoStatus === REQUEST}>
458
+ <CapSpin spinning={zaloTemplateInfoStatus === REQUEST && hostName === VIET_GUYS}>
414
459
  <CapRow type="flex" className="cap-zalo-creatives">
415
460
  <CapColumn span={14}>
416
461
  {templateStatus && (
@@ -488,6 +533,7 @@ const mapStateToProps = createStructuredSelector({
488
533
  accountData: makeSelectAccount(),
489
534
  metaEntities: makeSelectMetaEntities(),
490
535
  injectedTags: setInjectedTags(),
536
+ gapItTemplateData: makeSelectGapitTemplates(),
491
537
  });
492
538
 
493
539
  const mapDispatchToProps = (dispatch) => ({
@@ -9,4 +9,11 @@ const makeSelectZalo = () =>
9
9
  const makeSelectAccount = () =>
10
10
  createSelector(selectAccountDomain(), (substate) => substate && substate.toJS());
11
11
 
12
- export { makeSelectZalo, makeSelectAccount};
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 };
@@ -1,11 +1,11 @@
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", () => {
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,3 +26,26 @@ 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
+ });