Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / shared / lib / keys / memberHelper.ts
blobc2f68c7f192883ef73f212c9dfe9919e60bfcca4
1 import { MEMBER_STATE, type Member, MemberUnprivatizationState } from '../interfaces';
3 export const getHasMemberUnprivatization = (
4     member?: Member
5 ): member is Member & { Unprivatization: NonNullable<Member['Unprivatization']> } => {
6     return Boolean(member && member.Unprivatization);
7 };
9 export const getIsMemberSetup = (member?: Member): member is Member => {
10     return Boolean(member?.PublicKey);
13 export const getIsMemberInactive = (member?: Member): member is Member & { State: MEMBER_STATE.STATUS_DISABLED } => {
14     return member?.State === MEMBER_STATE.STATUS_DISABLED;
17 export enum MemberUnprivatizationMode {
18     None,
19     MagicLinkInvite,
20     GSSO,
21     AdminAccess,
24 export const getMemberUnprivatizationMode = (member?: Member) => {
25     if (getHasMemberUnprivatization(member)) {
26         return {
27             exists: true,
28             pending:
29                 member.Unprivatization.State === MemberUnprivatizationState.Pending ||
30                 member.Unprivatization.State === MemberUnprivatizationState.Ready,
31             mode: (() => {
32                 if (member.SSO) {
33                     return MemberUnprivatizationMode.GSSO;
34                 }
35                 const isMemberSetup = getIsMemberSetup(member);
36                 if (isMemberSetup) {
37                     return MemberUnprivatizationMode.AdminAccess;
38                 }
39                 return MemberUnprivatizationMode.MagicLinkInvite;
40             })(),
41         };
42     }
44     return {
45         exists: false,
46         mode: MemberUnprivatizationMode.None,
47         pending: false,
48     };
51 export const getMemberEmailOrName = (member: Member) => {
52     return member.Addresses?.[0]?.Email || member.Name || '';