Skip to content

Commit 58200d7

Browse files
authored
[#669] [유저 책장] 존재하지 않는 유저 책장 페이지 예외처리 (#671)
* fix: 비로그인 상태에서 꽂은책이 없는 책장에 접근시 발생하는 에러 해결 * fix: 존재하지 않는 유저 책장 페이지 예외처리 * feat: axios interceptor에 isNotFoundError 분기 추가 * feat: 유저 페이지 not-found.tsx 작성 * feat: 유저 프로필 페이지에 ErrorBoundary 추가 * chore: axios에 notFound 분기 제거
1 parent 6609f5b commit 58200d7

File tree

4 files changed

+70
-13
lines changed

4 files changed

+70
-13
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Link from 'next/link';
2+
import Image from 'next/image';
3+
4+
import Button from '@/components/common/Button';
5+
6+
export default function NotFound() {
7+
return (
8+
<div className="absolute left-0 top-0 flex h-full w-full flex-col items-center justify-center gap-[2rem]">
9+
<Image src="/images/loading.gif" width={230} height={160} alt="loading" />
10+
<p className="font-heading-bold">
11+
<span className="font-bold text-main-900">다독이</span>가 길을 잃었어요.
12+
</p>
13+
<Link href="/bookarchive">
14+
<Button size="large" colorScheme="main" fill={false}>
15+
책장 둘러보기
16+
</Button>
17+
</Link>
18+
</div>
19+
);
20+
}

src/app/bookshelf/[bookshelfId]/page.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import { notFound } from 'next/navigation';
34
import { useEffect } from 'react';
45
import { useInView } from 'react-intersection-observer';
56

@@ -55,6 +56,10 @@ const BookShelfInfo = ({ bookshelfId }: { bookshelfId: number }) => {
5556
const { isLiked, likeCount, userId, userNickname, job } = data;
5657
const hasJobInfo = job.jobGroupKoreanName && job.jobNameKoreanName;
5758

59+
if (!data.bookshelfId) {
60+
notFound();
61+
}
62+
5863
const { mutate: mutateBookshelfLike } =
5964
useMutateBookshelfLikeQuery(bookshelfId);
6065

@@ -111,6 +116,9 @@ const BookShelfContent = ({
111116
isSuccess,
112117
isFetchingNextPage,
113118
} = useBookShelfBooksQuery({ bookshelfId });
119+
const hasBooks = booksData && booksData.pages[0].books.length !== 0;
120+
const isSingleBookshelfRow =
121+
booksData && booksData.pages[0].books.length <= 1;
114122

115123
useEffect(() => {
116124
if (inView && hasNextPage) {
@@ -123,25 +131,30 @@ const BookShelfContent = ({
123131

124132
return isAuthenticated ? (
125133
<>
126-
{booksData.pages.map((page, pageIdx) =>
127-
page.books.length > 0 ? (
128-
page.books.map((rowBooks, idx) => (
129-
<BookShelfRow key={idx} books={rowBooks} />
130-
))
131-
) : (
132-
<EmptyBookShelfRow key={pageIdx} />
133-
)
134+
{hasBooks ? (
135+
<>
136+
{booksData.pages.map(page =>
137+
page.books.map((rowBooks, idx) => (
138+
<BookShelfRow key={idx} books={rowBooks} />
139+
))
140+
)}
141+
{!isFetchingNextPage && <div ref={ref} />}
142+
</>
143+
) : (
144+
<EmptyBookShelfRow />
134145
)}
135-
{!isFetchingNextPage && <div ref={ref} />}
136146
</>
137147
) : (
138148
<>
139-
<BookShelfRow books={booksData.pages[0].books[0]} />
149+
{!isSingleBookshelfRow && (
150+
<BookShelfRow books={booksData.pages[0].books[0]} />
151+
)}
140152
<DummyBookShelfRow />
141153
<BookShelfLoginBox bookshelfId={bookshelfId} />
142154
</>
143155
);
144156
};
157+
145158
const DummyBookShelfRow = () => (
146159
<div className="pointer-events-none blur-sm">
147160
<BookShelfRow books={initialBookImageUrl} />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Link from 'next/link';
2+
import Image from 'next/image';
3+
4+
import Button from '@/components/common/Button';
5+
6+
export default function NotFound() {
7+
return (
8+
<div className="absolute left-0 top-0 flex h-full w-full flex-col items-center justify-center gap-[2rem]">
9+
<Image src="/images/loading.gif" width={230} height={160} alt="loading" />
10+
<p className="font-heading-bold">
11+
<span className="font-bold text-main-900">다독이</span>가 길을 잃었어요.
12+
</p>
13+
<Link href="/bookarchive">
14+
<Button size="large" colorScheme="main" fill={false}>
15+
홈으로 가기
16+
</Button>
17+
</Link>
18+
</div>
19+
);
20+
}

src/app/profile/[userId]/page.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
'use client';
22

3-
import { APIUser } from '@/types/user';
3+
import { notFound } from 'next/navigation';
4+
import { ErrorBoundary } from 'react-error-boundary';
5+
6+
import type { APIUser } from '@/types/user';
7+
48
import BackButton from '@/components/common/BackButton';
59
import ShareButton from '@/components/common/ShareButton';
610
import TopNavigation from '@/components/common/TopNavigation';
@@ -13,7 +17,7 @@ const UserProfilePage = ({
1317
params: { userId: APIUser['userId'] };
1418
}) => {
1519
return (
16-
<>
20+
<ErrorBoundary fallbackRender={notFound}>
1721
<TopNavigation>
1822
<TopNavigation.LeftItem>
1923
<BackButton />
@@ -26,7 +30,7 @@ const UserProfilePage = ({
2630
<ProfileInfo userId={userId} />
2731
<ProfileBookShelf userId={userId} />
2832
</div>
29-
</>
33+
</ErrorBoundary>
3034
);
3135
};
3236

0 commit comments

Comments
 (0)