import { WebApplication } from '@/UIModels/Application' import { AppState } from '@/UIModels/AppState' import { observer } from 'mobx-react-lite' import { FunctionComponent } from 'preact' import { StateUpdater, useCallback, useEffect, useRef, useState } from 'preact/hooks' import { AccountMenuPane } from './AccountMenuPane' import { Button } from '@/Components/Button/Button' import { DecoratedInput } from '@/Components/Input/DecoratedInput' import { DecoratedPasswordInput } from '@/Components/Input/DecoratedPasswordInput' import { Icon } from '@/Components/Icon/Icon' import { IconButton } from '@/Components/Button/IconButton' 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 emailInputRef = useRef(null) const passwordInputRef = useRef(null) const [isPrivateWorkspace, setIsPrivateWorkspace] = useState(false) useEffect(() => { if (emailInputRef.current) { emailInputRef.current?.focus() } }, []) const handleEmailChange = useCallback( (text: string) => { setEmail(text) }, [setEmail], ) const handlePasswordChange = useCallback( (text: string) => { setPassword(text) }, [setPassword], ) const handleRegisterFormSubmit = useCallback( (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) }, [email, password, setPassword, setMenuPane, setEmail], ) const handleKeyDown = useCallback( (e: KeyboardEvent) => { if (e.key === 'Enter') { handleRegisterFormSubmit(e) } }, [handleRegisterFormSubmit], ) const handleClose = useCallback(() => { setMenuPane(AccountMenuPane.GeneralMenu) setEmail('') setPassword('') }, [setEmail, setMenuPane, setPassword]) const onPrivateWorkspaceChange = useCallback( (isPrivateWorkspace: boolean, privateWorkspaceIdentifier?: string) => { setIsPrivateWorkspace(isPrivateWorkspace) if (isPrivateWorkspace && privateWorkspaceIdentifier) { setEmail(privateWorkspaceIdentifier) } }, [setEmail], ) return ( <>
Create account
]} onChange={handleEmailChange} onKeyDown={handleKeyDown} placeholder="Email" ref={emailInputRef} type="email" value={email} /> ]} onChange={handlePasswordChange} onKeyDown={handleKeyDown} placeholder="Password" ref={passwordInputRef} value={password} />