Skip to content

Commit 9bc55ec

Browse files
authored
Merge pull request #290 from codeitFE11-part3-team7/feature/#288_프로필-생성-전-내-위키페이지로-가면-500에러뜨는-이슈
✨ 프로필이 없을 때 내 위키 오류페이지
2 parents 3e46806 + 39e9144 commit 9bc55ec

File tree

2 files changed

+81
-26
lines changed

2 files changed

+81
-26
lines changed

components/MyWikiError.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { ReactNode } from 'react';
2+
import Button from './Button';
3+
import { SITE_NAME } from 'constants/terms';
4+
5+
interface Props {
6+
title: string;
7+
buttonPosition?: 'left' | 'right';
8+
children: ReactNode;
9+
}
10+
11+
export default function MyWikiError({
12+
title,
13+
buttonPosition = 'left',
14+
children,
15+
}: Props) {
16+
const buttonRightStyle = buttonPosition === 'right' && 'justify-end';
17+
18+
return (
19+
<div>
20+
<div className="my-2 flex items-end gap-3">
21+
<span className="text-8xl font-bold text-green-200 mo:text-32b ta:text-6xl">
22+
{title}
23+
</span>
24+
</div>
25+
26+
<p className="mb-4 mt-8 text-balance break-keep text-18sb">{children}</p>
27+
28+
<div
29+
className={`flex gap-4 text-balance mo:justify-center ${buttonRightStyle}`}
30+
>
31+
<Button href="/" variant="secondary" className="w-[140px]">
32+
{SITE_NAME}
33+
</Button>
34+
<Button href="/mypage" variant="primary" className="w-[140px]">
35+
마이 페이지
36+
</Button>
37+
</div>
38+
</div>
39+
);
40+
}

pages/wiki/[code].tsx

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Contents from '@/components/wiki.page/Contents';
77
import Spinner from '@/components/Spinner';
88
import IconFaceDizzy from '@/components/Svg/IconFaceDizzy';
99
import ErrorMessage from '@/components/ErrorMessage';
10+
import MyWikiError from '@/components/MyWikiError';
1011

1112
const getProfileData = async (code: string): Promise<ProfileAnswer | null> => {
1213
try {
@@ -20,6 +21,7 @@ const getProfileData = async (code: string): Promise<ProfileAnswer | null> => {
2021
export default function Wiki() {
2122
const [profile, setProfile] = useState<ProfileAnswer | null>(null);
2223
const [isError, setIsError] = useState(false);
24+
const [isMyWikiBlank, setIsMyWikiBlank] = useState(false);
2325
const router = useRouter();
2426
const { code } = router.query;
2527

@@ -31,7 +33,7 @@ export default function Wiki() {
3133
if (profileData) {
3234
setProfile(profileData); // 프로필 상태 업데이트
3335
} else {
34-
setIsError(true);
36+
setIsMyWikiBlank(true);
3537
}
3638
} catch (error) {
3739
setIsError(true);
@@ -42,34 +44,47 @@ export default function Wiki() {
4244
fetchProfile();
4345
}, [code]);
4446

45-
return (
46-
<>
47-
{isError ? (
48-
<div className="min-h-screen">
49-
<div className="container flex min-h-screen items-center justify-center">
50-
<div className="inline-flex gap-8 px-4 mo:flex-col mo:gap-2">
51-
<IconFaceDizzy width={180} height={180} className="mo:mx-auto" />
47+
if (isError) {
48+
return (
49+
<div className="min-h-screen">
50+
<div className="container flex min-h-screen items-center justify-center">
51+
<div className="inline-flex gap-8 px-4 mo:flex-col mo:gap-2">
52+
<IconFaceDizzy width={180} height={180} className="mo:mx-auto" />
5253

53-
<ErrorMessage
54-
title="데이터를 가져오는데 문제가 있어요."
55-
code="500"
56-
>
57-
서버에서 전송한 데이터를 가져오는데 문제가 발생했습니다.
58-
<br />
59-
다시 한 번 시도해주세요.
60-
</ErrorMessage>
61-
</div>
54+
<ErrorMessage title="데이터를 가져오는데 문제가 있어요." code="500">
55+
서버에서 전송한 데이터를 가져오는데 문제가 발생했습니다.
56+
<br />
57+
다시 한 번 시도해주세요.
58+
</ErrorMessage>
6259
</div>
6360
</div>
64-
) : profile ? (
65-
<div className="mt-[120px] flex justify-center pc:mx-[100px]">
66-
<Contents key={profile.code} profile={profile} />
67-
</div>
68-
) : (
69-
<div className="flex h-[calc(100vh-120px)] items-center justify-center">
70-
<Spinner size={10} />
61+
</div>
62+
);
63+
}
64+
65+
if (isMyWikiBlank) {
66+
return (
67+
<div className="container flex min-h-screen items-center justify-center">
68+
<div className="inline-flex gap-8 px-4 mo:flex-col mo:gap-2">
69+
<MyWikiError title="내 위키가 비어있어요">
70+
마이페이지에서 내 위키를 생성해주세요.
71+
</MyWikiError>
7172
</div>
72-
)}
73-
</>
73+
</div>
74+
);
75+
}
76+
77+
if (profile) {
78+
return (
79+
<div className="mt-[120px] flex justify-center pc:mx-[100px]">
80+
<Contents key={profile.code} profile={profile} />
81+
</div>
82+
);
83+
}
84+
85+
return (
86+
<div className="flex h-[calc(100vh-120px)] items-center justify-center">
87+
<Spinner size={10} />
88+
</div>
7489
);
7590
}

0 commit comments

Comments
 (0)