Skip to content

Commit e86aea3

Browse files
committed
feat: add SiteMapErrorFallback component for enhanced error handling in SiteMapErrorBoundary
1 parent 85c8e89 commit e86aea3

4 files changed

Lines changed: 112 additions & 25 deletions

File tree

apps/ticket/src/app/(pages)/event/[eventId]/time-table/site-map/_clientBoundary/SiteMapErrorBoundary/index.tsx

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,26 @@
22

33
import { ReactNode } from "react";
44

5-
import { Button, Flex, Typography } from "@permit/design-system";
65
import { ErrorBoundary, ErrorHandler } from "@/shared/clientBoundary/ErrorBoundary";
76
import { AxiosErrorResponse, isAxiosErrorResponse } from "@/shared/types/axioxError";
87

8+
import { SiteMapErrorFallback } from "../SiteMapErrorFallback";
9+
910
type Props = {
1011
children: ReactNode;
12+
eventId: string;
1113
};
1214

1315
const NOT_FOUND_SITE_MAP_ERROR_CODE = 40429;
1416

15-
export const SiteMapErrorBoundary = ({ children }: Props) => {
16-
return <ErrorBoundary handlers={siteMapErrorHandlers}>{children}</ErrorBoundary>;
17+
export const SiteMapErrorBoundary = ({ children, eventId }: Props) => {
18+
return <ErrorBoundary handlers={siteMapErrorHandlers({ eventId })}>{children}</ErrorBoundary>;
1719
};
1820

19-
const siteMapErrorHandlers: ErrorHandler[] = [
21+
const siteMapErrorHandlers = ({ eventId }: { eventId: string }): ErrorHandler[] => [
2022
{
2123
isError: (error) => isSiteMapNotRegisteredError(error as AxiosErrorResponse),
22-
fallback: () => (
23-
<Flex
24-
direction="column"
25-
align="center"
26-
justify="center"
27-
gap={16}
28-
style={{ height: "calc(100vh - 150px)" }}
29-
>
30-
<Typography type="title20">아직 사이트맵이 등록되지 않았어요.</Typography>
31-
<Button
32-
variant="primary"
33-
size="md"
34-
onClick={() => {
35-
window.location.href = "/";
36-
}}
37-
>
38-
홈으로 이동
39-
</Button>
40-
</Flex>
41-
),
24+
fallback: () => <SiteMapErrorFallback eventId={eventId} />,
4225
},
4326
];
4427

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.header {
2+
// margin-bottom: 8px;
3+
padding: 12px 16px;
4+
}
5+
6+
.back_button {
7+
width: 90px;
8+
height: 32px;
9+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
"use client";
2+
3+
import { useRouter } from "next/navigation";
4+
import classNames from "classnames/bind";
5+
6+
import { Button, Flex, Typography } from "@permit/design-system";
7+
import { useEventDetailQuery } from "@/data/events/getEventDetail/queries";
8+
import { LoadingWithLayout } from "@/shared/components/LoadingWithLayout";
9+
10+
import styles from "./index.module.scss";
11+
12+
const cx = classNames.bind(styles);
13+
14+
type Props = {
15+
eventId: string;
16+
};
17+
18+
export const SiteMapErrorFallback = ({ eventId }: Props) => {
19+
const router = useRouter();
20+
21+
const {
22+
data: eventDetailData,
23+
isLoading,
24+
error,
25+
} = useEventDetailQuery({
26+
eventId,
27+
});
28+
29+
const handleBackButtonClick = () => {
30+
router.push(`/event/${eventId}`);
31+
};
32+
33+
if (isLoading) {
34+
return <LoadingWithLayout />;
35+
}
36+
37+
if (error) {
38+
throw error;
39+
}
40+
41+
return (
42+
<>
43+
<header className={cx("header")}>
44+
<Flex gap={8} justify="space-between">
45+
<Flex direction="column" gap={16}>
46+
<Typography type="title20">{eventDetailData?.eventName}</Typography>
47+
48+
<Button
49+
className={cx("back_button")}
50+
variant="secondary"
51+
onClick={handleBackButtonClick}
52+
>
53+
{"< back"}
54+
</Button>
55+
56+
<Flex gap={8}>
57+
<Button
58+
variant="secondary"
59+
onClick={() => router.push(`/event/${eventId}/time-table`)}
60+
>
61+
{"Timetable"}
62+
</Button>
63+
<Button
64+
variant="secondary"
65+
onClick={() => router.push(`/event/${eventId}/time-table/site-map`)}
66+
>
67+
{"Sitemap"}
68+
</Button>
69+
</Flex>
70+
</Flex>
71+
<></>
72+
</Flex>
73+
</header>
74+
75+
<Flex
76+
direction="column"
77+
align="center"
78+
justify="center"
79+
gap={16}
80+
style={{ height: "calc(100vh - 150px)" }}
81+
>
82+
<Typography type="title20">아직 사이트맵이 등록되지 않았어요.</Typography>
83+
<Button
84+
variant="primary"
85+
size="md"
86+
onClick={() => {
87+
window.location.href = `/event/${eventId}`;
88+
}}
89+
>
90+
이벤트 보기
91+
</Button>
92+
</Flex>
93+
</>
94+
);
95+
};

apps/ticket/src/app/(pages)/event/[eventId]/time-table/site-map/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function SiteMapPage({ params }: Props) {
2020
qc.prefetchQuery(siteMapOptions({ eventId }));
2121

2222
return (
23-
<SiteMapErrorBoundary>
23+
<SiteMapErrorBoundary eventId={eventId}>
2424
<HydrationBoundary state={dehydrate(qc)}>
2525
<Suspense fallback={<LoadingWithLayout />}>
2626
<SiteMapClient eventId={eventId} />

0 commit comments

Comments
 (0)