@capillarytech/creatives-library 8.0.345-alpha.9 → 8.0.345
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/CreativesContainer/SlideBoxContent.js +1 -20
- package/v2Containers/CreativesContainer/SlideBoxFooter.js +3 -1
- package/v2Containers/CreativesContainer/index.js +6 -4
- package/v2Containers/CreativesContainer/messages.js +4 -0
- package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +3 -0
- package/v2Containers/Email/index.js +0 -21
- package/v2Containers/Templates/ChannelTypeIllustration.js +23 -6
- package/v2Containers/Templates/_templates.scss +130 -24
- package/v2Containers/Templates/actions.js +36 -0
- package/v2Containers/Templates/constants.js +23 -0
- package/v2Containers/Templates/index.js +286 -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 +1300 -1122
- 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 +314 -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 className="notification-template-label">Template name </span>
|
|
20
|
+
<span className="notification-template-name">{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
|
+
const archiveFilter = yield select((state) => state.get('templates') ? state.get('templates').get('archiveFilter', 'active') : 'active');
|
|
223
|
+
yield call(getAllTemplates, { channel, queryParams: { page: 1, archiveStatus: archiveFilter } });
|
|
224
|
+
CapNotification.success({ message: 'Template archived successfully', description: templateNameDescription(templateName) });
|
|
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
|
+
const archiveFilter = yield select((state) => state.get('templates') ? state.get('templates').get('archiveFilter', 'active') : 'active');
|
|
236
|
+
yield call(getAllTemplates, { channel, queryParams: { page: 1, archiveStatus: archiveFilter } });
|
|
237
|
+
CapNotification.success({ message: 'Template unarchived successfully', description: templateNameDescription(templateName) });
|
|
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
|
+
const archiveFilter = yield select((state) => state.get('templates') ? state.get('templates').get('archiveFilter', 'active') : 'active');
|
|
250
|
+
yield call(getAllTemplates, { channel, queryParams: { page: 1, archiveStatus: archiveFilter } });
|
|
251
|
+
CapNotification.success({ message: `${count} templates archived successfully` });
|
|
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
|
+
const archiveFilter = yield select((state) => state.get('templates') ? state.get('templates').get('archiveFilter', 'active') : 'active');
|
|
264
|
+
yield call(getAllTemplates, { channel, queryParams: { page: 1, archiveStatus: archiveFilter } });
|
|
265
|
+
CapNotification.success({ message: `${count} templates unarchived successfully` });
|
|
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
|
});
|