Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / selectors / onboarding.ts
blob7b2dd8444ac3e145ee77f1aa964f2d48825a30cd
1 import { createSelector } from '@reduxjs/toolkit';
3 import { selectLatestImport } from '@proton/pass/store/selectors/import';
4 import { selectWritableSharedVaults, selectWritableVaults } from '@proton/pass/store/selectors/shares';
5 import { selectPassPlan, selectUser } from '@proton/pass/store/selectors/user';
6 import { UserPassPlan } from '@proton/pass/types/api/plan';
7 import { truthy } from '@proton/pass/utils/fp/predicates';
8 import { isAdmin } from '@proton/shared/lib/user/helpers';
10 export type OnboardingStatus = {
11     vaultCreated: boolean;
12     vaultImported: boolean;
13     vaultShared: boolean;
16 export const selectOnboardingState = createSelector(
17     [selectWritableVaults, selectWritableSharedVaults, selectLatestImport],
18     (vaults, sharedVaults, lastImport): OnboardingStatus => ({
19         vaultCreated: vaults.length > 1,
20         vaultImported: lastImport !== null,
21         vaultShared: sharedVaults.length > 0,
22     })
25 export const selectOnboardingComplete = (extensionInstalled: boolean) =>
26     createSelector(selectOnboardingState, (state): boolean => extensionInstalled && Object.values(state).every(truthy));
28 export const selectOnboardingEnabled = (extensionInstalled: boolean) =>
29     createSelector(
30         [selectUser, selectPassPlan, selectOnboardingComplete(extensionInstalled)],
31         (user, plan, complete) => user && isAdmin(user) && plan === UserPassPlan.BUSINESS && !complete
32     );