Skip to content

Commit

Permalink
fix: 사용자 프로필, 책장 페이지 닉네임 없으면 '익명'으로 노출
Browse files Browse the repository at this point in the history
- 직업 정보 있는 경우만 노출
  • Loading branch information
gxxrxn committed Jul 24, 2024
1 parent e7bf74b commit 0f6a180
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
19 changes: 13 additions & 6 deletions src/app/bookshelf/[bookshelfId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { IconKakao } from '@public/icons';

import useToast from '@/components/common/Toast/useToast';
import TopNavigation from '@/components/common/TopNavigation';
import BookShelfRow from '@/components/bookShelf/BookShelfRow';
import BookShelfRow, {
EmptyBookShelfRow,
} from '@/components/bookShelf/BookShelfRow';
import Button from '@/components/common/Button';
import LikeButton from '@/components/common/LikeButton';
import BackButton from '@/components/common/BackButton';
Expand Down Expand Up @@ -51,6 +53,7 @@ const BookShelfInfo = ({ bookshelfId }: { bookshelfId: number }) => {

const { data } = useBookShelfInfoQuery(bookshelfId);
const { isLiked, likeCount, userId, userNickname, job } = data;
const hasJobInfo = job.jobGroupKoreanName && job.jobNameKoreanName;

const { mutate: mutateBookshelfLike } =
useMutateBookshelfLikeQuery(bookshelfId);
Expand Down Expand Up @@ -81,7 +84,7 @@ const BookShelfInfo = ({ bookshelfId }: { bookshelfId: number }) => {
</h1>
<div className="flex items-center justify-between">
<span className="text-black-600 font-body2-regular">
{`${job.jobGroupKoreanName}${job.jobNameKoreanName}`}
{hasJobInfo && `${job.jobGroupKoreanName}${job.jobNameKoreanName}`}
</span>
<LikeButton
isLiked={isLiked}
Expand Down Expand Up @@ -120,10 +123,14 @@ const BookShelfContent = ({

return isAuthenticated ? (
<>
{booksData.pages.map(page =>
page.books.map((rowBooks, idx) => (
<BookShelfRow key={idx} books={rowBooks} />
))
{booksData.pages.map((page, pageIdx) =>
page.books.length > 0 ? (
page.books.map((rowBooks, idx) => (
<BookShelfRow key={idx} books={rowBooks} />
))
) : (
<EmptyBookShelfRow key={pageIdx} />
)
)}
{!isFetchingNextPage && <div ref={ref} />}
</>
Expand Down
9 changes: 9 additions & 0 deletions src/components/bookShelf/BookShelfRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ const BookShelfRow = ({ books }: Pick<APIBookshelf, 'books'>) => {
};

export default BookShelfRow;

export const EmptyBookShelfRow = () => (
<BookShelf>
<div className="relative left-[-2rem] w-[calc(100%+4rem)] pb-[2.5rem] pt-[2rem] shadow-[0px_28px_20px_-16px_#D1D1D1]">
<BookShelf.Background />
<BookShelf.EmptyText />
</div>
</BookShelf>
);
8 changes: 5 additions & 3 deletions src/queries/bookshelf/useBookShelfInfoQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { APIBookshelfInfo } from '@/types/bookshelf';
import useQueryWithSuspense from '@/hooks/useQueryWithSuspense';
import bookshelfAPI from '@/apis/bookshelf';
import bookShelfKeys from './key';
import { getSafeNickname } from '@/utils/converter';

const useBookShelfInfoQuery = <TData = APIBookshelfInfo>(
bookshelfId: APIBookshelfInfo['bookshelfId'],
Expand All @@ -11,9 +12,10 @@ const useBookShelfInfoQuery = <TData = APIBookshelfInfo>(
useQueryWithSuspense(
bookShelfKeys.info(bookshelfId),
() =>
bookshelfAPI
.getBookshelfInfo(bookshelfId)
.then(response => response.data),
bookshelfAPI.getBookshelfInfo(bookshelfId).then(({ data }) => ({
...data,
userNickname: getSafeNickname(data.userId, data.userNickname),
})),
options
);

Expand Down
8 changes: 6 additions & 2 deletions src/queries/user/useUserProfileQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { APIUser, APIUserProfile } from '@/types/user';
import useQueryWithSuspense, {
UseQueryOptionWithoutSuspense,
} from '@/hooks/useQueryWithSuspense';

import { getSafeNickname } from '@/utils/converter';
import userAPI from '@/apis/user';
import userKeys from './key';

Expand All @@ -12,7 +12,11 @@ const useUserProfileQuery = (
) =>
useQueryWithSuspense(
userKeys.detail(userId),
() => userAPI.getUserProfile({ userId }).then(({ data }) => data),
() =>
userAPI.getUserProfile({ userId }).then(({ data }) => ({
...data,
nickname: getSafeNickname(data.userId, data.nickname),
})),
options
);

Expand Down
9 changes: 9 additions & 0 deletions src/utils/converter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const getSafeNickname = (userId: number, nickname: string) => {
if (nickname) {
return nickname;
} else if (userId) {
return `익명${userId}`;
} else {
return '익명';
}
};

0 comments on commit 0f6a180

Please sign in to comment.