import { Button } from '@/Components/Button/Button' import { WebApplication } from '@/UIModels/Application' import { AppState } from '@/UIModels/AppState' import { PurchaseFlowPane } from '@/UIModels/AppState/PurchaseFlowState' import { observer } from 'mobx-react-lite' import { FunctionComponent } from 'preact' import { useEffect, useRef, useState } from 'preact/hooks' import { FloatingLabelInput } from '@/Components/Input/FloatingLabelInput' import { isEmailValid } from '@/Utils' import { loadPurchaseFlowUrl } from '@/Components/PurchaseFlow/PurchaseFlowWrapper' import { BlueDotIcon, CircleIcon, DiamondIcon } from '@standardnotes/stylekit' 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(console.error) }) } } 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).catch(console.error) } } } return (

Sign in

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