Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / sagas / vaults / vault-creation.saga.ts
blob40009a12de1d53de11134e68ff5d39d91720118d
1 import { put, takeEvery } from 'redux-saga/effects';
3 import { createVault } from '@proton/pass/lib/vaults/vault.requests';
4 import { vaultCreationFailure, vaultCreationIntent, vaultCreationSuccess } from '@proton/pass/store/actions';
5 import type { ShareType } from '@proton/pass/types';
6 import { type Share } from '@proton/pass/types';
8 function* createVaultWorker({ payload, meta }: ReturnType<typeof vaultCreationIntent>) {
9     const { callback: onCreateVaultProcessed } = meta;
10     try {
11         const share: Share<ShareType.Vault> = yield createVault({ content: payload.content });
13         const vaultCreationSuccessAction = vaultCreationSuccess(meta.request.id, { share });
14         yield put(vaultCreationSuccessAction);
16         onCreateVaultProcessed?.(vaultCreationSuccessAction);
17     } catch (e) {
18         const vaultCreationFailureAction = vaultCreationFailure(meta.request.id, payload, e);
19         yield put(vaultCreationFailureAction);
21         onCreateVaultProcessed?.(vaultCreationFailureAction);
22     }
25 export default function* watcher() {
26     yield takeEvery(vaultCreationIntent.match, createVaultWorker);