Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / sagas / items / item-trash.saga.ts
blobbc9e6a603fe6a884ee79adde121ed53e41ecf166
1 import { put, takeEvery } from 'redux-saga/effects';
3 import { trashItems } from '@proton/pass/lib/items/item.requests';
4 import { itemTrashFailure, itemTrashIntent, itemTrashSuccess } from '@proton/pass/store/actions';
5 import type { WithSenderAction } from '@proton/pass/store/actions/enhancers/endpoint';
6 import type { RootSagaOptions } from '@proton/pass/store/types';
8 function* trashItemWorker(
9     { onItemsUpdated }: RootSagaOptions,
10     { payload, meta }: WithSenderAction<ReturnType<typeof itemTrashIntent>>
11 ) {
12     const { item, shareId } = payload;
13     const { callback: onItemTrashProcessed } = meta;
15     try {
16         yield trashItems([item]);
17         const itemTrashSuccessAction = itemTrashSuccess({ itemId: item.itemId, shareId });
18         yield put(itemTrashSuccessAction);
20         onItemTrashProcessed?.(itemTrashSuccessAction);
21         onItemsUpdated?.();
22     } catch (e) {
23         const itemTrashFailureAction = itemTrashFailure({ itemId: item.itemId, shareId }, e);
24         yield put(itemTrashFailureAction);
26         onItemTrashProcessed?.(itemTrashFailureAction);
27     }
30 export default function* watcher(options: RootSagaOptions) {
31     yield takeEvery(itemTrashIntent.match, trashItemWorker, options);