@capillarytech/creatives-library 7.17.39-alpha.1 → 7.17.39-alpha.3

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.39-alpha.1",
4
+ "version": "7.17.39-alpha.3",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -500,6 +500,13 @@ export class Creatives extends React.Component {
500
500
  },
501
501
  },
502
502
  };
503
+ break;
504
+ }
505
+ case constants.ZALO: {
506
+ creativesTemplateData = {
507
+ ...templateData,
508
+ };
509
+ break;
503
510
  }
504
511
  default:
505
512
  break;
@@ -504,6 +504,6 @@ export default defineMessages({
504
504
  },
505
505
  "zaloOnlyApprovedTemplates": {
506
506
  id: `${scope}.zaloOnlyApprovedTemplates`,
507
- defaultMessage: 'Only enabled templates are shown here',
507
+ defaultMessage: 'Only enabled/approved templates are shown here',
508
508
  },
509
509
  });
@@ -80,6 +80,7 @@ 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
84
  const ZaloFooter = styled.div`
84
85
  background-color: ${CAP_WHITE};
85
86
  position: fixed;
@@ -111,39 +112,63 @@ export const Zalo = (props) => {
111
112
 
112
113
  //gets template details
113
114
  useEffect(() => {
114
- const { _id: id } = templateData;
115
- if (id && oa_id && token && username) {
115
+ if (_id && oa_id && token && username && isEmpty(varMapped)) {
116
116
  actions.getTemplateInfoById({
117
117
  username,
118
118
  oa_id,
119
119
  token,
120
- id,
120
+ id: _id,
121
121
  actionCallback,
122
122
  });
123
123
  }
124
- }, [templateData._id, oa_id, token, username]);
124
+ }, [_id, oa_id, token, username]);
125
125
 
126
- // here listParams and previewUrl data will be setting in respective states. We got that data by destructring
127
- useEffect(() => {
126
+ const handleSetValues = (paramsData = []) =>
127
+ paramsData.map((paramData) => {
128
+ // eslint-disable-next-line no-restricted-syntax
129
+ for (const key in varMapped) {
130
+ if (paramData?.name === key) {
131
+ // eslint-disable-next-line no-param-reassign
132
+ paramData.value = varMapped[key];
133
+ }
134
+ }
135
+ return paramData;
136
+ });
137
+
138
+ const setDataForEdit = (setValues) => {
128
139
  const {
129
140
  name = '',
130
- _id = '',
141
+ _id: id = '',
131
142
  versions: {
132
143
  base: {
133
144
  content: {
134
- zalo: { listParams = [], previewUrl = '', status = '' } = {},
145
+ zalo: {
146
+ listParams: paramsData = [],
147
+ previewUrl = '',
148
+ status = '',
149
+ } = {},
135
150
  } = {},
136
151
  } = {},
137
152
  } = {},
138
153
  } = zaloTemplateInfoValue;
139
154
  setTemplateName(name);
140
- setTemplateId(_id);
141
- setTemplateListParams(listParams);
155
+ setTemplateId(id);
156
+ setTemplateListParams(setValues ? handleSetValues(paramsData) : paramsData);
142
157
  setTemplatePreviewUrl(previewUrl);
143
158
  setZaloTemplateStatus(status);
144
- updateTextAreaId(listParams[0]?.name);
159
+ updateTextAreaId(paramsData[0]?.name);
160
+ };
161
+
162
+ // in creatives
163
+ useEffect(() => {
164
+ setDataForEdit(false);
145
165
  }, [zaloTemplateInfoValue]);
146
166
 
167
+ // in campaigns
168
+ useEffect(() => {
169
+ setDataForEdit(true);
170
+ }, [varMapped]);
171
+
147
172
  useEffect(() => {
148
173
  let tag = get(metaEntities, `tags.standard`, []);
149
174
  const { type, module } = location?.query || {};
@@ -319,10 +344,10 @@ export const Zalo = (props) => {
319
344
  return disableCheck;
320
345
  };
321
346
  const createPayload = () => {
322
- const varMapped = {};
347
+ const varMap = {};
323
348
  templateListParams.forEach((listParam) => {
324
349
  const { name, value } = listParam;
325
- varMapped[name] = value;
350
+ varMap[name] = value;
326
351
  });
327
352
  const payload = {
328
353
  channel: ZALO,
@@ -332,7 +357,7 @@ export const Zalo = (props) => {
332
357
  _id: templateId,
333
358
  name: templateName,
334
359
  template: templatePreviewUrl,
335
- varMapped,
360
+ varMapped: varMap,
336
361
  },
337
362
  };
338
363
  return payload;
@@ -11466,61 +11466,16 @@ export const accountData = {
11466
11466
 
11467
11467
  export const templateData = {
11468
11468
  _id: 463745,
11469
+ };
11470
+
11471
+ export const templateConfigs = {
11472
+ _id: 268532,
11469
11473
  name: 'Test QR - Thông báo thanh toán thành công',
11470
- versions: {
11471
- base: {
11472
- content: {
11473
- zalo: {
11474
- templateId: '268531',
11475
- templateName: 'Test QR - Thông báo thanh toán thành công',
11476
- listParams: [
11477
- {
11478
- name: 'danh_xung',
11479
- require: true,
11480
- type: 'STRING',
11481
- maxLength: 30,
11482
- minLength: 0,
11483
- acceptNull: false,
11484
- error: '',
11485
- value: '',
11486
- },
11487
- {
11488
- name: 'name',
11489
- require: true,
11490
- type: 'STRING',
11491
- maxLength: 20,
11492
- minLength: 0,
11493
- acceptNull: false,
11494
- error: '',
11495
- value: '',
11496
- },
11497
- {
11498
- name: 'ma_so',
11499
- require: true,
11500
- type: 'NUMBER',
11501
- maxLength: 10,
11502
- minLength: 0,
11503
- acceptNull: false,
11504
- error: '',
11505
- value: '',
11506
- },
11507
- {
11508
- name: 'ma_so1',
11509
- require: true,
11510
- type: 'DATE',
11511
- maxLength: 30,
11512
- minLength: 0,
11513
- acceptNull: false,
11514
- error: '',
11515
- value: '',
11516
- },
11517
- ],
11518
- previewUrl:
11519
- 'https://account.zalo.cloud/znspreview/-e0cMil4NU5WUUAVzP7T_g==',
11520
- status: 'ENABLE',
11521
- },
11522
- },
11523
- },
11474
+ template: 'https://account.zalo.cloud/znspreview/-e0cMil4NU5WUUAVzP7T_g==',
11475
+ varMapped: {
11476
+ danh_xung: '1',
11477
+ name: '2',
11478
+ ma_so: '3',
11479
+ ma_so1: '4',
11524
11480
  },
11525
- type: 'ZALO',
11526
11481
  };
@@ -1,174 +0,0 @@
1
- import React from 'react';
2
- import { injectIntl } from 'react-intl';
3
- import { browserHistory } from 'react-router';
4
- import '@testing-library/jest-dom';
5
- import { Provider } from 'react-redux';
6
- import configureStore from '../../../store';
7
- import { Zalo } from '..';
8
- import {
9
- metaEntities,
10
- editData,
11
- location,
12
- getDefaultTags,
13
- injectedTags,
14
- accountData,
15
- templateData,
16
- } from './mockData';
17
- import { render, screen, fireEvent } from '../../../utils/test-utils';
18
-
19
- const mockActions = {
20
- getTemplateInfoById: jest.fn(),
21
- };
22
- const mockGlobalActions = {
23
- fetchSchemaForEntity: jest.fn(),
24
- };
25
-
26
- let store;
27
- beforeAll(() => {
28
- store = configureStore({}, browserHistory);
29
- });
30
-
31
- const ComponentToRender = injectIntl(Zalo);
32
- const renderComponent = (props) =>
33
- render(
34
- <Provider store={store}>
35
- <ComponentToRender {...props} />
36
- </Provider>,
37
- );
38
-
39
- describe('Test activity zalo container', () => {
40
- it('test case for zalo template', async () => {
41
- renderComponent({
42
- actions: mockActions,
43
- globalActions: mockGlobalActions,
44
- editData,
45
- metaEntities,
46
- location,
47
- getDefaultTags,
48
- injectedTags,
49
- accountData,
50
- templateData,
51
- isFullMode: true,
52
- });
53
- const inputBox = await screen.findAllByPlaceholderText(
54
- 'Add labels or text or combination of both',
55
- );
56
- fireEvent.change(inputBox[0], { target: { value: 'Hello, welcome' } });
57
- inputBox[0].focus();
58
- const previewButton = screen.getByTestId('preview-link-button');
59
- previewButton.click();
60
- expect(
61
- screen.getByText('This template has been enabled'),
62
- ).toBeInTheDocument();
63
- });
64
-
65
- it('test case for text field curly braces error', async () => {
66
- renderComponent({
67
- actions: mockActions,
68
- globalActions: mockGlobalActions,
69
- editData,
70
- metaEntities,
71
- location,
72
- getDefaultTags,
73
- injectedTags,
74
- accountData,
75
- templateData,
76
- isFullMode: true,
77
- });
78
- const inputBox = await screen.findAllByPlaceholderText(
79
- 'Add labels or text or combination of both',
80
- );
81
- fireEvent.change(inputBox[0], { target: { value: 'Hello, welcome {{' } });
82
- inputBox[0].focus();
83
- expect(
84
- screen.getByText('Invalid label, please close all curly braces'),
85
- ).toBeInTheDocument();
86
- });
87
-
88
- it('test case for unsupported tag', async () => {
89
- renderComponent({
90
- actions: mockActions,
91
- globalActions: mockGlobalActions,
92
- editData,
93
- metaEntities,
94
- location,
95
- getDefaultTags,
96
- injectedTags,
97
- accountData,
98
- templateData,
99
- isFullMode: true,
100
- });
101
- const inputBox = await screen.findAllByPlaceholderText(
102
- 'Add labels or text or combination of both',
103
- );
104
- fireEvent.change(inputBox[0], {
105
- target: { value: 'Hello, welcome {{fsdaf}}' },
106
- });
107
- inputBox[0].focus();
108
- expect(
109
- screen.getByText(
110
- 'Unsupported tags: fsdaf. Please remove them from this message.',
111
- ),
112
- ).toBeInTheDocument();
113
- });
114
-
115
- it('test case for length check', async () => {
116
- renderComponent({
117
- actions: mockActions,
118
- globalActions: mockGlobalActions,
119
- editData,
120
- metaEntities,
121
- location,
122
- getDefaultTags,
123
- injectedTags,
124
- accountData,
125
- templateData,
126
- isFullMode: false,
127
- });
128
- const inputBox = await screen.findAllByPlaceholderText(
129
- 'Add labels or text or combination of both',
130
- );
131
- fireEvent.change(inputBox[0], {
132
- target: {
133
- value:
134
- 'Hello, welcome user. Habata itara modoranai to ittta Mezashita no wa aoi aoi ano sora',
135
- },
136
- });
137
- inputBox[0].focus();
138
- expect(
139
- screen.getByText(
140
- 'Character count for this variable should be in between 0 to 30',
141
- ),
142
- ).toBeInTheDocument();
143
- });
144
-
145
- it('test case for length check', async () => {
146
- renderComponent({
147
- actions: mockActions,
148
- globalActions: mockGlobalActions,
149
- editData,
150
- metaEntities,
151
- location,
152
- getDefaultTags,
153
- injectedTags,
154
- accountData,
155
- templateData,
156
- isFullMode: true,
157
- });
158
- const inputBox = await screen.findAllByPlaceholderText(
159
- 'Add labels or text or combination of both',
160
- );
161
- fireEvent.change(inputBox[0], {
162
- target: {
163
- value:
164
- 'Hello, welcome user. Habata itara modoranai to ittta Mezashita no wa aoi aoi ano sora',
165
- },
166
- });
167
- inputBox[0].focus();
168
- expect(
169
- screen.getByText(
170
- 'Character count for this variable should be in between 0 to 30',
171
- ),
172
- ).toBeInTheDocument();
173
- });
174
- });