diff --git a/web/settings/account-delete-modal.react.js b/web/settings/account-delete-modal.react.js --- a/web/settings/account-delete-modal.react.js +++ b/web/settings/account-delete-modal.react.js @@ -10,6 +10,7 @@ import { useModalContext } from 'lib/components/modal-provider.react'; import { preRequestUserStateSelector } from 'lib/selectors/account-selectors'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors'; +import { accountHasPassword } from 'lib/shared/account-utils.js'; import type { LogOutResult } from 'lib/types/account-types'; import type { PreRequestUserState } from 'lib/types/session-types'; import type { DispatchActionPromise } from 'lib/utils/action-utils'; @@ -26,17 +27,18 @@ import css from './account-delete-modal.css'; type Props = { + +isAccountWithPassword: boolean, +preRequestUserState: PreRequestUserState, +inputDisabled: boolean, +dispatchActionPromise: DispatchActionPromise, +deleteAccount: ( - password: string, + password: ?string, preRequestUserState: PreRequestUserState, ) => Promise, +popModal: () => void, }; type State = { - +currentPassword: string, + +currentPassword: ?string, +errorMessage: string, }; @@ -46,14 +48,17 @@ constructor(props: Props) { super(props); this.state = { - currentPassword: '', + currentPassword: props.isAccountWithPassword ? '' : null, errorMessage: '', }; } componentDidMount() { - invariant(this.currentPasswordInput, 'newPasswordInput ref unset'); - this.currentPasswordInput.focus(); + invariant( + !this.props.isAccountWithPassword || this.currentPasswordInput, + 'newPasswordInput ref unset', + ); + this.currentPasswordInput?.focus(); } render() { @@ -66,6 +71,30 @@ ); } + let passwordConfirmation; + if (this.props.isAccountWithPassword) { + invariant( + this.state.currentPassword, + 'currentPassword must be set if isAccountWithPassword', + ); + passwordConfirmation = ( + <> +

+ Please enter your account password to confirm your identity. +

+

Account password

+ + + ); + } + return (
@@ -75,18 +104,9 @@ Your account will be permanently deleted. There is no way to reverse this.

-

- Please enter your account password to confirm your identity. -

-

Account password

- + + {passwordConfirmation} +