1 import { useRef } from 'react';
3 import { addDays, fromUnixTime } from 'date-fns';
4 import { c } from 'ttag';
6 import { useWelcomeFlags } from '@proton/account';
7 import { useUser } from '@proton/account/user/hooks';
8 import { Href } from '@proton/atoms';
12 useBusySlotsAvailable,
13 useSpotlightOnFeature,
15 } from '@proton/components';
16 import { FeatureCode } from '@proton/features';
17 import type { VIEWS } from '@proton/shared/lib/calendar/constants';
18 import { getKnowledgeBaseUrl } from '@proton/shared/lib/helpers/url';
19 import spotlightImg from '@proton/styles/assets/img/illustrations/spotlight-stars.svg';
22 children: React.ReactNode;
24 isDisplayedInPopover: boolean;
27 const BusySlotsSpotlight = ({ children, view, isDisplayedInPopover }: Props) => {
28 const anchorRef = useRef<HTMLDivElement>(null);
29 const [user] = useUser();
30 const { viewportWidth } = useActiveBreakpoint();
31 const { welcomeFlags: { isDone } } = useWelcomeFlags();
32 const userAccountHasMoreThanTwoDays = new Date() > addDays(fromUnixTime(user.CreateTime), 2);
33 const isBusySlotsAvailable = useBusySlotsAvailable(view);
37 * 1. User is not on a mobile screen
38 * 2. User has done the welcome flow
39 * 3. User has created his account more than 2 days ago
40 * 4. Feature available for sure
41 * 5. Is in the popover modal
43 const displaySpotlight =
44 !viewportWidth['<=small'] &&
46 userAccountHasMoreThanTwoDays &&
47 isBusySlotsAvailable &&
50 const { show, onDisplayed, onClose } = useSpotlightOnFeature(
51 FeatureCode.CalendarBusySlotsSpotlight,
55 const shouldShowSpotlight = useSpotlightShow(show);
59 originalPlacement="right"
60 show={shouldShowSpotlight}
61 onDisplayed={onDisplayed}
67 <div className="flex flex-nowrap my-2">
68 <div className="shrink-0 mr-4">
69 <img src={spotlightImg} alt="" />
72 <p className="mt-0 mb-2 text-bold">{c('Spotlight').t`No more scheduling conflicts`}</p>
73 <p className="m-0">{c('Spotlight')
74 .t`Now you can see when participants are free to attend your meeting.`}</p>
75 <Href href={getKnowledgeBaseUrl('/calendar-availability')}>{c('Info').t`Learn more`}</Href>
80 {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
81 <div ref={anchorRef} onClick={onClose}>
88 export default BusySlotsSpotlight;