1 import { createAction } from '@reduxjs/toolkit';
2 import { c } from 'ttag';
4 import { isVaultShare } from '@proton/pass/lib/shares/share.predicates';
5 import { withCache } from '@proton/pass/store/actions/enhancers/cache';
6 import { withNotification } from '@proton/pass/store/actions/enhancers/notification';
8 shareAccessOptionsRequest,
9 shareEditMemberRoleRequest,
11 shareRemoveMemberRequest,
12 } from '@proton/pass/store/actions/requests';
13 import { withRequest, withRequestFailure, withRequestSuccess } from '@proton/pass/store/request/enhancers';
14 import { requestActionsFactory } from '@proton/pass/store/request/flow';
15 import type { SynchronizationResult } from '@proton/pass/store/sagas/client/sync';
16 import type { SelectedShare, Share, ShareAccessKeys, ShareRole } from '@proton/pass/types';
19 ShareEditMemberAccessIntent,
20 ShareRemoveMemberAccessIntent,
21 } from '@proton/pass/types/data/shares.dto';
22 import { pipe } from '@proton/pass/utils/fp/pipe';
24 export const shareEditSync = createAction('share::edit:sync', (payload: { id: string; share: Share }) =>
25 withCache({ payload })
28 export const shareDeleteSync = createAction('share::delete::sync', (share: Share) =>
33 text: isVaultShare(share)
34 ? c('Info').t`Vault "${share.content.name}" was removed`
35 : c('Info').t`An item previously shared with you was removed`,
37 )({ payload: { shareId: share.shareId } })
40 export const sharesSync = createAction('shares::sync', (payload: SynchronizationResult) => withCache({ payload }));
42 export const shareRemoveMemberAccessIntent = createAction(
43 'share::member::remove-access::intent',
44 (payload: ShareRemoveMemberAccessIntent) =>
45 withRequest({ status: 'start', id: shareRemoveMemberRequest(payload.userShareId) })({ payload })
48 export const shareRemoveMemberAccessSuccess = createAction(
49 'share::member::remove-access::success',
50 withRequestSuccess((shareId: string, userShareId: string) =>
55 text: c('Info').t`User's access removed`,
57 )({ payload: { shareId, userShareId } })
61 export const shareRemoveMemberAccessFailure = createAction(
62 'share::member::remove-access::failure',
63 withRequestFailure((error: unknown) =>
66 text: c('Error').t`Failed to remove user's access.`,
72 export const shareEditMemberAccessIntent = createAction(
73 'share::member::edit-access::intent',
74 (payload: ShareEditMemberAccessIntent) =>
75 withRequest({ status: 'start', id: shareEditMemberRoleRequest(payload.userShareId) })({ payload })
78 export const shareEditMemberAccessSuccess = createAction(
79 'share::member::edit-access::success',
80 withRequestSuccess((shareId: string, userShareId: string, shareRoleId: ShareRole) =>
85 text: c('Info').t`User's access successfully updated`,
87 )({ payload: { shareId, userShareId, shareRoleId } })
91 export const shareEditMemberAccessFailure = createAction(
92 'share::member:edit-access::failure',
93 withRequestFailure((error: unknown) =>
96 text: c('Error').t`Failed to edit user's access.`,
102 export const shareLeaveIntent = createAction('share::leave::intent', (payload: { shareId: string }) =>
104 withRequest({ status: 'start', id: shareLeaveRequest(payload.shareId) }),
109 text: c('Info').t`Leaving vault...`,
114 export const shareLeaveSuccess = createAction(
115 'share::leave::success',
116 withRequestSuccess((shareId: string) =>
119 text: c('Info').t`Successfully left the vault`,
120 })({ payload: { shareId } })
124 export const shareLeaveFailure = createAction(
125 'share::leave::failure',
126 withRequestFailure((error: unknown) =>
129 text: c('Error').t`Could not leave vault.`,
131 })({ payload: {}, error })
135 export const getShareAccessOptions = requestActionsFactory<SelectedShare, ShareAccessOptions>('share::access-options')({
136 requestId: ({ shareId }) => shareAccessOptionsRequest(shareId),
137 success: { config: { maxAge: 15 } },
139 prepare: (error: unknown) =>
142 text: c('Error').t`Could not resolve share members`,
144 })({ payload: {}, error }),
148 export const shareAccessChange = createAction('share::access::change', (payload: Pick<Share, ShareAccessKeys>) =>
149 withCache({ payload })