@capillarytech/creatives-library 8.0.345-alpha.12 → 8.0.345-alpha.13

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.
Files changed (138) hide show
  1. package/constants/unified.js +0 -29
  2. package/package.json +1 -1
  3. package/services/api.js +20 -0
  4. package/services/tests/api.test.js +59 -13
  5. package/utils/commonUtils.js +1 -19
  6. package/v2Components/CapActionButton/constants.js +0 -7
  7. package/v2Components/CapActionButton/index.js +109 -167
  8. package/v2Components/CapActionButton/index.scss +6 -157
  9. package/v2Components/CapActionButton/messages.js +3 -19
  10. package/v2Components/CapActionButton/tests/index.test.js +17 -41
  11. package/v2Components/CapCustomSkeleton/index.js +1 -1
  12. package/v2Components/CapCustomSkeleton/tests/__snapshots__/index.test.js.snap +12 -12
  13. package/v2Components/CapTagList/index.js +0 -10
  14. package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +49 -70
  15. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +2 -8
  16. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +21 -207
  17. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +0 -16
  18. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +10 -85
  19. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +0 -30
  20. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +11 -79
  21. package/v2Components/CommonTestAndPreview/SendTestMessage.js +5 -10
  22. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +15 -160
  23. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +76 -341
  24. package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +4 -133
  25. package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +0 -11
  26. package/v2Components/CommonTestAndPreview/constants.js +2 -38
  27. package/v2Components/CommonTestAndPreview/index.js +186 -676
  28. package/v2Components/CommonTestAndPreview/messages.js +3 -49
  29. package/v2Components/CommonTestAndPreview/sagas.js +6 -15
  30. package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +284 -308
  31. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +65 -231
  32. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +5 -118
  33. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +0 -341
  34. package/v2Components/CommonTestAndPreview/tests/PreviewSection.test.js +1 -8
  35. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +13 -34
  36. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/RcsPreviewContent.test.js +283 -281
  37. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +1 -199
  38. package/v2Components/CommonTestAndPreview/tests/index.test.js +4 -132
  39. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +2 -2
  40. package/v2Components/FormBuilder/index.js +10 -8
  41. package/v2Components/TemplatePreview/_templatePreview.scss +23 -33
  42. package/v2Components/TemplatePreview/index.js +28 -143
  43. package/v2Components/TemplatePreview/tests/index.test.js +0 -142
  44. package/v2Components/TestAndPreviewSlidebox/index.js +1 -13
  45. package/v2Components/TestAndPreviewSlidebox/sagas.js +4 -11
  46. package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +1 -3
  47. package/v2Containers/Assets/images/archive_Empty_Illustration.svg +9 -0
  48. package/v2Containers/CreativesContainer/SlideBoxContent.js +4 -36
  49. package/v2Containers/CreativesContainer/SlideBoxFooter.js +4 -11
  50. package/v2Containers/CreativesContainer/SlideBoxHeader.js +4 -29
  51. package/v2Containers/CreativesContainer/constants.js +0 -9
  52. package/v2Containers/CreativesContainer/index.js +108 -300
  53. package/v2Containers/CreativesContainer/index.scss +1 -51
  54. package/v2Containers/CreativesContainer/messages.js +4 -0
  55. package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +34 -78
  56. package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +16 -79
  57. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +0 -8
  58. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +98 -357
  59. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +18 -20
  60. package/v2Containers/CreativesContainer/tests/index.test.js +9 -71
  61. package/v2Containers/Rcs/constants.js +8 -119
  62. package/v2Containers/Rcs/index.js +812 -2375
  63. package/v2Containers/Rcs/index.scss +6 -276
  64. package/v2Containers/Rcs/messages.js +3 -38
  65. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +70345 -98302
  66. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +5 -0
  67. package/v2Containers/Rcs/tests/index.test.js +121 -152
  68. package/v2Containers/Rcs/tests/mockData.js +0 -38
  69. package/v2Containers/Rcs/tests/utils.test.js +30 -646
  70. package/v2Containers/Rcs/utils.js +11 -478
  71. package/v2Containers/Sms/Create/index.js +40 -100
  72. package/v2Containers/SmsTrai/Create/index.js +4 -9
  73. package/v2Containers/SmsTrai/Edit/constants.js +0 -2
  74. package/v2Containers/SmsTrai/Edit/index.js +130 -636
  75. package/v2Containers/SmsTrai/Edit/messages.js +4 -14
  76. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +2296 -4249
  77. package/v2Containers/SmsWrapper/index.js +8 -37
  78. package/v2Containers/TagList/index.js +0 -6
  79. package/v2Containers/Templates/ChannelTypeIllustration.js +23 -6
  80. package/v2Containers/Templates/_templates.scss +126 -181
  81. package/v2Containers/Templates/actions.js +36 -11
  82. package/v2Containers/Templates/constants.js +23 -2
  83. package/v2Containers/Templates/index.js +333 -142
  84. package/v2Containers/Templates/messages.js +68 -0
  85. package/v2Containers/Templates/reducer.js +68 -0
  86. package/v2Containers/Templates/sagas.js +98 -55
  87. package/v2Containers/Templates/selectors.js +12 -0
  88. package/v2Containers/Templates/tests/ChannelTypeIllustration.test.js +12 -0
  89. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1256 -1042
  90. package/v2Containers/Templates/tests/index.test.js +6 -0
  91. package/v2Containers/Templates/tests/reducer.test.js +178 -0
  92. package/v2Containers/Templates/tests/sagas.test.js +436 -200
  93. package/v2Containers/Templates/tests/selector.test.js +32 -0
  94. package/v2Containers/TemplatesV2/TemplatesV2.style.js +1 -72
  95. package/v2Containers/TemplatesV2/index.js +23 -86
  96. package/v2Containers/Whatsapp/index.js +20 -3
  97. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +34 -578
  98. package/utils/rcsPayloadUtils.js +0 -92
  99. package/utils/templateVarUtils.js +0 -201
  100. package/utils/tests/templateVarUtils.test.js +0 -204
  101. package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js.rej +0 -18
  102. package/v2Components/CommonTestAndPreview/previewApiUtils.js +0 -59
  103. package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +0 -67
  104. package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +0 -87
  105. package/v2Components/SmsFallback/constants.js +0 -73
  106. package/v2Components/SmsFallback/index.js +0 -955
  107. package/v2Components/SmsFallback/index.scss +0 -265
  108. package/v2Components/SmsFallback/messages.js +0 -78
  109. package/v2Components/SmsFallback/smsFallbackUtils.js +0 -118
  110. package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +0 -50
  111. package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +0 -147
  112. package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +0 -304
  113. package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +0 -197
  114. package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +0 -277
  115. package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +0 -422
  116. package/v2Components/SmsFallback/useLocalTemplateList.js +0 -92
  117. package/v2Components/TemplatePreview/constants.js +0 -2
  118. package/v2Components/VarSegmentMessageEditor/constants.js +0 -2
  119. package/v2Components/VarSegmentMessageEditor/index.js +0 -125
  120. package/v2Components/VarSegmentMessageEditor/index.scss +0 -46
  121. package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +0 -43
  122. package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +0 -67
  123. package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +0 -90
  124. package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +0 -258
  125. package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +0 -125
  126. package/v2Containers/Rcs/index.js.rej +0 -1336
  127. package/v2Containers/Rcs/index.scss.rej +0 -74
  128. package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +0 -225
  129. package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap.rej +0 -128
  130. package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +0 -318
  131. package/v2Containers/Sms/smsFormDataHelpers.js +0 -67
  132. package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +0 -253
  133. package/v2Containers/SmsTrai/Edit/index.scss +0 -121
  134. package/v2Containers/Templates/TemplatesActionBar.js +0 -101
  135. package/v2Containers/Templates/tests/TemplatesActionBar.test.js +0 -120
  136. package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +0 -180
  137. package/v2Containers/Templates/utils/smsTemplatesListApi.js +0 -79
  138. package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +0 -131
@@ -618,4 +618,72 @@ export default defineMessages({
618
618
  id: `${scope}.templateUpdateSuccess`,
619
619
  defaultMessage: 'Template updated successfully',
620
620
  },
621
+ "archiveTemplates": {
622
+ id: `${scope}.archiveTemplates`,
623
+ defaultMessage: 'Archive templates',
624
+ },
625
+ "archiveTemplateContent": {
626
+ id: `${scope}.archiveTemplateContent`,
627
+ defaultMessage: 'These templates will be archived and unavailable for use. You can restore them anytime.',
628
+ },
629
+ "archiveTemplateSingleContent": {
630
+ id: `${scope}.archiveTemplateSingleContent`,
631
+ defaultMessage: 'This template will be archived and unavailable for use. You can restore it anytime.',
632
+ },
633
+ "unarchiveTemplates": {
634
+ id: `${scope}.unarchiveTemplates`,
635
+ defaultMessage: 'Unarchive templates',
636
+ },
637
+ "unarchiveTemplateContent": {
638
+ id: `${scope}.unarchiveTemplateContent`,
639
+ defaultMessage: 'These templates will be unarchived and available for use again.',
640
+ },
641
+ "unarchiveTemplateSingleContent": {
642
+ id: `${scope}.unarchiveTemplateSingleContent`,
643
+ defaultMessage: 'This template will be unarchived and available for use again.',
644
+ },
645
+ "archiveConfirmOk": {
646
+ id: `${scope}.archiveConfirmOk`,
647
+ defaultMessage: 'Confirm',
648
+ },
649
+ "archiveConfirmCancel": {
650
+ id: `${scope}.archiveConfirmCancel`,
651
+ defaultMessage: 'Cancel',
652
+ },
653
+ "archiveButton": {
654
+ id: `${scope}.archiveButton`,
655
+ defaultMessage: 'Archive',
656
+ },
657
+ "unarchiveButton": {
658
+ id: `${scope}.unarchiveButton`,
659
+ defaultMessage: 'Unarchive',
660
+ },
661
+ "archivedTag": {
662
+ id: `${scope}.archivedTag`,
663
+ defaultMessage: 'Archived',
664
+ },
665
+ "archivedTemplates": {
666
+ id: `${scope}.archivedTemplates`,
667
+ defaultMessage: 'Archived templates',
668
+ },
669
+ "searchArchivedTemplates": {
670
+ id: `${scope}.searchArchivedTemplates`,
671
+ defaultMessage: 'Search archived templates...',
672
+ },
673
+ "templatesSelected": {
674
+ id: `${scope}.templatesSelected`,
675
+ defaultMessage: '{count} {count, plural, one {template} other {templates}} selected',
676
+ },
677
+ "cannotEditArchivedTemplate": {
678
+ id: `${scope}.cannotEditArchivedTemplate`,
679
+ defaultMessage: 'Cannot edit an archived template. Please unarchive it first.',
680
+ },
681
+ "noArchivedCreatives": {
682
+ id: `${scope}.noArchivedCreatives`,
683
+ defaultMessage: 'No archived creatives',
684
+ },
685
+ "noArchivedCreativesDesc": {
686
+ id: `${scope}.noArchivedCreativesDesc`,
687
+ defaultMessage: 'Creatives you archive will appear here',
688
+ },
621
689
  });
@@ -26,6 +26,13 @@ export const initialState = fromJS({
26
26
  reportsSettings: {},
27
27
  },
28
28
  senderDetails: {},
29
+ archiveFilter: 'active',
30
+ isArchivedMode: false,
31
+ selectedTemplateIds: fromJS([]),
32
+ archiveInProgress: false,
33
+ unarchiveInProgress: false,
34
+ bulkArchiveInProgress: false,
35
+ bulkUnarchiveInProgress: false,
29
36
  });
30
37
 
31
38
  function templatesReducer(state = initialState, action) {
@@ -231,6 +238,67 @@ function templatesReducer(state = initialState, action) {
231
238
  hostName: '',
232
239
  errors: action.payload,
233
240
  });
241
+ case types.SET_ARCHIVE_FILTER:
242
+ return state
243
+ .set('archiveFilter', action.filter)
244
+ .set('templates', [])
245
+ .set('selectedTemplateIds', fromJS([]));
246
+ case types.SET_ARCHIVED_MODE:
247
+ return state
248
+ .set('isArchivedMode', action.isArchived)
249
+ .set('archiveFilter', action.isArchived ? 'archived' : 'active')
250
+ .set('templates', [])
251
+ .set('selectedTemplateIds', fromJS([]));
252
+ case types.TOGGLE_TEMPLATE_SELECTION: {
253
+ const rawSelected = state.get('selectedTemplateIds');
254
+ // Defensive: handle undefined (stale persisted state) or plain array (pre-fromJS migration)
255
+ const currentSelected = rawSelected && typeof rawSelected.toJS === 'function'
256
+ ? rawSelected.toJS()
257
+ : (Array.isArray(rawSelected) ? rawSelected : []);
258
+ const idx = currentSelected.indexOf(action.id);
259
+ const newSelected = idx === -1
260
+ ? [...currentSelected, action.id]
261
+ : currentSelected.filter((id) => id !== action.id);
262
+ return state.set('selectedTemplateIds', fromJS(newSelected));
263
+ }
264
+ case types.SELECT_ALL_TEMPLATES:
265
+ return state.set('selectedTemplateIds', fromJS(action.ids));
266
+ case types.CLEAR_TEMPLATE_SELECTION:
267
+ return state.set('selectedTemplateIds', fromJS([]));
268
+ case types.ARCHIVE_TEMPLATE_REQUEST:
269
+ return state.set('archiveInProgress', true);
270
+ case types.ARCHIVE_TEMPLATE_SUCCESS: {
271
+ const afterArchive = state.get('selectedTemplateIds');
272
+ const archiveSelected = afterArchive && typeof afterArchive.toJS === 'function' ? afterArchive.toJS() : [];
273
+ return state
274
+ .set('archiveInProgress', false)
275
+ .set('selectedTemplateIds', fromJS(archiveSelected.filter((sid) => sid !== action.id)));
276
+ }
277
+ case types.ARCHIVE_TEMPLATE_FAILURE:
278
+ return state.set('archiveInProgress', false);
279
+ case types.UNARCHIVE_TEMPLATE_REQUEST:
280
+ return state.set('unarchiveInProgress', true);
281
+ case types.UNARCHIVE_TEMPLATE_SUCCESS: {
282
+ const afterUnarchive = state.get('selectedTemplateIds');
283
+ const unarchiveSelected = afterUnarchive && typeof afterUnarchive.toJS === 'function' ? afterUnarchive.toJS() : [];
284
+ return state
285
+ .set('unarchiveInProgress', false)
286
+ .set('selectedTemplateIds', fromJS(unarchiveSelected.filter((sid) => sid !== action.id)));
287
+ }
288
+ case types.UNARCHIVE_TEMPLATE_FAILURE:
289
+ return state.set('unarchiveInProgress', false);
290
+ case types.BULK_ARCHIVE_REQUEST:
291
+ return state.set('bulkArchiveInProgress', true);
292
+ case types.BULK_ARCHIVE_SUCCESS:
293
+ return state.set('bulkArchiveInProgress', false).set('selectedTemplateIds', fromJS([]));
294
+ case types.BULK_ARCHIVE_FAILURE:
295
+ return state.set('bulkArchiveInProgress', false);
296
+ case types.BULK_UNARCHIVE_REQUEST:
297
+ return state.set('bulkUnarchiveInProgress', true);
298
+ case types.BULK_UNARCHIVE_SUCCESS:
299
+ return state.set('bulkUnarchiveInProgress', false).set('selectedTemplateIds', fromJS([]));
300
+ case types.BULK_UNARCHIVE_FAILURE:
301
+ return state.set('bulkUnarchiveInProgress', false);
234
302
  default:
235
303
  return state;
236
304
  }
@@ -1,75 +1,51 @@
1
+ import React from 'react';
1
2
  import {
2
- call, put, takeLatest, takeEvery, 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';
8
10
  import { saveCdnConfigs, removeAllCdnLocalStorageItems } from '../../utils/cdnTransformation';
9
11
  import { COPY_OF } from '../../constants/unified';
10
- import { fetchSmsTemplatesFromQuery } from './utils/smsTemplatesListApi';
11
12
  import { ZALO_TEMPLATE_INFO_REQUEST } from '../Zalo/constants';
12
13
  import { getTemplateInfoById } from '../Zalo/saga';
13
14
 
14
- export function* getLocalSmsTemplates(action) {
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
+
26
+ // Individual exports for testing
27
+ export function* getAllTemplates(channel, queryParams) {
15
28
  try {
16
- const fetched = yield call(
17
- fetchSmsTemplatesFromQuery,
18
- action.queryParams,
19
- action.intlCopyOf,
20
- );
21
- if (typeof action.onSuccess === 'function') {
22
- yield call(action.onSuccess, fetched);
23
- }
24
- } catch (error) {
25
- if (typeof action.onFailure === 'function') {
26
- yield call(action.onFailure, error);
27
- }
28
- }
29
- }
30
-
31
- export function* getAllTemplates(action) {
32
- try {
33
- if (action.channel && String(action.channel).toLowerCase() === 'sms') {
34
- const fetched = yield call(
35
- fetchSmsTemplatesFromQuery,
36
- action.queryParams,
37
- action.intlCopyOf,
38
- );
39
- yield put({
40
- type: types.GET_ALL_TEMPLATES_SUCCESS,
41
- data: fetched.channelTemplates,
42
- weCRMTemplate: fetched.weCRMTemplate,
43
- isReset: get(action, 'queryParams.page') === 1,
44
- });
45
- return;
46
- }
47
-
48
- const result = yield call(Api.getAllTemplates, action);
49
- const channelTemplates = (action.channel === 'wechat')
50
- ? { templates: [...result.response.mapped, ...result.response.richmedia] }
51
- : result.response;
52
- if (action.channel === 'wechat' && action.queryParams && action.queryParams.sortBy && action.queryParams.sortBy.toLocaleLowerCase() === ("Most Recent").toLocaleLowerCase()) {
29
+ const result = yield call(Api.getAllTemplates, channel, queryParams);
30
+ const channelTemplates = (channel.channel === 'wechat') ? { templates: [...result.response.mapped, ...result.response.richmedia] } : result.response;
31
+ // const sidebar = result.response.sidebar;
32
+ if (channel.channel === 'wechat' && channel.queryParams && channel.queryParams.sortBy && channel.queryParams.sortBy.toLocaleLowerCase() === ("Most Recent").toLocaleLowerCase()) {
53
33
  channelTemplates.templates.sort((a, b) => {
54
34
  const dateA = new Date(a.updatedAt);
55
35
  const dateB = new Date(b.updatedAt);
56
36
  return dateB - dateA;
57
37
  });
58
- } else if (action.channel === 'wechat' && action.queryParams && action.queryParams.sortBy && action.queryParams.sortBy.toLocaleLowerCase() === ("Alphabetically").toLocaleLowerCase()) {
38
+ } else if (channel.channel === 'wechat' && channel.queryParams && channel.queryParams.sortBy && channel.queryParams.sortBy.toLocaleLowerCase() === ("Alphabetically").toLocaleLowerCase()) {
59
39
  channelTemplates.templates.sort((a, b) => b.name - a.name);
60
40
  }
61
- if (action.intlCopyOf && channelTemplates?.templates) {
41
+ // Update the "name" property in each template
42
+ if (channel.intlCopyOf && channelTemplates?.templates) {
62
43
  channelTemplates.templates = channelTemplates.templates.map((template) => ({
63
44
  ...template,
64
- name: template.name.replace(new RegExp(COPY_OF, 'g'), action.intlCopyOf),
45
+ name: template.name.replace(new RegExp(COPY_OF, 'g'), channel.intlCopyOf),
65
46
  }));
66
47
  }
67
- yield put({
68
- type: types.GET_ALL_TEMPLATES_SUCCESS,
69
- data: channelTemplates,
70
- weCRMTemplate: result.response.unMapped,
71
- isReset: get(action, 'queryParams.page') === 1,
72
- });
48
+ yield put({ type: types.GET_ALL_TEMPLATES_SUCCESS, data: channelTemplates, weCRMTemplate: result.response.unMapped, isReset: channel.queryParams.page === 1 });
73
49
  } catch (error) {
74
50
  yield put({ type: types.GET_ALL_TEMPLATES_FAILURE, error });
75
51
  }
@@ -239,13 +215,78 @@ export function* getSenderDetails({
239
215
  }
240
216
  }
241
217
 
242
- export function* watchGetAllTemplates() {
243
- yield takeLatest(types.GET_ALL_TEMPLATES_REQUEST, getAllTemplates);
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);
244
274
  }
245
275
 
276
+ export function* watchUnarchiveTemplate() {
277
+ yield takeLatest(types.UNARCHIVE_TEMPLATE_REQUEST, unarchiveTemplateSaga);
278
+ }
246
279
 
247
- export function* watchGetLocalSmsTemplates() {
248
- yield takeEvery(types.GET_LOCAL_SMS_TEMPLATES_REQUEST, getLocalSmsTemplates);
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
+
288
+ export function* watchGetAllTemplates() {
289
+ yield takeLatest(types.GET_ALL_TEMPLATES_REQUEST, getAllTemplates);
249
290
  }
250
291
 
251
292
  export function* watchDeleteTemplate() {
@@ -301,7 +342,6 @@ export function* watchForGetTemplateInfoById() {
301
342
  // All sagas to be loaded
302
343
  export default [
303
344
  watchGetAllTemplates,
304
- watchGetLocalSmsTemplates,
305
345
  watchDeleteTemplate,
306
346
  watchDeleteRcsTemplate,
307
347
  watchGetUserList,
@@ -318,7 +358,6 @@ export default [
318
358
  export function* v2TemplateSaga() {
319
359
  yield all([
320
360
  watchGetAllTemplates(),
321
- watchGetLocalSmsTemplates(),
322
361
  watchDeleteTemplate(),
323
362
  watchDeleteRcsTemplate(),
324
363
  watchGetUserList(),
@@ -328,6 +367,10 @@ export function* v2TemplateSaga() {
328
367
  watchFetchWeCrmAccounts(),
329
368
  watchGetSenderDetails(),
330
369
  watchForGetTemplateInfoById(), // Zalo preview functionality from Templates component
370
+ watchArchiveTemplate(),
371
+ watchUnarchiveTemplate(),
372
+ watchBulkArchive(),
373
+ watchBulkUnarchive(),
331
374
  ]);
332
375
  }
333
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
  });