Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / pass / store / selectors / invites.ts
blobe73a0795af9cbf18d30520a0ed46541808df43d8
1 import { createSelector } from '@reduxjs/toolkit';
3 import type { InviteState } from '@proton/pass/store/reducers';
4 import type { State } from '@proton/pass/store/types';
5 import type { Invite, Maybe, MaybeNull } from '@proton/pass/types';
6 import { first } from '@proton/pass/utils/array/first';
7 import { sortOn } from '@proton/pass/utils/fp/sort';
9 export const selectInvites = (state: State): InviteState => state.invites;
11 export const selectInviteByToken =
12     (token: string) =>
13     (state: State): Maybe<Invite> =>
14         state.invites[token];
16 export const selectMostRecentInvite = createSelector(
17     [selectInvites],
18     (invites): MaybeNull<Invite> => first(Object.values(invites).sort(sortOn('createTime', 'DESC'))) ?? null