-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prettier error-page #836
base: main
Are you sure you want to change the base?
Prettier error-page #836
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
import React from "react"; | ||
import { useRouteError } from "react-router-dom"; | ||
import { useRouteError, useNavigate } from "react-router-dom"; | ||
import { PageTitle } from "../components/elements/BattlecodeStyle"; | ||
import { DEFAULT_EPISODE } from "../utils/constants"; | ||
|
||
const ErrorBoundary: React.FC = () => { | ||
const error = useRouteError(); | ||
const navigate = useNavigate(); // Initialize useNavigate | ||
|
||
if (error instanceof Error) { | ||
return ( | ||
<div className="flex flex-col gap-6 p-6 xl:flex-row"> | ||
const handleGoHome = (): void => { | ||
navigate(`/${DEFAULT_EPISODE}/home`); // Navigate to home | ||
}; | ||
|
||
return ( | ||
<div className="flex h-screen w-full items-center justify-center bg-white p-6"> | ||
<div className="flex flex-col gap-4 rounded-lg border border-gray-300 bg-gray-50 p-6 shadow-md max-w-xs w-full"> | ||
<PageTitle>Oops, something went wrong.</PageTitle> | ||
<p> | ||
<p className="text-center"> | ||
Please reach out on Discord or to [email protected] with the | ||
following error message: | ||
</p> | ||
<span className="rounded-md bg-gray-200 px-1 py-0.5 font-mono"> | ||
{error.message} | ||
</span> | ||
{error instanceof Error ? ( | ||
<span className="rounded-md bg-gray-200 px-1 py-0.5 font-mono text-center block"> | ||
{error.message} | ||
</span> | ||
) : ( | ||
<span className="text-red-600 text-center block">An unknown error occurred.</span> | ||
)} | ||
<button | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a custom Button component in components/elements that you can use for any buttons you create, it's pre styled. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just use a div here instead of a button though (put the div inside the Link component) |
||
onClick={handleGoHome} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of using navigate we can use the React Router Link component https://reactrouter.com/en/main/components/link It'll simplify the logic a bit, I think that navigate should be used for more complicated logic |
||
className="mt-4 rounded bg-blue-500 text-white px-3 py-1 hover:bg-blue-600 transition mx-auto" | ||
> | ||
Go to Home | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
return <p>Oops, something went wrong.</p>; | ||
</div> | ||
); | ||
}; | ||
|
||
export default ErrorBoundary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's replace this with whatever the standard way to link to an email address is! Maybe:
where the body is the error message and page name (or some other well-formatted embedding of the error information 😃)