|
| 1 | +import type { ReactElement } from 'react'; |
| 2 | +import React, { useCallback, useEffect, useState } from 'react'; |
| 3 | +import { |
| 4 | + Button, |
| 5 | + ButtonSize, |
| 6 | + ButtonVariant, |
| 7 | +} from '../../../components/buttons/Button'; |
| 8 | +import { |
| 9 | + Typography, |
| 10 | + TypographyColor, |
| 11 | + TypographyTag, |
| 12 | + TypographyType, |
| 13 | +} from '../../../components/typography/Typography'; |
| 14 | +import { useLogContext } from '../../../contexts/LogContext'; |
| 15 | +import { LogEvent } from '../../../lib/log'; |
| 16 | +import { cloudinaryOnboardingActivationDemo } from '../../../lib/image'; |
| 17 | +import { requestOpenNewTabFromPage } from '../../extensionEmbed/newTabActivationBridge'; |
| 18 | + |
| 19 | +type NewTabActivationPrimerProps = { |
| 20 | + onComplete: () => void; |
| 21 | +}; |
| 22 | + |
| 23 | +// Aspect ratio matches source dimensions so the element hugs the frame. |
| 24 | +const DEMO_URL = cloudinaryOnboardingActivationDemo; // 1748×1080 |
| 25 | + |
| 26 | +function ActivationDemoVideo(): ReactElement { |
| 27 | + return ( |
| 28 | + <video |
| 29 | + src={DEMO_URL} |
| 30 | + className="aspect-[1748/1080] w-full max-w-[43rem] rounded-16 border border-border-subtlest-tertiary bg-background-subtle shadow-2" |
| 31 | + muted |
| 32 | + autoPlay |
| 33 | + loop |
| 34 | + playsInline |
| 35 | + disablePictureInPicture |
| 36 | + controls={false} |
| 37 | + aria-label="Rehearsal of Chrome's confirmation bubble and the Keep it click" |
| 38 | + /> |
| 39 | + ); |
| 40 | +} |
| 41 | + |
| 42 | +export function NewTabActivationPrimer({ |
| 43 | + onComplete, |
| 44 | +}: NewTabActivationPrimerProps): ReactElement { |
| 45 | + const { logEvent } = useLogContext(); |
| 46 | + const [isOpening, setIsOpening] = useState(false); |
| 47 | + |
| 48 | + useEffect(() => { |
| 49 | + logEvent({ event_name: LogEvent.ExtensionPrimerShown }); |
| 50 | + }, [logEvent]); |
| 51 | + |
| 52 | + const handleOpenNewTab = useCallback(async (): Promise<void> => { |
| 53 | + logEvent({ event_name: LogEvent.ExtensionPrimerCtaClick }); |
| 54 | + setIsOpening(true); |
| 55 | + // Ask the extension to open chrome://newtab so Chrome's confirmation |
| 56 | + // bubble appears. Advance this tab afterwards regardless of the result, |
| 57 | + // so the user is never stranded on the primer. |
| 58 | + await requestOpenNewTabFromPage(); |
| 59 | + onComplete(); |
| 60 | + }, [logEvent, onComplete]); |
| 61 | + |
| 62 | + return ( |
| 63 | + <div className="flex w-full flex-1 flex-col items-center justify-center px-6 py-10"> |
| 64 | + <div className="flex w-full max-w-[48rem] flex-col items-center gap-5 text-center"> |
| 65 | + <div className="flex flex-col items-center gap-2"> |
| 66 | + <Typography |
| 67 | + tag={TypographyTag.H1} |
| 68 | + type={TypographyType.LargeTitle} |
| 69 | + color={TypographyColor.Primary} |
| 70 | + bold |
| 71 | + className="text-balance" |
| 72 | + > |
| 73 | + Welcome! Let's activate your new tab. |
| 74 | + </Typography> |
| 75 | + |
| 76 | + <Typography |
| 77 | + tag={TypographyTag.P} |
| 78 | + type={TypographyType.Title3} |
| 79 | + color={TypographyColor.Secondary} |
| 80 | + className="text-balance" |
| 81 | + > |
| 82 | + Tap “Keep it” on the Chrome popup. |
| 83 | + </Typography> |
| 84 | + </div> |
| 85 | + |
| 86 | + <ActivationDemoVideo /> |
| 87 | + |
| 88 | + <div className="flex flex-col items-center gap-4"> |
| 89 | + <Button |
| 90 | + type="button" |
| 91 | + variant={ButtonVariant.Primary} |
| 92 | + size={ButtonSize.XLarge} |
| 93 | + disabled={isOpening} |
| 94 | + onClick={handleOpenNewTab} |
| 95 | + > |
| 96 | + {isOpening ? 'Opening…' : 'Open new tab'} |
| 97 | + </Button> |
| 98 | + <p className="text-text-tertiary typo-callout"> |
| 99 | + Takes 2 seconds. Reversible anytime. |
| 100 | + </p> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + ); |
| 105 | +} |
0 commit comments