1 import { put, takeLatest } from 'redux-saga/effects';
3 import { restoreItems } from '@proton/pass/lib/items/item.requests';
4 import { itemRestoreFailure, itemRestoreIntent, itemRestoreSuccess } from '@proton/pass/store/actions';
5 import type { RootSagaOptions } from '@proton/pass/store/types';
7 function* restoreItem({ onItemsUpdated }: RootSagaOptions, { payload, meta }: ReturnType<typeof itemRestoreIntent>) {
8 const { item, shareId } = payload;
9 const { itemId } = item;
10 const { callback: onItemRestoreProcessed } = meta;
13 yield restoreItems([item]);
14 const itemRestoreSuccessAction = itemRestoreSuccess({ itemId, shareId });
15 yield put(itemRestoreSuccessAction);
17 onItemRestoreProcessed?.(itemRestoreSuccessAction);
20 const itemRestoreFailureAction = itemRestoreFailure({ itemId, shareId }, e);
21 yield put(itemRestoreFailureAction);
22 onItemRestoreProcessed?.(itemRestoreFailureAction);
26 export default function* watcher(options: RootSagaOptions) {
27 yield takeLatest(itemRestoreIntent, restoreItem, options);