Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / sagas / items / item-restore.saga.ts
blobe616c377392786b267c34691ba0d3f870925b721
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;
12     try {
13         yield restoreItems([item]);
14         const itemRestoreSuccessAction = itemRestoreSuccess({ itemId, shareId });
15         yield put(itemRestoreSuccessAction);
17         onItemRestoreProcessed?.(itemRestoreSuccessAction);
18         onItemsUpdated?.();
19     } catch (e) {
20         const itemRestoreFailureAction = itemRestoreFailure({ itemId, shareId }, e);
21         yield put(itemRestoreFailureAction);
22         onItemRestoreProcessed?.(itemRestoreFailureAction);
23     }
26 export default function* watcher(options: RootSagaOptions) {
27     yield takeLatest(itemRestoreIntent, restoreItem, options);