Skip to content

Commit 15b0b8d

Browse files
authored
Merge pull request #202 from MBTips/feature/404-페이지
feat: 401,404,500 엣지케이스 Error 컴포넌트로 통일
2 parents 2b59eb3 + 6801a89 commit 15b0b8d

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

public/icon/error.svg

Lines changed: 4 additions & 0 deletions
Loading

src/App.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +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 Error from "@/pages/Error";
2324

2425
const PageTracker = () => {
2526
const location = useLocation();
@@ -77,16 +78,23 @@ const App = () => {
7778
<Route path="/" element={<Home />} />
7879
<Route path="/select-info" element={<SelectInfo />} />
7980
<Route path="/chat" element={<Chat />} />
80-
<Route path="/chat-recommend" element={<ChatRecommend />} />
81-
<Route path="/chat-tips" element={<ChatTips />} />
82-
<Route path="/chat-temporature" element={<ChatTemporature />} />
81+
<Route
82+
path="/chat-recommend/:virtualFriendId"
83+
element={<ChatRecommend />}
84+
/>
85+
<Route path="/chat-tips/:virtualFriendId" element={<ChatTips />} />
86+
<Route
87+
path="/chat-temporature/:conversationId"
88+
element={<ChatTemporature />}
89+
/>
8390
<Route path="/contents/:id" element={<Content />} />
8491
<Route path="/login" element={<Login />} />
8592
<Route path="/my-info" element={<MyInfo />} />
8693
<Route path="/kakao-login" element={<KaKaoLogin />} />
87-
<Route path="/mbti-test" element={<MbtiTestIntro />} />
94+
<Route path="/mbti-test" element={<MbtiTestIntro />} />
8895
<Route path="/mbti-test-progress" element={<MbtiTestQuestions />} />
8996
<Route path="/mbti-test-result" element={<MbtiTestResult />} />
97+
<Route path="*" element={<Error statusCode="500" />} />
9098
</Routes>
9199
</CenteredLayout>
92100
</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 = ({ statusCode }: { statusCode: "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[statusCode].title}</h1>
38+
<p className="text-center whitespace-pre-wrap text-gray-600">
39+
{content[statusCode].description}
40+
</p>
41+
</div>
42+
<div className="absolute bottom-[60px]">
43+
<PrimaryButton size="md" onClick={content[statusCode].onClick}>
44+
{content[statusCode].buttonTitle}
45+
</PrimaryButton>
46+
</div>
47+
</main>
48+
);
49+
};
50+
51+
export default Error;

0 commit comments

Comments
 (0)