Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / actions / creators / trash.ts
blob98224fbb502dfbb2cf7ea973874571207985fffb
1 import { createAction } from '@reduxjs/toolkit';
2 import { c } from 'ttag';
4 import { withCache } from '@proton/pass/store/actions/enhancers/cache';
5 import { withNotification } from '@proton/pass/store/actions/enhancers/notification';
6 import { trashEmptyRequest, trashRestoreRequest } from '@proton/pass/store/actions/requests';
7 import {
8     withRequest,
9     withRequestFailure,
10     withRequestProgress,
11     withRequestSuccess,
12 } from '@proton/pass/store/request/enhancers';
13 import type { BatchItemRevisionIDs } from '@proton/pass/types';
14 import { pipe } from '@proton/pass/utils/fp/pipe';
16 export const emptyTrashIntent = createAction('trash::empty::intent', () =>
17     pipe(
18         withRequest({ status: 'start', id: trashEmptyRequest() }),
19         withNotification({
20             type: 'info',
21             text: c('Info').t`Emptying trash...`,
22             loading: true,
23             expiration: -1,
24         })
25     )({ payload: {} })
28 export const emptyTrashFailure = createAction(
29     'trash::empty::failure',
30     withRequestFailure((error: unknown) =>
31         withNotification({
32             type: 'error',
33             text: c('Error').t`Emptying trash failed`,
34             error,
35         })({ payload: {}, error })
36     )
39 export const emptyTrashProgress = createAction(
40     'trash::empty::progress',
41     withRequestProgress((payload: BatchItemRevisionIDs) => withCache({ payload }))
44 export const emptyTrashSuccess = createAction(
45     'trash::empty::success',
46     withRequestSuccess(() =>
47         pipe(
48             withNotification({
49                 type: 'success',
50                 text: c('Info').t`All trashed items permanently deleted`,
51             })
52         )({ payload: {} })
53     )
56 export const restoreTrashIntent = createAction('trash::restore::intent', () =>
57     pipe(
58         withRequest({ status: 'start', id: trashRestoreRequest() }),
59         withNotification({
60             type: 'info',
61             text: c('Info').t`Restoring trashed items...`,
62             loading: true,
63             expiration: -1,
64         })
65     )({ payload: {} })
68 export const restoreTrashFailure = createAction(
69     'trash::restore::failure',
70     withRequestFailure((error: unknown) =>
71         withNotification({
72             type: 'error',
73             text: c('Error').t`Restoring trashed items failed`,
74             error,
75         })({ payload: {}, error })
76     )
79 export const restoreTrashProgress = createAction(
80     'trash::restore::progress',
81     withRequestProgress((payload: BatchItemRevisionIDs) => withCache({ payload }))
84 export const restoreTrashSuccess = createAction(
85     'trash::restore::success',
86     withRequestSuccess(() =>
87         withNotification({
88             type: 'success',
89             text: c('Info').t`All trashed items successfully restored`,
90         })({ payload: {} })
91     )