1 import { useUser } from '@proton/account/user/hooks';
2 import useConfig from '@proton/components/hooks/useConfig';
3 import { FeatureCode, useFeature } from '@proton/features';
5 import useOfferFlags from '../../hooks/useOfferFlags';
6 import type { Operation } from '../../interface';
7 import config from './configuration';
8 import getIsEligible from './eligibility';
11 * This offer is different than others, it runs all the time and is used to nudge free users
12 * Once the account is old enough, we display a spotlight over the upgrade button on the navbar
14 const useOffer = (): Operation => {
15 const protonConfig = useConfig();
16 const [user, loadingUser] = useUser();
17 const { isActive, loading: flagsLoading, isVisited } = useOfferFlags(config);
18 const { feature: lastReminderDate, loading: lastReminderDateLoading } = useFeature(
19 FeatureCode.SubscriptionLastReminderDate
22 const isLoading = flagsLoading || loadingUser || lastReminderDateLoading;
23 // We use today time if the feature flag is not set to avoid showing the value to all users or unexpected behavior
24 const isEligible = getIsEligible({
27 lastReminderTimestamp: lastReminderDate?.Value,
31 return { isValid: isEligible && isActive, config, isEligible, isLoading: !!isLoading };
34 export default useOffer;