From 5b65a4165f48159fc3a8e0b544d70608ab70ae27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B4=80=EC=8B=9D?= <39869096+gwansikk@users.noreply.github.com> Date: Wed, 27 Mar 2024 03:15:13 +0900 Subject: [PATCH] =?UTF-8?q?refactor(member):=20=EB=A7=88=EC=9D=B4=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EB=82=B4=EC=97=AD=20=EC=83=81=ED=98=B8?= =?UTF-8?q?=EC=9E=91=EC=9A=A9=20=EC=B6=94=EA=B0=80=20(#78)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../my/MyHistorySection/MyHistorySection.tsx | 47 ++++++++++++++++--- apps/member/src/constants/path.ts | 5 +- apps/member/src/types/board.ts | 5 +- apps/member/src/types/comment.ts | 7 +++ 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/apps/member/src/components/my/MyHistorySection/MyHistorySection.tsx b/apps/member/src/components/my/MyHistorySection/MyHistorySection.tsx index e0e49dd1..42aca508 100644 --- a/apps/member/src/components/my/MyHistorySection/MyHistorySection.tsx +++ b/apps/member/src/components/my/MyHistorySection/MyHistorySection.tsx @@ -4,6 +4,10 @@ import { toYYMMDD } from '@utils/date'; import type { BoardItem } from '@type/board'; import type { NotificationItem } from '@type/notification'; import { CommentItem } from '@type/comment'; +import { PATH_FINDER } from '@constants/path'; +import { titleToCategory } from '@utils/community'; +import useModal from '@hooks/common/useModal'; +import { useCallback } from 'react'; interface MyHistorySectionProps { title: string; @@ -11,25 +15,56 @@ interface MyHistorySectionProps { } const MyHistorySection = ({ title, data }: MyHistorySectionProps) => { + const { openModal } = useModal(); + + const handleAlarmClick = useCallback( + (content: string) => { + openModal({ + title: '알림', + content: content, + }); + }, + [openModal], + ); + return (
{data.map((item) => { - if ('content' in item) { - // NotificationItem or CommentItem - const { id, content, createdAt } = item as NotificationItem; + if ('boardId' in item) { + // CommentItem + const { id, boardId, boardCategory, content, createdAt } = + item as CommentItem; + return ( + +

{content}

+

{toYYMMDD(createdAt)}

+
+ ); + } else if ('content' in item) { + // NotificationItem + const { id, content, createdAt } = item as CommentItem; return ( - + handleAlarmClick(content)}>

{content}

{toYYMMDD(createdAt)}

); } else if ('title' in item) { // BoardItem - const { id, title, createdAt } = item as BoardItem; + const { id, category, title, createdAt } = item as BoardItem; return ( - +

{title}

{toYYMMDD(createdAt)}

diff --git a/apps/member/src/constants/path.ts b/apps/member/src/constants/path.ts index b2284b04..1ee9b9c9 100644 --- a/apps/member/src/constants/path.ts +++ b/apps/member/src/constants/path.ts @@ -1,5 +1,6 @@ -import type { IDType } from '@type/api'; import { createPath } from '@utils/api'; +import type { IDType } from '@type/api'; +import type { CommunityCategoryType } from '@type/community'; export const NOT_FOUND_IMG = '/not_found.webp'; @@ -36,7 +37,7 @@ export const PATH = { export const PATH_FINDER = { NEWS_POST: (id: IDType) => createPath(PATH.NEWS, id), BLOG_POST: (id: IDType) => createPath(PATH.BLOG, id), - COMMUNITY_POST: (sort: IDType, id: IDType) => + COMMUNITY_POST: (sort: CommunityCategoryType, id: IDType) => createPath(PATH.COMMUNITY, sort, id), LIBRARY_DETAIL: (id: IDType) => createPath(PATH.LIBRARY, id), ACTIVITY_DETAIL: (id: IDType) => createPath(PATH.ACTIVITY, id), diff --git a/apps/member/src/types/board.ts b/apps/member/src/types/board.ts index 162b3fb3..39954d44 100644 --- a/apps/member/src/types/board.ts +++ b/apps/member/src/types/board.ts @@ -1,6 +1,9 @@ +import type { CommunityCategoryKorType } from './community'; + export interface BoardItem { id: number; - memberName: string; + category: CommunityCategoryKorType; title: string; + writer: string; createdAt: string; } diff --git a/apps/member/src/types/comment.ts b/apps/member/src/types/comment.ts index f9c495ea..95fc5526 100644 --- a/apps/member/src/types/comment.ts +++ b/apps/member/src/types/comment.ts @@ -1,8 +1,15 @@ +import type { CommunityCategoryKorType } from './community'; + export interface CommentItem { id: number; writerName: string; writerImageUrl: string; content: string; + boardId: number; + boardCategory: CommunityCategoryKorType; + hasLikeByMe: boolean; + likes: number; + writer: string; createdAt: string; }