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;
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,
25 export const selectOnboardingComplete = (extensionInstalled: boolean) =>
26 createSelector(selectOnboardingState, (state): boolean => extensionInstalled && Object.values(state).every(truthy));
28 export const selectOnboardingEnabled = (extensionInstalled: boolean) =>
30 [selectUser, selectPassPlan, selectOnboardingComplete(extensionInstalled)],
31 (user, plan, complete) => user && isAdmin(user) && plan === UserPassPlan.BUSINESS && !complete