forked from Celo-HaiTi/celoht-dapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorBoundary.tsx
More file actions
47 lines (41 loc) · 1.43 KB
/
Copy pathErrorBoundary.tsx
File metadata and controls
47 lines (41 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use client";
import { Component, type ReactNode } from "react";
import { Button } from "@/components/ui/Button";
type Props = {
children: ReactNode;
fallbackTitle?: string;
fallbackDescription?: string;
};
type State = { hasError: boolean };
export class ErrorBoundary extends Component<Props, State> {
state: State = { hasError: false };
static getDerivedStateFromError() {
return { hasError: true };
}
componentDidCatch(error: unknown) {
// In production this should report to an error-tracking service.
console.error("CeloHT UI error boundary caught:", error);
}
render() {
if (this.state.hasError) {
return (
<div
role="alert"
className="mx-auto max-w-lg rounded-2xl border border-red-500/30 bg-red-500/5 p-8 text-center"
>
<h2 className="font-display text-xl font-semibold">
{this.props.fallbackTitle ?? "This section is temporarily unavailable"}
</h2>
<p className="text-ink-soft dark:text-parchment-100/70 mt-2 text-sm">
{this.props.fallbackDescription ??
"Your wallet and other CeloHT sections are still available. Return to the previous page and try this section again later."}
</p>
<Button className="mt-4" onClick={() => this.setState({ hasError: false })}>
Return to this section
</Button>
</div>
);
}
return this.props.children;
}
}