@capillarytech/creatives-library 7.17.60 → 7.17.61

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.60",
4
+ "version": "7.17.61",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -626,7 +626,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
626
626
  const zaloPreviewUrl = get(nextProps, 'Zalo.zaloTemplatePreviewData.versions.base.content.zalo.previewUrl', '');
627
627
  if (zaloPreviewUrl && this.state.channel.toLowerCase() === ZALO_LOWERCASE) {
628
628
  handlePreviewInNewTab(zaloPreviewUrl);
629
- this.props.zaloActions.resetTemplateInfoData();
629
+ this.props.zaloActions.resetTemplatePreviewData();
630
630
  }
631
631
  }
632
632
 
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  ZALO_TEMPLATE_INFO_REQUEST,
3
3
  ZALO_TEMPLATE_PREVIEW_RESET,
4
+ ZALO_TEMPLATE_INFO_RESET,
4
5
  } from "./constants";
5
6
 
6
7
  export function getTemplateInfoById(payload) {
@@ -10,8 +11,14 @@ export function getTemplateInfoById(payload) {
10
11
  };
11
12
  }
12
13
 
13
- export function resetTemplateInfoData() {
14
+ export function resetTemplatePreviewData() {
14
15
  return {
15
16
  type: ZALO_TEMPLATE_PREVIEW_RESET,
16
17
  };
17
18
  }
19
+
20
+ export function resetTemplateInfoData() {
21
+ return {
22
+ type: ZALO_TEMPLATE_INFO_RESET,
23
+ };
24
+ }
@@ -24,6 +24,7 @@ export const ZALO_TEMPLATE_INFO_SUCCESS = `${prefix}/ZALO_TEMPLATE_INFO_SUCCESS`
24
24
  export const ZALO_TEMPLATE_INFO_ERROR = `${prefix}/ZALO_TEMPLATE_INFO_ERROR`;
25
25
  export const ZALO_TEMPLATE_PREVIEW_RESET = `${prefix}/ZALO_TEMPLATE_PREVIEW_RESET`;
26
26
  export const ZALO_TEMPLATE_PREVIEW_INFO = `${prefix}/ZALO_TEMPLATE_PREVIEW_INFO`;
27
+ export const ZALO_TEMPLATE_INFO_RESET = `${prefix}/ZALO_TEMPLATE_INFO_RESET`;
27
28
 
28
29
  export const ZALO_STATUSES = {
29
30
  PENDING_REVIEW: 'PENDING_REVIEW',
@@ -55,7 +55,7 @@ export const Zalo = (props) => {
55
55
  isFullMode,
56
56
  templateData = {},
57
57
  editData = {},
58
- accountData = {},
58
+ accountData: { selectedZaloAccount = {} } = {},
59
59
  globalActions,
60
60
  location,
61
61
  getDefaultTags,
@@ -80,7 +80,14 @@ export const Zalo = (props) => {
80
80
  const [textAreaId, updateTextAreaId] = useState('');
81
81
  const { zaloTemplateInfoValue = {}, zaloTemplateInfoStatus = REQUEST } =
82
82
  editData;
83
- const { _id, templateConfigs: { varMapped = {} } = {} } = templateData;
83
+ const {
84
+ _id = '',
85
+ accountId = '',
86
+ accountName = '',
87
+ templateConfigs: { id = '', varMapped = {} } = {},
88
+ token: zaloToken = '',
89
+ } = templateData;
90
+ const zaloTempId = _id || id;
84
91
  const ZaloFooter = styled.div`
85
92
  background-color: ${CAP_WHITE};
86
93
  position: fixed;
@@ -97,31 +104,34 @@ export const Zalo = (props) => {
97
104
  `;
98
105
  //gets account details
99
106
  useEffect(() => {
100
- const accountObj = accountData.selectedZaloAccount || {};
101
- if (!isEmpty(accountObj)) {
107
+ if (!isEmpty(selectedZaloAccount) || !isEmpty(templateData)) {
102
108
  const {
103
109
  sourceAccountIdentifier = '',
104
110
  configs: { token: accessToken = '' } = {},
105
111
  name = '',
106
- } = accountObj;
107
- setOaId(sourceAccountIdentifier);
108
- setToken(accessToken);
109
- setUsername(name);
112
+ } = selectedZaloAccount;
113
+ setOaId(sourceAccountIdentifier || accountId);
114
+ setToken(accessToken || zaloToken);
115
+ setUsername(name || accountName);
110
116
  }
111
- }, [accountData.selectedZaloAccount]);
117
+ }, [selectedZaloAccount, templateData]);
112
118
 
113
119
  //gets template details
114
120
  useEffect(() => {
115
- if (_id && oa_id && token && username && isEmpty(varMapped)) {
121
+ if (zaloTempId && oa_id && token && username) {
116
122
  actions.getTemplateInfoById({
117
123
  username,
118
124
  oa_id,
119
125
  token,
120
- id: _id,
126
+ id: zaloTempId,
121
127
  actionCallback,
122
128
  });
123
129
  }
124
- }, [_id, oa_id, token, username]);
130
+ //cleanup code
131
+ return () => {
132
+ actions.resetTemplateInfoData();
133
+ };
134
+ }, [zaloTempId, oa_id, token, username]);
125
135
 
126
136
  const handleSetValues = (paramsData = []) =>
127
137
  paramsData.map((paramData) => {
@@ -136,7 +146,7 @@ export const Zalo = (props) => {
136
146
  const setDataForEdit = (setValues) => {
137
147
  const {
138
148
  name = '',
139
- _id: id = '',
149
+ _id: zaloId = '',
140
150
  versions: {
141
151
  base: {
142
152
  content: {
@@ -150,7 +160,7 @@ export const Zalo = (props) => {
150
160
  } = {},
151
161
  } = zaloTemplateInfoValue;
152
162
  setTemplateName(name);
153
- setTemplateId(id);
163
+ setTemplateId(zaloId);
154
164
  setTemplateListParams(setValues ? handleSetValues(paramsData) : paramsData);
155
165
  setTemplatePreviewUrl(previewUrl);
156
166
  setZaloTemplateStatus(status);
@@ -165,7 +175,7 @@ export const Zalo = (props) => {
165
175
  if (!isEmpty(varMapped)) {
166
176
  setDataForEdit(true);
167
177
  }
168
- }, [varMapped]);
178
+ }, [varMapped, zaloTemplateInfoValue]);
169
179
 
170
180
  useEffect(() => {
171
181
  let tag = get(metaEntities, `tags.standard`, []);
@@ -353,6 +363,7 @@ export const Zalo = (props) => {
353
363
  template: templatePreviewUrl,
354
364
  varMapped: varMap,
355
365
  },
366
+ token,
356
367
  };
357
368
  return payload;
358
369
  };
@@ -5,6 +5,7 @@ import {
5
5
  ZALO_TEMPLATE_INFO_REQUEST,
6
6
  ZALO_TEMPLATE_PREVIEW_RESET,
7
7
  ZALO_TEMPLATE_PREVIEW_INFO,
8
+ ZALO_TEMPLATE_INFO_RESET,
8
9
  SUCCESS,
9
10
  REQUEST,
10
11
  ERROR,
@@ -48,6 +49,11 @@ const zaloReducer = (state = initialState, action) => {
48
49
  .set("zaloTemplateInfoStatus", REQUEST)
49
50
  .set("zaloTemplatePreviewData", "")
50
51
  .set("zaloTemplateInfoError", null);
52
+ case ZALO_TEMPLATE_INFO_RESET:
53
+ return state
54
+ .set("zaloTemplateInfoStatus", REQUEST)
55
+ .set("zaloTemplateInfoValue", "")
56
+ .set("zaloTemplateInfoError", null);
51
57
 
52
58
  default:
53
59
  return state;
@@ -15,6 +15,12 @@ describe("Test zalo actions", () => {
15
15
  const expected = {
16
16
  type: types.ZALO_TEMPLATE_PREVIEW_RESET,
17
17
  };
18
+ expect(actions.resetTemplatePreviewData()).toEqual(expected);
19
+ });
20
+ it("has a type of ZALO_TEMPLATE_INFO_RESET action", () => {
21
+ const expected = {
22
+ type: types.ZALO_TEMPLATE_INFO_RESET,
23
+ };
18
24
  expect(actions.resetTemplateInfoData()).toEqual(expected);
19
25
  });
20
26
  });
@@ -19,6 +19,7 @@ import { render, screen, fireEvent } from '../../../utils/test-utils';
19
19
 
20
20
  const mockActions = {
21
21
  getTemplateInfoById: jest.fn(),
22
+ resetTemplateInfoData: jest.fn(),
22
23
  };
23
24
  const mockGlobalActions = {
24
25
  fetchSchemaForEntity: jest.fn(),
@@ -6,6 +6,7 @@ import {
6
6
  ZALO_TEMPLATE_INFO_ERROR,
7
7
  ZALO_TEMPLATE_PREVIEW_INFO,
8
8
  ZALO_TEMPLATE_PREVIEW_RESET,
9
+ ZALO_TEMPLATE_INFO_RESET,
9
10
  REQUEST,
10
11
  SUCCESS,
11
12
  ERROR,
@@ -76,6 +77,16 @@ describe("zalo reducer", () => {
76
77
  expect(zaloReducer(state, action)).toEqual(expectedResult);
77
78
  });
78
79
 
80
+ it("should handle ZALO_TEMPLATE_INFO_RESET action", () => {
81
+ action.type = ZALO_TEMPLATE_INFO_RESET;
82
+ state = state
83
+ .set("zaloTemplateInfoStatus", REQUEST)
84
+ .set("zaloTemplateInfoValue", "")
85
+ .set("zaloTemplateInfoError", null);
86
+ const expectedResult = state;
87
+ expect(zaloReducer(state, action)).toEqual(expectedResult);
88
+ });
89
+
79
90
  it("should handle default action", () => {
80
91
  action.type = "deafult_action";
81
92
  const expectedResult = state;