Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / components / containers / offers / operations / blackFridayVPN2024Free / useOffer.ts
blob905f7a741030f03de1a30893c1803648a1c76e5c
1 import { useSubscription } from '@proton/account/subscription/hooks';
2 import { useUser } from '@proton/account/user/hooks';
3 import useConfig from '@proton/components/hooks/useConfig';
4 import useLastSubscriptionEnd from '@proton/components/hooks/useLastSubscriptionEnd';
5 import { useAutomaticCurrency } from '@proton/components/payments/client-extensions';
7 import useOfferFlags from '../../hooks/useOfferFlags';
8 import type { Operation } from '../../interface';
9 import config from './configuration';
10 import getIsEligible from './eligibility';
12 const useOffer = (): Operation => {
13     const [user, userLoading] = useUser();
14     const [subscription, subscriptionLoading] = useSubscription();
15     const { isActive, loading: flagsLoading } = useOfferFlags(config);
16     const [lastSubscriptionEnd, lastSubscriptionEndLoading] = useLastSubscriptionEnd();
17     const [preferredCurrency, loadingCurrency] = useAutomaticCurrency();
18     const protonConfig = useConfig();
19     const isLoading =
20         flagsLoading || userLoading || subscriptionLoading || lastSubscriptionEndLoading || loadingCurrency;
21     const isEligible = getIsEligible({ subscription, protonConfig, user, lastSubscriptionEnd, preferredCurrency });
22     const isValid = isEligible && isActive;
24     return { isValid, config, isLoading, isEligible };
27 export default useOffer;