Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / components / hooks / usePreferredPlansMap.ts
blobe96fc8cdb3874c0ea4059a1aaf066743e37e50b9
1 import { usePaymentStatus } from '@proton/account/paymentStatus/hooks';
2 import { usePlans } from '@proton/account/plans/hooks';
3 import { useSubscription } from '@proton/account/subscription/hooks';
4 import { useUser } from '@proton/account/user/hooks';
5 import {
6     type Currency,
7     type FullPlansMap,
8     type GetPreferredCurrencyParams,
9     getPlansMap as getPlansMapInner,
10 } from '@proton/payments';
12 import { useCurrencies } from '../payments/client-extensions/useCurrencies';
14 type PreferredPlansMapHook = {
15     plansMapLoading: boolean;
16     plansMap: FullPlansMap;
17     getPlansMap: (overrides?: GetPreferredCurrencyParams) => {
18         plansMap: FullPlansMap;
19         preferredCurrency: Currency;
20     };
21     preferredCurrency: Currency;
24 export const usePreferredPlansMap = (currencyFallback?: boolean): PreferredPlansMapHook => {
25     const [plans, plansLoading] = usePlans();
26     const [status, statusLoading] = usePaymentStatus();
27     const [subscription, subscriptionLoading] = useSubscription();
28     const [user] = useUser();
29     const { getPreferredCurrency } = useCurrencies();
31     const getPlansMap = (overrides: GetPreferredCurrencyParams = {}) => {
32         const preferredCurrency = getPreferredCurrency({
33             ...overrides,
34             user,
35             subscription,
36             plans: plans?.plans,
37             status,
38         });
40         return {
41             preferredCurrency,
42             plansMap: getPlansMapInner(plans?.plans ?? [], preferredCurrency, currencyFallback),
43         };
44     };
46     return {
47         ...getPlansMap(),
48         getPlansMap,
49         plansMapLoading: plansLoading || statusLoading || subscriptionLoading,
50     };