import { STRING_NON_MATCHING_PASSWORDS } from '@/strings'; import { WebApplication } from '@/ui_models/application'; import { AppState } from '@/ui_models/app_state'; import { observer } from 'mobx-react-lite'; import { FunctionComponent } from 'preact'; import { useEffect, useRef, useState } from 'preact/hooks'; import { AccountMenuPane } from '.'; import { Button } from '../Button'; import { Checkbox } from '../Checkbox'; import { IconButton } from '../IconButton'; import { InputWithIcon } from '../InputWithIcon'; import { AdvancedOptions } from './AdvancedOptions'; type Props = { appState: AppState; application: WebApplication; setMenuPane: (pane: AccountMenuPane) => void; email: string; password: string; }; export const ConfirmPassword: FunctionComponent = observer( ({ application, appState, setMenuPane, email, password }) => { const { notesAndTagsCount } = appState.accountMenu; const [confirmPassword, setConfirmPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [isRegistering, setIsRegistering] = useState(false); const [isEphemeral, setIsEphemeral] = useState(false); const [shouldMergeLocal, setShouldMergeLocal] = useState(true); const [error, setError] = useState(''); const passwordInputRef = useRef(null); useEffect(() => { passwordInputRef.current?.focus(); }, []); const handlePasswordChange = (e: Event) => { if (e.target instanceof HTMLInputElement) { setConfirmPassword(e.target.value); } }; const handleEphemeralChange = () => { setIsEphemeral(!isEphemeral); }; const handleShouldMergeChange = () => { setShouldMergeLocal(!shouldMergeLocal); }; const handleKeyDown = (e: KeyboardEvent) => { if (error.length) { setError(''); } if (e.key === 'Enter') { handleConfirmFormSubmit(e); } }; const handleConfirmFormSubmit = (e: Event) => { e.preventDefault(); if (!password) { passwordInputRef.current?.focus(); return; } if (password === confirmPassword) { setIsRegistering(true); application .register(email, password, isEphemeral, shouldMergeLocal) .then((res) => { if (res.error) { throw new Error(res.error.message); } appState.accountMenu.closeAccountMenu(); appState.accountMenu.setCurrentPane(AccountMenuPane.GeneralMenu); }) .catch((err) => { console.error(err); setError(err.message); }) .finally(() => { setIsRegistering(false); }); } else { setError(STRING_NON_MATCHING_PASSWORDS); setConfirmPassword(''); passwordInputRef.current?.focus(); } }; const handleGoBack = () => { setMenuPane(AccountMenuPane.Register); }; return ( <>
Confirm password
Because your notes are encrypted using your password,{' '} Standard Notes does not have a password reset option . If you forget your password, you will permanently lose access to your data.
{error ?
{error}
: null}