♻️ refactor(ErrorPage): use Mui components

This commit is contained in:
2024-01-20 16:07:25 +01:00
parent 8aff802faa
commit af3274f881
2 changed files with 17 additions and 17 deletions
@@ -17,12 +17,13 @@ describe('Renders ErrorPage correctly', async () => {
* Passes - shows title correctly
*/
it('Should render the error page correctly', () => {
const router = createMemoryRouter([{ path: '/', element: <div />, errorElement: <ErrorPage /> }], { initialEntries: ['/some/bad/route'] })
const badRoute = '/some/bad/route'
const router = createMemoryRouter([{ path: '/', element: <div />, errorElement: <ErrorPage /> }], { initialEntries: [badRoute] })
render(<RouterProvider router={router} />)
expect(screen.getByText('Oops!')).toBeInTheDocument()
expect(screen.getByText('Sorry, an unexpected error has occurred.')).toBeInTheDocument()
expect(screen.getByText('404 Not Found')).toBeInTheDocument()
expect(screen.getByText(`404 Error: No route matches URL "${badRoute}"`)).toBeInTheDocument()
})
})
+14 -15
View File
@@ -1,22 +1,21 @@
import { isRouteErrorResponse, useRouteError } from 'react-router-dom'
import { Box, Typography } from '@mui/material'
const ErrorPage: React.FC = () => {
const error: unknown = useRouteError()
if (isRouteErrorResponse(error)) {
return (
<div id="error-page" className="flex flex-col gap-8 justify-center items-center h-screen">
<h1 className="text-4xl font-bold">Oops!</h1>
<p>Sorry, an unexpected error has occurred.</p>
{isRouteErrorResponse(error) && (
<p className="text-slate-400">
<i>
{error.status} {error.statusText}
</i>
</p>
)}
</div>
)
}
return (
<Box display="flex" flexDirection="column" justifyContent="center" alignItems="center" minHeight="100vh">
<Typography variant="h1" color="primary.main">
Oops!
</Typography>
<Typography variant="h6">Sorry, an unexpected error has occurred.</Typography>
{isRouteErrorResponse(error) && (
<Typography color="text.secondary">
{error.status} {error.data}
</Typography>
)}
</Box>
)
}
export default ErrorPage