feat: add error snackbar for errors originating from registerUser function
This commit is contained in:
@@ -53,15 +53,13 @@ function SignUpForm() {
|
|||||||
}, [authentication.isAuthenticated]);
|
}, [authentication.isAuthenticated]);
|
||||||
|
|
||||||
const handleSubmit = async (values) => {
|
const handleSubmit = async (values) => {
|
||||||
|
try {
|
||||||
const { fullName, email, password } = values;
|
const { fullName, email, password } = values;
|
||||||
|
|
||||||
await registerUser({
|
await registerUser({
|
||||||
fullName,
|
fullName,
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
|
||||||
const { data } = await createAccessToken({
|
const { data } = await createAccessToken({
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
@@ -69,10 +67,28 @@ function SignUpForm() {
|
|||||||
const { token } = data;
|
const { token } = data;
|
||||||
authentication.updateToken(token);
|
authentication.updateToken(token);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const errors = error?.response?.data?.errors
|
||||||
|
? Object.values(error.response.data.errors)
|
||||||
|
: [];
|
||||||
|
|
||||||
|
if (errors.length) {
|
||||||
|
for (const [error] of errors) {
|
||||||
|
enqueueSnackbar(error, {
|
||||||
|
variant: 'error',
|
||||||
|
SnackbarProps: {
|
||||||
|
'data-test': 'snackbar-sign-up-error',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
enqueueSnackbar(error?.message || formatMessage('signupForm.error'), {
|
enqueueSnackbar(error?.message || formatMessage('signupForm.error'), {
|
||||||
variant: 'error',
|
variant: 'error',
|
||||||
|
SnackbarProps: {
|
||||||
|
'data-test': 'snackbar-sign-up-error',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user