Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / pass / store / selectors / alias.ts
blob4ee8da409abe9c7091ba58cc22eb2f49d050d0b4
1 import { createSelector } from '@reduxjs/toolkit';
3 import type { AliasDetailsState } from '@proton/pass/store/reducers';
4 import type { State } from '@proton/pass/store/types';
5 import type { Maybe } from '@proton/pass/types';
6 import type { AliasMailbox } from '@proton/pass/types/data/alias';
8 import { selectAliasItems } from './items';
10 export const selectAliasState = ({ alias }: State) => alias;
11 export const selectAliasOptions = ({ alias }: State) => alias.aliasOptions;
13 export const selectAliasDetails = (aliasEmail: string) =>
14     createSelector([selectAliasState], (alias): Maybe<AliasDetailsState> => alias.aliasDetails?.[aliasEmail]);
16 export const selectAliasMailboxes = (aliasEmail: string) =>
17     createSelector([selectAliasState], (alias): Maybe<AliasMailbox[]> => alias.aliasDetails?.[aliasEmail]?.mailboxes);
19 export const selectAliasByAliasEmail = (aliasEmail: string) =>
20     createSelector([selectAliasItems], (aliasItems) => aliasItems.find((item) => item.aliasEmail! === aliasEmail));
22 export const selectCanManageAlias = ({ user: { plan } }: State) => Boolean(plan?.ManageAlias);