Skip to content

Commit 936ebe5

Browse files
committed
ref: 401,404,500 하나의 컴포넌트로 공통화
1 parent 97474e3 commit 936ebe5

File tree

3 files changed

+53
-38
lines changed

3 files changed

+53
-38
lines changed

src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import MbtiTestQuestions from "@/pages/MbtiTestQuestions";
2020
import MbtiTestResult from "@/pages/MbtiTestResult";
2121
import CenteredLayout from "@/components/CenteredLayout";
2222
import { initGA, trackPageView } from "@/libs/analytics";
23-
import NotFound from "@/pages/NotFound";
23+
import Error from "@/pages/Error";
2424

2525
const PageTracker = () => {
2626
const location = useLocation();
@@ -94,7 +94,7 @@ const App = () => {
9494
<Route path="/mbti-test" element={<MbtiTestIntro />} />
9595
<Route path="/mbti-test-progress" element={<MbtiTestQuestions />} />
9696
<Route path="/mbti-test-result" element={<MbtiTestResult />} />
97-
<Route path="*" element={<NotFound />} />
97+
<Route path="*" element={<Error mode="500" />} />
9898
</Routes>
9999
</CenteredLayout>
100100
</Router>

src/pages/Error.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import PrimaryButton from "@/components/button/PrimaryButton";
2+
import { useNavigate } from "react-router-dom";
3+
4+
const Error = ({ mode }: { mode: "401" | "404" | "500" }) => {
5+
const navigate = useNavigate();
6+
7+
const content = {
8+
401: {
9+
title: "세션이 만료되었습니다.",
10+
description: `활동이 없어 자동으로 로그아웃되었어요.\n채팅을 이어가려면 다시 로그인해 주세요.`,
11+
buttonTitle: "홈으로 가기",
12+
onClick: () => {
13+
navigate("/");
14+
}
15+
},
16+
404: {
17+
title: "페이지를 찾을 수 없습니다.",
18+
description: `입력하신 주소가 올바르지 않거나,\n요청하신 페이지가 삭제되었을 수 있습니다.`,
19+
buttonTitle: "홈으로 가기",
20+
onClick: () => {
21+
navigate("/");
22+
}
23+
},
24+
500: {
25+
title: "앗! 잠시 오류가 일어났어요",
26+
description: `일시적인 문제가 발생했습니다.\n잠시 후 다시 시도해 주세요.`,
27+
buttonTitle: "새로고침 버튼",
28+
onClick: () => {
29+
window.location.reload();
30+
}
31+
}
32+
};
33+
return (
34+
<main className="relative flex flex-col items-center bg-white">
35+
<div className="absolute bottom-[372px] flex h-[196px] flex-col items-center justify-between">
36+
<img src="/icon/error.svg" alt="에러 아이콘" width={63} height={63} />
37+
<h1 className="text-2xl font-bold ">{content[mode].title}</h1>
38+
<p className="text-center whitespace-pre-wrap text-gray-600">
39+
{content[mode].description}
40+
</p>
41+
</div>
42+
<div className="absolute bottom-[60px]">
43+
<PrimaryButton size="md" onClick={content[mode].onClick}>
44+
{content[mode].buttonTitle}
45+
</PrimaryButton>
46+
</div>
47+
</main>
48+
);
49+
};
50+
51+
export default Error;

src/pages/NotFound.tsx

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)