1 import { useState } from 'react';
3 import { isAfter, isBefore } from 'date-fns';
5 import { useWelcomeFlags } from '@proton/account';
6 import { getItem, setItem } from '@proton/shared/lib/helpers/storage';
10 featureFlagsEnabled?: boolean;
11 shouldWelcomeFlowBeDone?: boolean;
13 expirationDate?: string;
16 const getIsActive = (startDate?: string, expirationDate?: string) => {
17 const today = new Date();
19 if (startDate && isBefore(today, new Date(startDate))) {
23 if (expirationDate && isAfter(today, new Date(expirationDate))) {
30 export default function useNewFeatureOnboarding({
32 featureFlagsEnabled = true,
33 shouldWelcomeFlowBeDone = true,
37 const onboardingKey = `onboarding-${key}`;
38 const [wasShown, setWasShown] = useState<boolean>(Boolean(getItem(onboardingKey, 'false')));
39 const { welcomeFlags } = useWelcomeFlags();
41 const isActive = getIsActive(startDate, expirationDate);
42 const isWelcomeDone = shouldWelcomeFlowBeDone && welcomeFlags.isDone;
43 const showOnboarding = !wasShown && isActive && featureFlagsEnabled && isWelcomeDone;
45 const onWasShown = () => {
47 setItem(onboardingKey, 'true');