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>>
12 const { item, shareId } = payload;
13 const { callback: onItemTrashProcessed } = meta;
16 yield trashItems([item]);
17 const itemTrashSuccessAction = itemTrashSuccess({ itemId: item.itemId, shareId });
18 yield put(itemTrashSuccessAction);
20 onItemTrashProcessed?.(itemTrashSuccessAction);
23 const itemTrashFailureAction = itemTrashFailure({ itemId: item.itemId, shareId }, e);
24 yield put(itemTrashFailureAction);
26 onItemTrashProcessed?.(itemTrashFailureAction);
30 export default function* watcher(options: RootSagaOptions) {
31 yield takeEvery(itemTrashIntent.match, trashItemWorker, options);