Skip to content

Commit 1c4ee31

Browse files
committed
fix: duplicate enable 2FA error messages
1 parent f5dfe86 commit 1c4ee31

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

resources/scripts/components/dashboard/forms/SetupTwoFactorModal.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import getTwoFactorTokenUrl from '@/api/account/getTwoFactorTokenUrl';
66
import enableAccountTwoFactor from '@/api/account/enableAccountTwoFactor';
77
import { Actions, useStoreActions } from 'easy-peasy';
88
import { ApplicationStore } from '@/state';
9-
import { httpErrorToHuman } from '@/api/http';
109
import FlashMessageRender from '@/components/FlashMessageRender';
1110
import Field from '@/components/elements/Field';
1211
import tw from 'twin.macro';
@@ -22,28 +21,26 @@ export default ({ onDismissed, ...props }: RequiredModalProps) => {
2221
const [ recoveryTokens, setRecoveryTokens ] = useState<string[]>([]);
2322

2423
const updateUserData = useStoreActions((actions: Actions<ApplicationStore>) => actions.user.updateUserData);
25-
const { addError, clearFlashes } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
24+
const { clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
2625

2726
useEffect(() => {
28-
clearFlashes('account:two-factor');
2927
getTwoFactorTokenUrl()
3028
.then(setToken)
3129
.catch(error => {
3230
console.error(error);
33-
addError({ message: httpErrorToHuman(error), key: 'account:two-factor' });
31+
clearAndAddHttpError({ error: error, key: 'account:two-factor' });
3432
});
3533
}, []);
3634

3735
const submit = ({ code }: Values, { setSubmitting }: FormikHelpers<Values>) => {
38-
clearFlashes('account:two-factor');
3936
enableAccountTwoFactor(code)
4037
.then(tokens => {
4138
setRecoveryTokens(tokens);
4239
})
4340
.catch(error => {
4441
console.error(error);
4542

46-
addError({ message: httpErrorToHuman(error), key: 'account:two-factor' });
43+
clearAndAddHttpError({ error: error, key: 'account:two-factor' });
4744
})
4845
.then(() => setSubmitting(false));
4946
};

0 commit comments

Comments
 (0)