1 import { put, select, takeEvery } from 'redux-saga/effects';
3 import { PassCrypto } from '@proton/pass/lib/crypto';
4 import { deleteVault } from '@proton/pass/lib/vaults/vault.requests';
10 } from '@proton/pass/store/actions';
11 import { withRevalidate } from '@proton/pass/store/request/enhancers';
12 import { selectUserDefaultShareID } from '@proton/pass/store/selectors';
13 import type { RootSagaOptions } from '@proton/pass/store/types';
14 import type { Maybe } from '@proton/pass/types';
16 function* deleteVaultWorker(
17 { onItemsUpdated, getAuthStore }: RootSagaOptions,
18 { payload: { shareId, content }, meta }: ReturnType<typeof vaultDeleteIntent>
21 yield deleteVault(shareId);
22 PassCrypto.removeShare(shareId);
24 /* Handle edge case when the alias sync vault is deleted:
25 * we check the new alias sync vault from BE in the user access route */
26 const userID = getAuthStore().getUserID();
27 const aliasSyncShareId: Maybe<string> = yield select(selectUserDefaultShareID);
28 if (shareId === aliasSyncShareId) yield put(withRevalidate(getUserAccessIntent(userID!)));
30 yield put(vaultDeleteSuccess(meta.request.id, { shareId, content }));
33 yield put(vaultDeleteFailure(meta.request.id, { shareId, content }, e));
37 export default function* watcher(options: RootSagaOptions) {
38 yield takeEvery(vaultDeleteIntent.match, deleteVaultWorker, options);