1 import type { Reducer } from 'redux';
5 getAliasDetailsSuccess,
6 getAliasOptionsSuccess,
9 } from '@proton/pass/store/actions';
10 import type { AliasDetails, Maybe, MaybeNull } from '@proton/pass/types';
11 import type { AliasOptions } from '@proton/pass/types/data/alias';
12 import { merge } from '@proton/pass/utils/object/merge';
14 export type AliasDetailsState = Maybe<Omit<AliasDetails, 'aliasEmail'>>;
16 export type AliasState = {
17 aliasOptions: MaybeNull<AliasOptions>;
18 aliasDetails: { [aliasEmail: string]: AliasDetailsState };
21 const getInitialState = (): AliasState => ({ aliasOptions: null, aliasDetails: {} });
23 const reducer: Reducer<AliasState> = (state = getInitialState(), action) => {
24 if (getAliasOptionsSuccess.match(action)) {
25 return merge(state, { aliasOptions: { ...action.payload.options } });
28 if (itemCreationIntent.match(action) && action.payload.type === 'alias') {
31 extraData: { mailboxes, aliasEmail },
37 [aliasEmail]: { mailboxes },
42 if (getAliasDetailsSuccess.match(action) || aliasDetailsSync.match(action)) {
44 payload: { aliasEmail, ...aliasDetails },
47 return merge(state, { aliasDetails: { [aliasEmail]: aliasDetails } });
51 itemEditIntent.match(action) &&
52 action.payload.type === 'alias' &&
53 action.payload.extraData &&
54 action.payload.extraData.aliasOwner
57 extraData: { mailboxes, aliasEmail },
59 return merge(state, { aliasDetails: { [aliasEmail]: { mailboxes } } });
65 export default reducer;