1 import type { Reducer } from 'redux';
5 getAliasDetailsSuccess,
6 getAliasOptionsSuccess,
9 } from '@proton/pass/store/actions';
10 import type { MaybeNull } from '@proton/pass/types';
11 import type { AliasMailbox, AliasOptions } from '@proton/pass/types/data/alias';
12 import { merge } from '@proton/pass/utils/object/merge';
14 export type AliasState = {
15 aliasOptions: MaybeNull<AliasOptions>;
16 aliasDetails: { [aliasEmail: string]: AliasMailbox[] };
19 const getInitialState = (): AliasState => ({ aliasOptions: null, aliasDetails: {} });
21 const reducer: Reducer<AliasState> = (state = getInitialState(), action) => {
22 if (getAliasOptionsSuccess.match(action)) {
23 return merge(state, { aliasOptions: { ...action.payload.options } });
26 if (itemCreationIntent.match(action) && action.payload.type === 'alias') {
29 extraData: { mailboxes, aliasEmail },
35 [aliasEmail]: mailboxes,
40 if (getAliasDetailsSuccess.match(action)) {
42 payload: { aliasEmail, mailboxes },
44 return merge(state, { aliasDetails: { [aliasEmail]: mailboxes } });
47 if (aliasDetailsSync.match(action)) {
49 payload: { aliasEmail, mailboxes },
51 return merge(state, { aliasDetails: { [aliasEmail]: mailboxes } });
55 itemEditIntent.match(action) &&
56 action.payload.type === 'alias' &&
57 action.payload.extraData &&
58 action.payload.extraData.aliasOwner
61 extraData: { mailboxes, aliasEmail },
63 return merge(state, { aliasDetails: { [aliasEmail]: mailboxes } });
69 export default reducer;