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 { StateUpdater, 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; setPassword: StateUpdater; }; export const ConfirmPassword: FunctionComponent = observer( ({ application, appState, setMenuPane, email, password, setPassword }) => { 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 passwordInputRef = useRef(); 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 (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); application.alertService.alert(err).finally(() => { setPassword(''); handleGoBack(); }); }) .finally(() => { setIsRegistering(false); }); } else { application.alertService .alert(STRING_NON_MATCHING_PASSWORDS) .finally(() => { 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.