import { WebApplication } from '@/ui_models/application'; import { AppState } from '@/ui_models/app_state'; import { observer } from 'mobx-react-lite'; import { FunctionComponent } from 'preact'; import { StateUpdater, useEffect, useRef, useState } from 'preact/hooks'; import { AccountMenuPane } from '.'; import { Button } from '../Button'; import { IconButton } from '../IconButton'; import { InputWithIcon } from '../InputWithIcon'; import { AdvancedOptions } from './AdvancedOptions'; type Props = { appState: AppState; application: WebApplication; setMenuPane: (pane: AccountMenuPane) => void; email: string; setEmail: StateUpdater; password: string; setPassword: StateUpdater; }; export const CreateAccount: FunctionComponent = observer( ({ appState, application, setMenuPane, email, setEmail, password, setPassword, }) => { const [showPassword, setShowPassword] = useState(false); 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); } }; const handlePasswordChange = (e: Event) => { if (e.target instanceof HTMLInputElement) { setPassword(e.target.value); } }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Enter') { handleRegisterFormSubmit(e); } }; const handleRegisterFormSubmit = (e: Event) => { e.preventDefault(); if (!email || email.length === 0) { emailInputRef.current?.focus(); return; } if (!password || password.length === 0) { passwordInputRef.current?.focus(); return; } setEmail(email); setPassword(password); setMenuPane(AccountMenuPane.ConfirmPassword); }; const handleClose = () => { setMenuPane(AccountMenuPane.GeneralMenu); setEmail(''); setPassword(''); }; return ( <>
Create account