-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Error boundary for staff profiles
fixes #538
- Loading branch information
1 parent
aa0e058
commit 8fbf0d4
Showing
8 changed files
with
268 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from "react"; | ||
import ErrorPage from "./ErrorPage"; | ||
|
||
interface Props { | ||
children: React.ReactNode; | ||
isSuperuser?: boolean; | ||
} | ||
|
||
interface State { | ||
hasError: boolean; | ||
error: Error | null; | ||
} | ||
|
||
class ErrorBoundary extends React.Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props); | ||
this.state = { hasError: false, error: null }; | ||
} | ||
|
||
static getDerivedStateFromError(error: Error): State { | ||
return { hasError: true, error }; | ||
} | ||
|
||
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { | ||
console.error("Error caught by boundary:", error, errorInfo); | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
return ( | ||
<ErrorPage | ||
error={this.state.error} | ||
isSuperuser={this.props.isSuperuser} | ||
resetError={() => this.setState({ hasError: false, error: null })} | ||
/> | ||
); | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from "react"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { Button } from "@/components/ui/button"; | ||
import { RefreshCw, Home } from "lucide-react"; | ||
|
||
interface ErrorPageProps { | ||
error?: Error | null; | ||
resetError?: () => void; | ||
isSuperuser?: boolean; | ||
} | ||
|
||
const ErrorPage: React.FC<ErrorPageProps> = ({ | ||
error, | ||
resetError, | ||
isSuperuser = false, | ||
}) => { | ||
if (isSuperuser && error) { | ||
console.error("Error caught by boundary:", error); | ||
} | ||
|
||
return ( | ||
<div className="container mx-auto flex min-h-[60vh] items-center justify-center px-4"> | ||
<Card className="w-full max-w-2xl"> | ||
<CardHeader> | ||
<CardTitle className="text-2xl">Something went wrong</CardTitle> | ||
<CardDescription> | ||
We encountered an unexpected error while loading this page | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
{isSuperuser && error && ( | ||
<div className="mt-0 overflow-hidden rounded-lg bg-slate-800 p-4"> | ||
<p className="mb-2 text-sm text-slate-400">Error details:</p> | ||
<pre className="overflow-auto text-sm text-white"> | ||
{error.toString()} | ||
</pre> | ||
</div> | ||
)} | ||
</CardContent> | ||
<CardFooter className="flex gap-4"> | ||
<Button | ||
variant="default" | ||
onClick={() => window.location.reload()} | ||
className="gap-2 bg-blue-600 hover:bg-blue-700" | ||
> | ||
<RefreshCw className="h-4 w-4" /> | ||
Reload Page | ||
</Button> | ||
<Button | ||
variant="outline" | ||
onClick={() => (window.location.href = "/")} | ||
className="gap-2" | ||
> | ||
<Home className="h-4 w-4" /> | ||
Return Home | ||
</Button> | ||
</CardFooter> | ||
</Card> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ErrorPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as React from "react" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const Card = React.forwardRef< | ||
HTMLDivElement, | ||
React.HTMLAttributes<HTMLDivElement> | ||
>(({ className, ...props }, ref) => ( | ||
<div | ||
ref={ref} | ||
className={cn( | ||
"rounded-lg border bg-card text-card-foreground shadow-sm", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
Card.displayName = "Card" | ||
|
||
const CardHeader = React.forwardRef< | ||
HTMLDivElement, | ||
React.HTMLAttributes<HTMLDivElement> | ||
>(({ className, ...props }, ref) => ( | ||
<div | ||
ref={ref} | ||
className={cn("flex flex-col space-y-1.5 p-6", className)} | ||
{...props} | ||
/> | ||
)) | ||
CardHeader.displayName = "CardHeader" | ||
|
||
const CardTitle = React.forwardRef< | ||
HTMLDivElement, | ||
React.HTMLAttributes<HTMLDivElement> | ||
>(({ className, ...props }, ref) => ( | ||
<div | ||
ref={ref} | ||
className={cn( | ||
"text-2xl font-semibold leading-none tracking-tight", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
CardTitle.displayName = "CardTitle" | ||
|
||
const CardDescription = React.forwardRef< | ||
HTMLDivElement, | ||
React.HTMLAttributes<HTMLDivElement> | ||
>(({ className, ...props }, ref) => ( | ||
<div | ||
ref={ref} | ||
className={cn("text-sm text-muted-foreground", className)} | ||
{...props} | ||
/> | ||
)) | ||
CardDescription.displayName = "CardDescription" | ||
|
||
const CardContent = React.forwardRef< | ||
HTMLDivElement, | ||
React.HTMLAttributes<HTMLDivElement> | ||
>(({ className, ...props }, ref) => ( | ||
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} /> | ||
)) | ||
CardContent.displayName = "CardContent" | ||
|
||
const CardFooter = React.forwardRef< | ||
HTMLDivElement, | ||
React.HTMLAttributes<HTMLDivElement> | ||
>(({ className, ...props }, ref) => ( | ||
<div | ||
ref={ref} | ||
className={cn("flex items-center p-6 pt-0", className)} | ||
{...props} | ||
/> | ||
)) | ||
CardFooter.displayName = "CardFooter" | ||
|
||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters