Skip to content

Commit 31eba0b

Browse files
authored
Error Boundary (#177)
* Add error handling UI * Update redirect message * Update boundary
1 parent 06e5c8a commit 31eba0b

File tree

9 files changed

+141
-13
lines changed

9 files changed

+141
-13
lines changed

src/app/private/admin/home/error.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use client";
2+
3+
import { ErrorNavigation } from "@components/navigation";
4+
5+
const Error = () => {
6+
return (
7+
<ErrorNavigation
8+
message="Oops, an error has occurred."
9+
redirectTo="/private/admin/home/chapters"
10+
redirectMessage="View all chapters"
11+
/>
12+
);
13+
};
14+
15+
export default Error;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use client";
2+
3+
import { ErrorNavigation } from "@components/navigation";
4+
5+
const Error = () => {
6+
return (
7+
<ErrorNavigation
8+
message="Oops, an error has occurred."
9+
redirectTo="/private/chapter-leader/seniors"
10+
redirectMessage="View all seniors"
11+
/>
12+
);
13+
};
14+
15+
export default Error;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use client";
2+
3+
import { ErrorNavigation } from "@components/navigation";
4+
5+
const Error = () => {
6+
return (
7+
<ErrorNavigation
8+
message="Oops, an error has occurred."
9+
redirectTo="/private/chapter-leader/users"
10+
redirectMessage="View all users"
11+
/>
12+
);
13+
};
14+
15+
export default Error;

src/app/private/error.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use client";
2+
3+
import { ErrorNavigation } from "@components/navigation";
4+
5+
const Error = () => {
6+
return (
7+
<ErrorNavigation
8+
message="Oops, an error has occurred."
9+
redirectMessage="Back to home"
10+
/>
11+
);
12+
};
13+
14+
export default Error;

src/app/private/user/layout.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ISideBar } from "@components/Sidebar";
22
import { CollapsibleSidebarContainer } from "@components/container";
33
import { faHome, faUsers, faUser } from "@fortawesome/free-solid-svg-icons";
4-
import { UserContext } from "src/context/UserProvider";
54

65
interface IUserLayout {
76
children: React.ReactNode;
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use client";
2+
3+
import { ErrorNavigation } from "@components/navigation";
4+
5+
const Error = () => {
6+
return (
7+
<ErrorNavigation
8+
message="Oops, an error has occurred."
9+
redirectTo="/private/user/seniors"
10+
redirectMessage="View all seniors"
11+
/>
12+
);
13+
};
14+
15+
export default Error;

src/components/Sidebar.tsx

+24-12
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,33 @@ const Sidebar = (props: ISideBar) => {
116116
<_Sidebar {...props} />
117117
</div>
118118
<div
119-
className="mt-6 block lg:hidden"
119+
className="block lg:hidden"
120120
onMouseLeave={() => setSidebarVisible(false)}
121121
>
122-
<svg
123-
className="h-8 w-8 text-darkest-tan"
124-
viewBox="0 0 24 24"
125-
fill="none"
126-
stroke="currentColor"
127-
strokeWidth="1.5"
128-
onClick={() => setSidebarVisible(!sidebarVisible)}
122+
<div
123+
className="mb-24 block lg:hidden"
124+
style={{ display: sidebarVisible ? "none" : "block" }}
129125
>
130-
<line x1="4" y1="7" x2="20" y2="7" />
131-
<line x1="4" y1="12" x2="20" y2="12" />
132-
<line x1="4" y1="17" x2="20" y2="17" />
133-
</svg>
126+
<div className="fixed left-0 top-0 z-50 w-full bg-med-tan px-6 shadow-lg shadow-gray-500">
127+
<div className="flex items-center justify-between">
128+
<svg
129+
className="h-8 w-8 text-darkest-tan"
130+
viewBox="0 0 24 24"
131+
fill="none"
132+
stroke="currentColor"
133+
strokeWidth="1.5"
134+
onClick={() => setSidebarVisible(!sidebarVisible)}
135+
>
136+
<line x1="4" y1="7" x2="20" y2="7" />
137+
<line x1="4" y1="12" x2="20" y2="12" />
138+
<line x1="4" y1="17" x2="20" y2="17" />
139+
</svg>
140+
<Link href="/public">
141+
<Image src={Logo} alt="logo" height={96} />
142+
</Link>
143+
</div>
144+
</div>
145+
</div>
134146
{sidebarVisible && (
135147
<div className="fixed left-0 top-0 z-50 h-full w-64 overflow-y-auto drop-shadow-lg lg:overflow-y-hidden">
136148
<_Sidebar {...props} />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use client";
2+
3+
import { Popup } from "@components/container";
4+
import { UserContext } from "@context/UserProvider";
5+
import { formatUserHomeRoute } from "@utils";
6+
import { useRouter } from "next/navigation";
7+
import React from "react";
8+
9+
interface ErrorNavigationProps {
10+
message?: string;
11+
redirectTo?: string;
12+
redirectMessage?: string;
13+
}
14+
15+
const ErrorNavigation = ({
16+
message,
17+
redirectTo,
18+
redirectMessage,
19+
}: ErrorNavigationProps) => {
20+
const router = useRouter();
21+
const userContext = React.useContext(UserContext);
22+
23+
return (
24+
<Popup>
25+
<div className="text-wrap flex h-full w-full flex-col items-center justify-center gap-y-6">
26+
<h1 className="text-lg text-white sm:text-xl">
27+
{message ?? "Oops, an error has occurred."}
28+
</h1>
29+
<button
30+
className="mx-1 w-fit rounded bg-white p-3 text-lg text-dark-teal drop-shadow-md"
31+
onClick={() =>
32+
router.replace(redirectTo ?? formatUserHomeRoute(userContext.user))
33+
}
34+
>
35+
{redirectMessage ?? "Redirect"}
36+
</button>
37+
</div>
38+
</Popup>
39+
);
40+
};
41+
42+
export default ErrorNavigation;

src/components/navigation/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default as RootNavigation } from "./RootNavigation";
2+
export { default as ErrorNavigation } from "./ErrorNavigation";

0 commit comments

Comments
 (0)