♻️ refactor(ErrorPage): use Mui components
This commit is contained in:
@@ -17,12 +17,13 @@ describe('Renders ErrorPage correctly', async () => {
|
|||||||
* Passes - shows title correctly
|
* Passes - shows title correctly
|
||||||
*/
|
*/
|
||||||
it('Should render the error page 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} />)
|
render(<RouterProvider router={router} />)
|
||||||
|
|
||||||
expect(screen.getByText('Oops!')).toBeInTheDocument()
|
expect(screen.getByText('Oops!')).toBeInTheDocument()
|
||||||
expect(screen.getByText('Sorry, an unexpected error has occurred.')).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()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
import { isRouteErrorResponse, useRouteError } from 'react-router-dom'
|
import { isRouteErrorResponse, useRouteError } from 'react-router-dom'
|
||||||
|
import { Box, Typography } from '@mui/material'
|
||||||
|
|
||||||
const ErrorPage: React.FC = () => {
|
const ErrorPage: React.FC = () => {
|
||||||
const error: unknown = useRouteError()
|
const error: unknown = useRouteError()
|
||||||
if (isRouteErrorResponse(error)) {
|
return (
|
||||||
return (
|
<Box display="flex" flexDirection="column" justifyContent="center" alignItems="center" minHeight="100vh">
|
||||||
<div id="error-page" className="flex flex-col gap-8 justify-center items-center h-screen">
|
<Typography variant="h1" color="primary.main">
|
||||||
<h1 className="text-4xl font-bold">Oops!</h1>
|
Oops!
|
||||||
<p>Sorry, an unexpected error has occurred.</p>
|
</Typography>
|
||||||
{isRouteErrorResponse(error) && (
|
<Typography variant="h6">Sorry, an unexpected error has occurred.</Typography>
|
||||||
<p className="text-slate-400">
|
{isRouteErrorResponse(error) && (
|
||||||
<i>
|
<Typography color="text.secondary">
|
||||||
{error.status} {error.statusText}
|
{error.status} {error.data}
|
||||||
</i>
|
</Typography>
|
||||||
</p>
|
)}
|
||||||
)}
|
</Box>
|
||||||
</div>
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ErrorPage
|
export default ErrorPage
|
||||||
|
|||||||
Reference in New Issue
Block a user