1 import { createAction } from '@reduxjs/toolkit';
2 import { c } from 'ttag';
4 import { withCache } from '@proton/pass/store/actions/enhancers/cache';
5 import type { ActionCallback } from '@proton/pass/store/actions/enhancers/callback';
6 import { withCallback } from '@proton/pass/store/actions/enhancers/callback';
7 import { withNotification } from '@proton/pass/store/actions/enhancers/notification';
12 vaultMoveAllItemsRequest,
13 vaultTransferOwnerRequest,
14 } from '@proton/pass/store/actions/requests';
20 } from '@proton/pass/store/request/enhancers';
21 import type { BatchItemRevisions, ItemMoveDTO, ItemRevision, Share, ShareContent, ShareType } from '@proton/pass/types';
22 import type { VaultTransferOwnerIntent } from '@proton/pass/types/data/vault.dto';
23 import { pipe } from '@proton/pass/utils/fp/pipe';
24 import { uniqueId } from '@proton/pass/utils/string/unique-id';
26 export const vaultCreationIntent = createAction(
27 'vault::creation::intent',
30 payload: { content: ShareContent<ShareType.Vault> },
31 callback?: ActionCallback<ReturnType<typeof vaultCreationSuccess> | ReturnType<typeof vaultCreationFailure>>
32 ) => pipe(withRequest({ status: 'start', id: vaultCreateRequest(uniqueId()) }), withCallback(callback))({ payload })
35 export const vaultCreationFailure = createAction(
36 'vault::creation::failure',
37 withRequestFailure((payload: { content: ShareContent<ShareType.Vault> }, error: unknown) =>
40 text: c('Error').t`Vault "${payload.content.name}" creation failed`,
42 })({ payload, error })
46 /* This action will be intercepted by the events.saga to create
47 * the appropriate event loop channel upon successful creation */
48 export const vaultCreationSuccess = createAction(
49 'vault::creation::success',
51 (payload: { share: Share<ShareType.Vault> }) =>
56 text: c('Info').t`Vault "${payload.share.content.name}" successfully created`,
63 export const vaultEditIntent = createAction(
64 'vault::edit::intent',
65 (payload: { shareId: string; content: ShareContent<ShareType.Vault> }) =>
66 withRequest({ status: 'start', id: vaultEditRequest(payload.shareId) })({ payload })
69 export const vaultEditFailure = createAction(
70 'vault::edit::failure',
71 withRequestFailure((payload: { shareId: string; content: ShareContent<ShareType.Vault> }, error: unknown) =>
74 text: c('Error').t`Updating vault "${payload.content.name}" failed`,
76 })({ payload, error })
80 export const vaultEditSuccess = createAction(
81 'vault::edit::success',
82 withRequestSuccess((payload: { share: Share<ShareType.Vault> }) =>
87 text: c('Info').t`Vault "${payload.share.content.name}" successfully updated`,
93 export const vaultDeleteIntent = createAction(
94 'vault::delete::intent',
96 (payload: { shareId: string; content: ShareContent<ShareType.Vault> }) =>
98 withRequest({ status: 'start', id: vaultDeleteRequest(payload.shareId) }),
102 text: c('Info').t`Deleting "${payload.content.name}"`,
107 export const vaultDeleteFailure = createAction(
108 'vault::delete::failure',
109 withRequestFailure((payload: { shareId: string; content: ShareContent<ShareType.Vault> }, error: unknown) =>
112 text: c('Error').t`Deleting vault "${payload.content.name}" failed`,
114 })({ payload, error })
118 export const vaultDeleteSuccess = createAction(
119 'vault::delete::success',
120 withRequestSuccess((payload: { shareId: string; content: ShareContent<ShareType.Vault> }) =>
125 text: c('Info').t`Vault "${payload.content.name}" successfully deleted`,
131 export const vaultMoveAllItemsIntent = createAction(
132 'vault::move::items::intent',
133 (payload: { shareId: string; content: ShareContent<ShareType.Vault>; destinationShareId: string }) =>
135 withRequest({ status: 'start', id: vaultMoveAllItemsRequest(payload.shareId) }),
140 text: c('Info').t`Moving all items from "${payload.content.name}"`,
145 export const vaultMoveAllItemsProgress = createAction(
146 'vault::move::items::progress',
147 withRequestProgress((payload: BatchItemRevisions & { movedItems: ItemRevision[]; destinationShareId: string }) =>
148 withCache({ payload })
152 export const vaultMoveAllItemsSuccess = createAction(
153 'vault::move::items::success',
154 withRequestSuccess((payload: { content: ShareContent<ShareType.Vault> }) =>
157 text: c('Info').t`All items from "${payload.content.name}" successfully moved`,
162 export const vaultMoveAllItemsFailure = createAction(
163 'vault::move::items::failure',
164 withRequestFailure((payload: { shareId: string; content: ShareContent<ShareType.Vault> }, error: unknown) =>
167 text: c('Error').t`Failed to move all items from "${payload.content.name}"`,
169 })({ payload, error })
173 export const vaultTransferOwnerIntent = createAction(
174 'vault::ownership::transfer::intent',
175 (payload: VaultTransferOwnerIntent) =>
176 withRequest({ status: 'start', id: vaultTransferOwnerRequest(payload.userShareId) })({ payload })
179 export const vaultTransferOwnershipSuccess = createAction(
180 'vault::ownership::transfer::success',
181 withRequestSuccess((shareId: string, userShareId: string) =>
186 text: c('Info').t`Ownership successfully transfered. You are no long the owner of this vault.`,
188 )({ payload: { shareId, userShareId } })
192 export const vaultTransferOwnershipFailure = createAction(
193 'vault::ownership::transfer::failure',
194 withRequestFailure((error: unknown) =>
197 text: c('Error').t`Failed to transfer this vault's ownership.`,
203 export const sharedVaultCreated = createAction(
204 'vault::shared::created',
205 (payload: { share: Share<ShareType.Vault>; move?: ItemMoveDTO }) => withCache({ payload })