feat: introduce inline error messages for ForgotPassword and ResetPasswordForm
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import Paper from '@mui/material/Paper';
|
import Paper from '@mui/material/Paper';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
import LoadingButton from '@mui/lab/LoadingButton';
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
import { enqueueSnackbar } from 'notistack';
|
|
||||||
|
|
||||||
import useForgotPassword from 'hooks/useForgotPassword';
|
import useForgotPassword from 'hooks/useForgotPassword';
|
||||||
import Form from 'components/Form';
|
import Form from 'components/Form';
|
||||||
@@ -15,6 +15,8 @@ export default function ForgotPasswordForm() {
|
|||||||
mutateAsync: forgotPassword,
|
mutateAsync: forgotPassword,
|
||||||
isPending: loading,
|
isPending: loading,
|
||||||
isSuccess,
|
isSuccess,
|
||||||
|
isError,
|
||||||
|
error,
|
||||||
} = useForgotPassword();
|
} = useForgotPassword();
|
||||||
|
|
||||||
const handleSubmit = async (values) => {
|
const handleSubmit = async (values) => {
|
||||||
@@ -23,14 +25,7 @@ export default function ForgotPasswordForm() {
|
|||||||
await forgotPassword({
|
await forgotPassword({
|
||||||
email,
|
email,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch {}
|
||||||
enqueueSnackbar(
|
|
||||||
error?.message || formatMessage('forgotPasswordForm.error'),
|
|
||||||
{
|
|
||||||
variant: 'error',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -57,6 +52,16 @@ export default function ForgotPasswordForm() {
|
|||||||
margin="dense"
|
margin="dense"
|
||||||
autoComplete="username"
|
autoComplete="username"
|
||||||
/>
|
/>
|
||||||
|
{isError && (
|
||||||
|
<Alert severity="error" sx={{ mt: 2 }}>
|
||||||
|
{error?.message || formatMessage('forgotPasswordForm.error')}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
{isSuccess && (
|
||||||
|
<Alert severity="success" sx={{ mt: 2 }}>
|
||||||
|
{formatMessage('forgotPasswordForm.instructionsSent')}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
@@ -68,14 +73,6 @@ export default function ForgotPasswordForm() {
|
|||||||
>
|
>
|
||||||
{formatMessage('forgotPasswordForm.submit')}
|
{formatMessage('forgotPasswordForm.submit')}
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
{isSuccess && (
|
|
||||||
<Typography
|
|
||||||
variant="body1"
|
|
||||||
sx={{ color: (theme) => theme.palette.success.main }}
|
|
||||||
>
|
|
||||||
{formatMessage('forgotPasswordForm.instructionsSent')}
|
|
||||||
</Typography>
|
|
||||||
)}
|
|
||||||
</Form>
|
</Form>
|
||||||
</Paper>
|
</Paper>
|
||||||
);
|
);
|
||||||
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|||||||
import { useNavigate, Link as RouterLink } from 'react-router-dom';
|
import { useNavigate, Link as RouterLink } from 'react-router-dom';
|
||||||
import Paper from '@mui/material/Paper';
|
import Paper from '@mui/material/Paper';
|
||||||
import Link from '@mui/material/Link';
|
import Link from '@mui/material/Link';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import LoadingButton from '@mui/lab/LoadingButton';
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
import useAuthentication from 'hooks/useAuthentication';
|
import useAuthentication from 'hooks/useAuthentication';
|
||||||
@@ -11,7 +12,6 @@ import Form from 'components/Form';
|
|||||||
import TextField from 'components/TextField';
|
import TextField from 'components/TextField';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useCreateAccessToken from 'hooks/useCreateAccessToken';
|
import useCreateAccessToken from 'hooks/useCreateAccessToken';
|
||||||
import { Alert } from '@mui/material';
|
|
||||||
|
|
||||||
function LoginForm() {
|
function LoginForm() {
|
||||||
const isCloud = useCloud();
|
const isCloud = useCloud();
|
||||||
@@ -45,7 +45,7 @@ function LoginForm() {
|
|||||||
|
|
||||||
const renderError = () => {
|
const renderError = () => {
|
||||||
const errors = error?.response?.data?.errors?.general || [
|
const errors = error?.response?.data?.errors?.general || [
|
||||||
formatMessage('loginForm.error'),
|
error?.message || formatMessage('loginForm.error'),
|
||||||
];
|
];
|
||||||
|
|
||||||
return errors.map((error) => (
|
return errors.map((error) => (
|
||||||
|
@@ -2,6 +2,7 @@ import { yupResolver } from '@hookform/resolvers/yup';
|
|||||||
import LoadingButton from '@mui/lab/LoadingButton';
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
import Paper from '@mui/material/Paper';
|
import Paper from '@mui/material/Paper';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
@@ -30,6 +31,8 @@ export default function ResetPasswordForm() {
|
|||||||
mutateAsync: resetPassword,
|
mutateAsync: resetPassword,
|
||||||
isPending,
|
isPending,
|
||||||
isSuccess,
|
isSuccess,
|
||||||
|
error,
|
||||||
|
isError,
|
||||||
} = useResetPassword();
|
} = useResetPassword();
|
||||||
const token = searchParams.get('token');
|
const token = searchParams.get('token');
|
||||||
|
|
||||||
@@ -47,14 +50,23 @@ export default function ResetPasswordForm() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
navigate(URLS.LOGIN);
|
navigate(URLS.LOGIN);
|
||||||
} catch (error) {
|
} catch {}
|
||||||
enqueueSnackbar(
|
};
|
||||||
error?.message || formatMessage('resetPasswordForm.error'),
|
|
||||||
{
|
const renderError = () => {
|
||||||
variant: 'error',
|
if (!isError) {
|
||||||
},
|
return null;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const errors = error?.response?.data?.errors?.general || [
|
||||||
|
error?.message || formatMessage('resetPasswordForm.error'),
|
||||||
|
];
|
||||||
|
|
||||||
|
return errors.map((error) => (
|
||||||
|
<Alert severity="error" sx={{ mt: 2 }}>
|
||||||
|
{error}
|
||||||
|
</Alert>
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -96,7 +108,6 @@ export default function ResetPasswordForm() {
|
|||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
label={formatMessage(
|
label={formatMessage(
|
||||||
'resetPasswordForm.confirmPasswordFieldLabel',
|
'resetPasswordForm.confirmPasswordFieldLabel',
|
||||||
@@ -117,7 +128,7 @@ export default function ResetPasswordForm() {
|
|||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
{renderError()}
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
Reference in New Issue
Block a user