fix: duplicate enable 2FA error messages
This commit is contained in:
parent
f5dfe86eff
commit
1c4ee31491
1 changed files with 3 additions and 6 deletions
|
@ -6,7 +6,6 @@ import getTwoFactorTokenUrl from '@/api/account/getTwoFactorTokenUrl';
|
||||||
import enableAccountTwoFactor from '@/api/account/enableAccountTwoFactor';
|
import enableAccountTwoFactor from '@/api/account/enableAccountTwoFactor';
|
||||||
import { Actions, useStoreActions } from 'easy-peasy';
|
import { Actions, useStoreActions } from 'easy-peasy';
|
||||||
import { ApplicationStore } from '@/state';
|
import { ApplicationStore } from '@/state';
|
||||||
import { httpErrorToHuman } from '@/api/http';
|
|
||||||
import FlashMessageRender from '@/components/FlashMessageRender';
|
import FlashMessageRender from '@/components/FlashMessageRender';
|
||||||
import Field from '@/components/elements/Field';
|
import Field from '@/components/elements/Field';
|
||||||
import tw from 'twin.macro';
|
import tw from 'twin.macro';
|
||||||
|
@ -22,20 +21,18 @@ export default ({ onDismissed, ...props }: RequiredModalProps) => {
|
||||||
const [ recoveryTokens, setRecoveryTokens ] = useState<string[]>([]);
|
const [ recoveryTokens, setRecoveryTokens ] = useState<string[]>([]);
|
||||||
|
|
||||||
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
|
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
|
||||||
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
const { clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
clearFlashes('account:two-factor');
|
|
||||||
getTwoFactorTokenUrl()
|
getTwoFactorTokenUrl()
|
||||||
.then(setToken)
|
.then(setToken)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
addError({ message: httpErrorToHuman(error), key: 'account:two-factor' });
|
clearAndAddHttpError({ error: error, key: 'account:two-factor' });
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const submit = ({ code }: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
const submit = ({ code }: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
||||||
clearFlashes('account:two-factor');
|
|
||||||
enableAccountTwoFactor(code)
|
enableAccountTwoFactor(code)
|
||||||
.then(tokens => {
|
.then(tokens => {
|
||||||
setRecoveryTokens(tokens);
|
setRecoveryTokens(tokens);
|
||||||
|
@ -43,7 +40,7 @@ export default ({ onDismissed, ...props }: RequiredModalProps) => {
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
addError({ message: httpErrorToHuman(error), key: 'account:two-factor' });
|
clearAndAddHttpError({ error: error, key: 'account:two-factor' });
|
||||||
})
|
})
|
||||||
.then(() => setSubmitting(false));
|
.then(() => setSubmitting(false));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue