diff --git a/src/components/Error.tsx b/src/components/Error.tsx new file mode 100644 index 00000000..73f89897 --- /dev/null +++ b/src/components/Error.tsx @@ -0,0 +1,41 @@ +import { CircleAlert } from "lucide-react"; +import { Header } from "./Header"; +import { Card } from "./ui/card"; + +export function Error() { + return ( +
+
+
+
+
+ + +
+ An error occurred +
+
+ If this issue persists, please reach out to us on{" "} + + Discord + {" "} + or open a new{" "} + + Github issue + +
+
+
+
+ ); +} diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx new file mode 100644 index 00000000..acd1ee61 --- /dev/null +++ b/src/components/ErrorBoundary.tsx @@ -0,0 +1,33 @@ +import type { ReactNode } from "react"; +import { Component } from "react"; + +interface Props { + children?: ReactNode; + fallback: ReactNode; +} + +interface State { + hasError: boolean; +} + +export default class ErrorBoundary extends Component { + public state: State = { + hasError: false, + }; + + public static getDerivedStateFromError(): State { + return { hasError: true }; + } + + public componentDidCatch() { + // this should log the error to a service like Sentry + } + + public render() { + if (this.state.hasError) { + return this.props.fallback; + } + + return this.props.children; + } +} diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 74dc4121..33115d7c 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -2,12 +2,17 @@ import { Link } from "react-router-dom"; import { SidebarTrigger } from "./ui/sidebar"; import { Separator } from "./ui/separator"; -export function Header() { +export function Header({ hasError }: { hasError?: boolean }) { return (
- - + {!hasError && ( + <> + + + + )} +