| 1 | import { ArrowPathIcon, FlagIcon } from "@heroicons/react/24/outline"; |
| 2 | import { DISCORD_LINK, GITHUB_LINK } from "core/util/constants"; |
| 3 | import { useContext, useEffect, useState } from "react"; |
| 4 | import { useDispatch } from "react-redux"; |
| 5 | import { useNavigate, useRouteError } from "react-router-dom"; |
| 6 | import { Button, SecondaryButton } from "../components"; |
| 7 | import { DiscordIcon } from "../components/svg/DiscordIcon"; |
| 8 | import { GithubIcon } from "../components/svg/GithubIcon"; |
| 9 | import { IdeMessengerContext } from "../context/IdeMessenger"; |
| 10 | import { newSession } from "../redux/slices/sessionSlice"; |
| 11 | |
| 12 | const ErrorPage: React.FC = () => { |
| 13 | const error: any = useRouteError(); |
| 14 | console.error(error); |
| 15 | const dispatch = useDispatch(); |
| 16 | const navigate = useNavigate(); |
| 17 | |
| 18 | const messenger = useContext(IdeMessengerContext); |
| 19 | const openUrl = (url: string) => { |
| 20 | if (messenger) { |
| 21 | messenger.post("openUrl", url); |
| 22 | } |
| 23 | }; |
| 24 | |
| 25 | const [initialLoad, setInitialLoad] = useState(true); |
| 26 | |
| 27 | useEffect(() => { |
| 28 | setTimeout(() => { |
| 29 | setInitialLoad(false); |
| 30 | }, 500); |
| 31 | }, []); |
| 32 | |
| 33 | return ( |
| 34 | <div className="flex flex-col items-center justify-center px-2 py-4 text-center sm:px-8"> |
| 35 | <h1 className="mb-4 text-3xl font-bold">Oops! Something went wrong</h1> |
| 36 | |
| 37 | <code className="whitespace-wrap mx-2 mb-4 max-w-full break-words py-2"> |
| 38 | {error.statusText || error.message} |
| 39 | </code> |
| 40 | |
| 41 | <Button |
| 42 | className="flex flex-row items-center gap-2" |
| 43 | onClick={() => { |
| 44 | dispatch(newSession()); |
| 45 | localStorage.removeItem("persist:root"); |
| 46 | localStorage.removeItem("inputHistory_chat"); |
| 47 | // localStorage.removeItem("showTutorialCard"); |
| 48 | // localStorage.removeItem("onboardingStatus"); |
| 49 | navigate("/"); |
| 50 | }} |
| 51 | > |
| 52 | {initialLoad ? ( |
| 53 | <FlagIcon className="h-5 w-5 text-red-600" /> |
| 54 | ) : ( |
| 55 | <ArrowPathIcon className="h-5 w-5" /> |
| 56 | )} |
| 57 | Continue |
| 58 | </Button> |
| 59 | |
| 60 | <p className="mb-0 mt-6 text-lg"> |
| 61 | Report the issue on GitHub or Discord: |
| 62 | </p> |
| 63 | |
| 64 | <div className="mt-2 flex flex-row flex-wrap justify-center gap-2"> |
| 65 | <SecondaryButton |
| 66 | onClick={() => openUrl(GITHUB_LINK)} |
| 67 | className="flex items-center justify-center space-x-2 rounded-lg px-4 py-2 text-base text-white" |
| 68 | > |
| 69 | <GithubIcon size={20} /> <span className="ml-2">GitHub</span> |
| 70 | </SecondaryButton> |
| 71 | <SecondaryButton |
| 72 | onClick={() => openUrl(DISCORD_LINK)} |
| 73 | className="flex items-center justify-center rounded-lg text-base" |
| 74 | > |
| 75 | <DiscordIcon size={20} /> <span className="ml-2">Discord</span> |
| 76 | </SecondaryButton> |
| 77 | </div> |
| 78 | </div> |
| 79 | ); |
| 80 | }; |
| 81 | |
| 82 | export default ErrorPage; |