1 import { useEffect } from 'react';
3 import { useUser } from '@proton/account/user/hooks';
4 import { getCookie, setCookie } from '@proton/shared/lib/helpers/cookies';
5 import { getSecondLevelDomain } from '@proton/shared/lib/helpers/url';
7 const COOKIE_NAME = 'no-offer';
8 const today = new Date();
9 const lastDayOfTheYear = new Date(today.getFullYear(), 11, 31, 23, 59, 59);
10 const cookieDomain = `.${getSecondLevelDomain(window.location.hostname)}`;
13 * Set a cookie for non eligible user to BF offer
14 * Used by proton.me website to hide BF banner
16 const useIsPaidUserCookie = () => {
17 const [user, loadingUser] = useUser();
18 const loading = loadingUser;
25 const cookie = getCookie(COOKIE_NAME);
26 const isPaid = user.isPaid;
27 const shouldSet = isPaid;
29 if (shouldSet && cookie !== '1') {
31 cookieName: COOKIE_NAME,
34 expirationDate: lastDayOfTheYear.toUTCString(),
37 } else if (!shouldSet && cookie === '1') {
39 cookieName: COOKIE_NAME,
40 cookieValue: undefined,
42 expirationDate: new Date(0).toUTCString(),
49 export default useIsPaidUserCookie;