1 import { createSelector } from '@reduxjs/toolkit';
3 import { sortItems } from '@proton/pass/lib/items/item.utils';
4 import { PlanType } from '@proton/pass/types';
6 import { selectAliasItems, selectLoginItems } from './items';
7 import { selectAllVaults } from './shares';
8 import { selectUserPlan } from './user';
10 export const selectVaultLimits = createSelector([selectAllVaults, selectUserPlan], (vaults, plan) => {
11 const vaultLimit = plan?.VaultLimit ?? Number.MAX_SAFE_INTEGER;
15 vaultTotalCount: vaults.length,
16 vaultLimitReached: vaults.length >= vaultLimit,
17 didDowngrade: vaults.length > vaultLimit && plan?.Type === PlanType.free,
21 export const selectAliasLimits = createSelector([selectAliasItems, selectUserPlan], (alias, plan) => {
22 const aliasLimit = plan?.AliasLimit ?? Number.MAX_SAFE_INTEGER;
26 aliasLimited: typeof plan?.AliasLimit === 'number',
27 aliasTotalCount: alias.length,
28 needsUpgrade: alias.length >= aliasLimit,
29 didDowngrade: alias.length > aliasLimit,
33 export const selectTOTPLimits = createSelector([selectLoginItems, selectUserPlan], (loginItems, plan) => {
34 const totpLimit = plan?.TotpLimit;
35 let needsUpgrade = false;
36 let didDowngrade = false;
37 let totpAllowed: (itemId: string) => boolean = () => true;
39 if (typeof totpLimit === 'number') {
40 const totpItems = loginItems.filter((item) => Boolean(item.data.content.totpUri.v));
41 const totpTotalCount = totpItems.length;
43 needsUpgrade = totpTotalCount >= totpLimit;
44 didDowngrade = totpTotalCount > totpLimit;
45 totpAllowed = (itemId: string) =>
46 sortItems('createTimeASC')(totpItems)
48 .some((item) => item.itemId === itemId);
59 export const selectExtraFieldLimits = createSelector([selectUserPlan], (plan) => {
61 needsUpgrade: plan?.Type === PlanType.free,