@capillarytech/creatives-library 8.0.333 → 8.0.334-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 +1 -1
- package/services/api.js +20 -0
- package/services/tests/api.test.js +59 -0
- package/v2Components/CapCustomSkeleton/index.js +1 -1
- package/v2Components/CapCustomSkeleton/tests/__snapshots__/index.test.js.snap +12 -12
- package/v2Containers/Assets/images/archive_Empty_Illustration.svg +9 -0
- package/v2Containers/Templates/ChannelTypeIllustration.js +23 -6
- package/v2Containers/Templates/_templates.scss +99 -24
- package/v2Containers/Templates/actions.js +36 -0
- package/v2Containers/Templates/constants.js +23 -0
- package/v2Containers/Templates/index.js +287 -30
- package/v2Containers/Templates/messages.js +68 -0
- package/v2Containers/Templates/reducer.js +68 -0
- package/v2Containers/Templates/sagas.js +89 -1
- package/v2Containers/Templates/selectors.js +12 -0
- package/v2Containers/Templates/tests/ChannelTypeIllustration.test.js +12 -0
- package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1375 -1114
- package/v2Containers/Templates/tests/index.test.js +6 -0
- package/v2Containers/Templates/tests/reducer.test.js +178 -0
- package/v2Containers/Templates/tests/sagas.test.js +306 -8
- package/v2Containers/Templates/tests/selector.test.js +32 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import {
|
|
2
|
-
call, put, takeLatest, all,
|
|
3
|
+
call, put, select, takeLatest, all,
|
|
3
4
|
} from 'redux-saga/effects';
|
|
4
5
|
import get from 'lodash/get';
|
|
6
|
+
import { CapNotification } from '@capillarytech/cap-ui-library';
|
|
5
7
|
// import { schema, normalize } from 'normalizr';
|
|
6
8
|
import * as Api from '../../services/api';
|
|
7
9
|
import * as types from './constants';
|
|
@@ -9,6 +11,18 @@ import { saveCdnConfigs, removeAllCdnLocalStorageItems } from '../../utils/cdnTr
|
|
|
9
11
|
import { COPY_OF } from '../../constants/unified';
|
|
10
12
|
import { ZALO_TEMPLATE_INFO_REQUEST } from '../Zalo/constants';
|
|
11
13
|
import { getTemplateInfoById } from '../Zalo/saga';
|
|
14
|
+
|
|
15
|
+
const templateNameDescription = (templateName) => (
|
|
16
|
+
templateName
|
|
17
|
+
? (
|
|
18
|
+
<span>
|
|
19
|
+
<span style={{ color: '#5E6C84' }}>Template name </span>
|
|
20
|
+
<span style={{ color: '#091E42' }}>{templateName}</span>
|
|
21
|
+
</span>
|
|
22
|
+
)
|
|
23
|
+
: undefined
|
|
24
|
+
);
|
|
25
|
+
|
|
12
26
|
// Individual exports for testing
|
|
13
27
|
export function* getAllTemplates(channel, queryParams) {
|
|
14
28
|
try {
|
|
@@ -201,6 +215,76 @@ export function* getSenderDetails({
|
|
|
201
215
|
}
|
|
202
216
|
}
|
|
203
217
|
|
|
218
|
+
export function* archiveTemplateSaga({ channel, id, templateName }) {
|
|
219
|
+
try {
|
|
220
|
+
yield call(Api.archiveTemplate, { channel, id });
|
|
221
|
+
yield put({ type: types.ARCHIVE_TEMPLATE_SUCCESS, id });
|
|
222
|
+
CapNotification.success({ message: 'Template archived successfully', description: templateNameDescription(templateName) });
|
|
223
|
+
const archiveFilter = yield select((state) => state.get('templates') ? state.get('templates').get('archiveFilter', 'active') : 'active');
|
|
224
|
+
yield put({ type: types.GET_ALL_TEMPLATES_REQUEST, channel, queryParams: { page: 1, archiveStatus: archiveFilter } });
|
|
225
|
+
} catch (error) {
|
|
226
|
+
yield put({ type: types.ARCHIVE_TEMPLATE_FAILURE, error });
|
|
227
|
+
CapNotification.error({ message: 'Failed to archive template' });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function* unarchiveTemplateSaga({ channel, id, templateName }) {
|
|
232
|
+
try {
|
|
233
|
+
yield call(Api.unarchiveTemplate, { channel, id });
|
|
234
|
+
yield put({ type: types.UNARCHIVE_TEMPLATE_SUCCESS, id });
|
|
235
|
+
CapNotification.success({ message: 'Template unarchived successfully', description: templateNameDescription(templateName) });
|
|
236
|
+
const archiveFilter = yield select((state) => state.get('templates') ? state.get('templates').get('archiveFilter', 'active') : 'active');
|
|
237
|
+
yield put({ type: types.GET_ALL_TEMPLATES_REQUEST, channel, queryParams: { page: 1, archiveStatus: archiveFilter } });
|
|
238
|
+
} catch (error) {
|
|
239
|
+
yield put({ type: types.UNARCHIVE_TEMPLATE_FAILURE, error });
|
|
240
|
+
CapNotification.error({ message: 'Failed to unarchive template' });
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function* bulkArchiveTemplatesSaga({ channel, ids }) {
|
|
245
|
+
try {
|
|
246
|
+
const result = yield call(Api.bulkArchiveTemplates, { channel, ids });
|
|
247
|
+
yield put({ type: types.BULK_ARCHIVE_SUCCESS });
|
|
248
|
+
const count = get(result, 'response.modifiedCount', ids.length);
|
|
249
|
+
CapNotification.success({ message: `${count} templates archived successfully` });
|
|
250
|
+
const archiveFilter = yield select((state) => state.get('templates') ? state.get('templates').get('archiveFilter', 'active') : 'active');
|
|
251
|
+
yield put({ type: types.GET_ALL_TEMPLATES_REQUEST, channel, queryParams: { page: 1, archiveStatus: archiveFilter } });
|
|
252
|
+
} catch (error) {
|
|
253
|
+
yield put({ type: types.BULK_ARCHIVE_FAILURE, error });
|
|
254
|
+
CapNotification.error({ message: 'Failed to archive templates' });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function* bulkUnarchiveTemplatesSaga({ channel, ids }) {
|
|
259
|
+
try {
|
|
260
|
+
const result = yield call(Api.bulkUnarchiveTemplates, { channel, ids });
|
|
261
|
+
yield put({ type: types.BULK_UNARCHIVE_SUCCESS });
|
|
262
|
+
const count = get(result, 'response.modifiedCount', ids.length);
|
|
263
|
+
CapNotification.success({ message: `${count} templates unarchived successfully` });
|
|
264
|
+
const archiveFilter = yield select((state) => state.get('templates') ? state.get('templates').get('archiveFilter', 'active') : 'active');
|
|
265
|
+
yield put({ type: types.GET_ALL_TEMPLATES_REQUEST, channel, queryParams: { page: 1, archiveStatus: archiveFilter } });
|
|
266
|
+
} catch (error) {
|
|
267
|
+
yield put({ type: types.BULK_UNARCHIVE_FAILURE, error });
|
|
268
|
+
CapNotification.error({ message: 'Failed to unarchive templates' });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function* watchArchiveTemplate() {
|
|
273
|
+
yield takeLatest(types.ARCHIVE_TEMPLATE_REQUEST, archiveTemplateSaga);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export function* watchUnarchiveTemplate() {
|
|
277
|
+
yield takeLatest(types.UNARCHIVE_TEMPLATE_REQUEST, unarchiveTemplateSaga);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function* watchBulkArchive() {
|
|
281
|
+
yield takeLatest(types.BULK_ARCHIVE_REQUEST, bulkArchiveTemplatesSaga);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function* watchBulkUnarchive() {
|
|
285
|
+
yield takeLatest(types.BULK_UNARCHIVE_REQUEST, bulkUnarchiveTemplatesSaga);
|
|
286
|
+
}
|
|
287
|
+
|
|
204
288
|
export function* watchGetAllTemplates() {
|
|
205
289
|
yield takeLatest(types.GET_ALL_TEMPLATES_REQUEST, getAllTemplates);
|
|
206
290
|
}
|
|
@@ -283,6 +367,10 @@ export function* v2TemplateSaga() {
|
|
|
283
367
|
watchFetchWeCrmAccounts(),
|
|
284
368
|
watchGetSenderDetails(),
|
|
285
369
|
watchForGetTemplateInfoById(), // Zalo preview functionality from Templates component
|
|
370
|
+
watchArchiveTemplate(),
|
|
371
|
+
watchUnarchiveTemplate(),
|
|
372
|
+
watchBulkArchive(),
|
|
373
|
+
watchBulkUnarchive(),
|
|
286
374
|
]);
|
|
287
375
|
}
|
|
288
376
|
|
|
@@ -72,6 +72,16 @@ const selectBEEEditor = () => createSelector(makeSelectTemplates(), (templates)
|
|
|
72
72
|
return BEETemplate || null;
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
+
const selectArchiveFilter = () => createSelector(
|
|
76
|
+
makeSelectTemplates(),
|
|
77
|
+
(substate) => substate.archiveFilter || 'active',
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const selectSelectedTemplateIds = () => createSelector(
|
|
81
|
+
makeSelectTemplates(),
|
|
82
|
+
(substate) => substate.selectedTemplateIds || [],
|
|
83
|
+
);
|
|
84
|
+
|
|
75
85
|
export {
|
|
76
86
|
uploadSelector,
|
|
77
87
|
templateUserList,
|
|
@@ -83,4 +93,6 @@ export {
|
|
|
83
93
|
selectEdmEditor,
|
|
84
94
|
selectBEEEditor,
|
|
85
95
|
selectCmsTemplatesLoader,
|
|
96
|
+
selectArchiveFilter,
|
|
97
|
+
selectSelectedTemplateIds,
|
|
86
98
|
};
|
|
@@ -320,4 +320,16 @@ describe('ChannelTypeIllustration', () => {
|
|
|
320
320
|
}).not.toThrow();
|
|
321
321
|
});
|
|
322
322
|
});
|
|
323
|
+
|
|
324
|
+
describe('isArchivedMode', () => {
|
|
325
|
+
it('should render CapIllustration when isArchivedMode is true', () => {
|
|
326
|
+
const wrapper = renderComponent({ isArchivedMode: true });
|
|
327
|
+
expect(wrapper.find('CapIllustration').exists()).toBe(true);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('should render CapIllustration when isArchivedMode is false', () => {
|
|
331
|
+
const wrapper = renderComponent({ isArchivedMode: false, currentChannel: SMS });
|
|
332
|
+
expect(wrapper.find('CapIllustration').exists()).toBe(true);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
323
335
|
});
|