diff --git a/app/soapbox/components/ui/input/input.tsx b/app/soapbox/components/ui/input/input.tsx index 44b90912f..a5543c9e9 100644 --- a/app/soapbox/components/ui/input/input.tsx +++ b/app/soapbox/components/ui/input/input.tsx @@ -11,7 +11,7 @@ const messages = defineMessages({ hidePassword: { id: 'input.password.hide_password', defaultMessage: 'Hide password' }, }); -interface IInput extends Pick, 'maxLength' | 'onChange' | 'type' | 'autoComplete' | 'autoCorrect' | 'autoCapitalize' | 'required'> { +interface IInput extends Pick, 'maxLength' | 'onChange' | 'type' | 'autoComplete' | 'autoCorrect' | 'autoCapitalize' | 'required' | 'disabled'> { autoFocus?: boolean, defaultValue?: string, className?: string, diff --git a/app/soapbox/features/security/mfa/disable_otp_form.tsx b/app/soapbox/features/security/mfa/disable_otp_form.tsx new file mode 100644 index 000000000..2dd66b8c8 --- /dev/null +++ b/app/soapbox/features/security/mfa/disable_otp_form.tsx @@ -0,0 +1,83 @@ +import React, { useState, useCallback } from 'react'; +import { useIntl, defineMessages, FormattedMessage } from 'react-intl'; +import { useHistory } from 'react-router-dom'; + +import { disableMfa } from 'soapbox/actions/mfa'; +import snackbar from 'soapbox/actions/snackbar'; +import { useAppDispatch } from 'soapbox/hooks'; + +import { Button, Form, FormGroup, Input, FormActions, Stack, Text } from '../../../components/ui'; + +const messages = defineMessages({ + mfa_setup_disable_button: { id: 'column.mfa_disable_button', defaultMessage: 'Disable' }, + disableFail: { id: 'security.disable.fail', defaultMessage: 'Incorrect password. Try again.' }, + mfaDisableSuccess: { id: 'mfa.disable.success_message', defaultMessage: 'MFA disabled' }, + passwordPlaceholder: { id: 'mfa.mfa_setup.password_placeholder', defaultMessage: 'Password' }, +}); + + +const DisableOtpForm: React.FC = () => { + const [isLoading, setIsLoading] = useState(false); + const [password, setPassword] = useState(''); + + const intl = useIntl(); + const dispatch = useAppDispatch(); + const history = useHistory(); + + const handleSubmit = useCallback(() => { + setIsLoading(true); + dispatch(disableMfa('totp', password)).then(() => { + dispatch(snackbar.success(intl.formatMessage(messages.mfaDisableSuccess))); + history.push('../auth/edit'); + }).finally(() => { + setIsLoading(false); + }).catch(() => { + dispatch(snackbar.error(intl.formatMessage(messages.disableFail))); + }); + }, [password, dispatch, intl]); + + const handleInputChange = (event: React.ChangeEvent) => { + setPassword(event.target.value); + }; + + + return ( +
+ + + + + + + + + + + } + > + + + + +