import { useEffect, useState } from 'react'; import { Modal } from '../Modal'; import { GitHubButton } from './GitHubButton'; import { GoogleButton } from './GoogleButton'; import { LinkedInButton } from './LinkedInButton'; import { EmailLoginForm } from './EmailLoginForm'; import { EmailSignupForm } from './EmailSignupForm'; type CourseLoginPopupProps = { onClose: () => void; checkoutAfterLogin?: boolean; }; export const CHECKOUT_AFTER_LOGIN_KEY = 'checkoutAfterLogin'; export const SAMPLE_AFTER_LOGIN_KEY = 'sampleAfterLogin'; export function CourseLoginPopup(props: CourseLoginPopupProps) { const { onClose: parentOnClose, checkoutAfterLogin = true } = props; const [isDisabled, setIsDisabled] = useState(false); const [isUsingEmail, setIsUsingEmail] = useState(false); const [emailNature, setEmailNature] = useState<'login' | 'signup' | null>( null, ); function onClose() { // if user didn't login and closed the popup, we remove the checkoutAfterLogin flag // so that login from other buttons on course page will trigger purchase localStorage.removeItem(CHECKOUT_AFTER_LOGIN_KEY); localStorage.removeItem(SAMPLE_AFTER_LOGIN_KEY); parentOnClose(); } useEffect(() => { localStorage.setItem( CHECKOUT_AFTER_LOGIN_KEY, checkoutAfterLogin ? '1' : '0', ); }, [checkoutAfterLogin]); if (emailNature) { const emailHeader = (
{emailNature === 'login' ? 'Login to your account' : 'Create an account'}
Fill in the details below to continue
Create or login to Enroll
Login or sign up for an account to start learning