import { Button } from '@/components/Button'; import { WebApplication } from '@/ui_models/application'; import { AppState } from '@/ui_models/app_state'; import { PurchaseFlowPane } from '@/ui_models/app_state/purchase_flow_state'; import { observer } from 'mobx-react-lite'; import { FunctionComponent } from 'preact'; import { useEffect, useRef, useState } from 'preact/hooks'; import Circle from '../../../svg/circle-55.svg'; import BlueDot from '../../../svg/blue-dot.svg'; import Diamond from '../../../svg/diamond-with-horizontal-lines.svg'; import { FloatingLabelInput } from '@/components/FloatingLabelInput'; import { isEmailValid } from '@/utils'; import { loadPurchaseFlowUrl } from '../PurchaseFlowWrapper'; type Props = { appState: AppState; application: WebApplication; }; export const SignIn: FunctionComponent = observer( ({ appState, application }) => { const { setCurrentPane } = appState.purchaseFlow; const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [isSigningIn, setIsSigningIn] = useState(false); const [isEmailInvalid, setIsEmailInvalid] = useState(false); const [isPasswordInvalid, setIsPasswordInvalid] = useState(false); const [otherErrorMessage, setOtherErrorMessage] = useState(''); const emailInputRef = useRef(null); const passwordInputRef = useRef(null); useEffect(() => { if (emailInputRef.current) emailInputRef.current!.focus(); }, []); const handleEmailChange = (e: Event) => { if (e.target instanceof HTMLInputElement) { setEmail(e.target.value); setIsEmailInvalid(false); } }; const handlePasswordChange = (e: Event) => { if (e.target instanceof HTMLInputElement) { setPassword(e.target.value); setIsPasswordInvalid(false); setOtherErrorMessage(''); } }; const handleCreateAccountInstead = () => { if (isSigningIn) return; setCurrentPane(PurchaseFlowPane.CreateAccount); }; const handleSignIn = async () => { if (!email) { emailInputRef?.current!.focus(); return; } if (!isEmailValid(email)) { setIsEmailInvalid(true); emailInputRef?.current!.focus(); return; } if (!password) { passwordInputRef?.current!.focus(); return; } setIsSigningIn(true); try { const response = await application.signIn(email, password); if (response.error || response.data?.error) { throw new Error( response.error?.message || response.data?.error?.message ); } else { loadPurchaseFlowUrl(application).catch((err) => { console.error(err); application.alertService.alert(err); }); } } catch (err) { console.error(err); if ((err as Error).toString().includes('Invalid email or password')) { setIsSigningIn(false); setIsEmailInvalid(true); setIsPasswordInvalid(true); setOtherErrorMessage('Invalid email or password.'); setPassword(''); } else { application.alertService.alert(err as string); } } }; return (

Sign in

to continue to Standard Notes.
{isEmailInvalid && !otherErrorMessage ? (
Please provide a valid email.
) : null} {otherErrorMessage ? (
{otherErrorMessage}
) : null}
); } );