From 04d74f2ff2bacdf5de61372e08515177d717f57b Mon Sep 17 00:00:00 2001 From: euijin Date: Wed, 20 Nov 2024 19:24:26 +0900 Subject: [PATCH] =?UTF-8?q?fix=20::=20=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=AD?= =?UTF-8?q?=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Apis/Notices/index.ts | 12 ++++++---- src/Apis/Notices/response.ts | 24 +++++++++---------- src/Components/Notice/AttachedBox/index.tsx | 4 ++-- .../NoticePage/NoticeDetailPage/index.tsx | 5 +++- .../NoticePage/NoticeWritePage/index.tsx | 4 ++-- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/Apis/Notices/index.ts b/src/Apis/Notices/index.ts index e49031c..c7d4955 100644 --- a/src/Apis/Notices/index.ts +++ b/src/Apis/Notices/index.ts @@ -66,11 +66,14 @@ export const useNoticeDetailData = (noticeId: string) => { title: data.title, content: data.content, created_at: new Date(data.created_at).toISOString(), - attachments: data.attachments.map((attachment: any) => ({ - url: attachment.url, - type: attachment.type, - })), + attachments: data.attachments + ? data.attachments.map((attachment: any) => ({ + url: attachment.url, + type: attachment.type, + })) + : [], }; + setNoticeDetail(fetchedNoticeDetail); }) .catch(() => { @@ -120,7 +123,6 @@ export const useNoticeListData = () => { useEffect(() => { fetchNoticeList(); - }, [fetchNoticeList]); return { notices }; diff --git a/src/Apis/Notices/response.ts b/src/Apis/Notices/response.ts index 56d2e55..cb53453 100644 --- a/src/Apis/Notices/response.ts +++ b/src/Apis/Notices/response.ts @@ -1,21 +1,19 @@ export interface NoticeListResponse { - id: number - title: string - created_at: string + id: number; + title: string; + created_at: string; } export interface NoticeDetailResponse { - title: string; - content: string; - created_at: string; - attachments?: AttachmentResponse[]; + title: string; + content: string; + created_at: string; + attachments?: AttachmentResponse[] | null; } -export type AttachmentType = - | "FILE" - | "URL" +export type AttachmentType = 'FILE' | 'URL'; export interface AttachmentResponse { - url: string; - type: AttachmentType; -} \ No newline at end of file + url: string; + type: AttachmentType; +} diff --git a/src/Components/Notice/AttachedBox/index.tsx b/src/Components/Notice/AttachedBox/index.tsx index 54f9c5a..1c3e759 100644 --- a/src/Components/Notice/AttachedBox/index.tsx +++ b/src/Components/Notice/AttachedBox/index.tsx @@ -4,7 +4,7 @@ import * as _ from './style'; import axios from 'axios'; interface PropsType { - props: AttachmentResponse[]; + props: AttachmentResponse[] | null | undefined; } export function AttachedBox({ props }: PropsType) { @@ -43,7 +43,7 @@ export function AttachedBox({ props }: PropsType) { <_.AttachedWrapper> <_.AttachmentTitle>첨부자료 <_.Attachments> - {props.map((attachment, index) => ( + {props?.map((attachment, index) => ( <_.Attachment key={index}>
{file_name_regex(attachment.url)}
<_.Date>{date} <_.Contents>{noticeDetail?.content} - + {noticeDetail?.attachments && + noticeDetail.attachments.length > 0 && ( + + )} diff --git a/src/Pages/NoticePage/NoticeWritePage/index.tsx b/src/Pages/NoticePage/NoticeWritePage/index.tsx index 158a95d..3cec791 100644 --- a/src/Pages/NoticePage/NoticeWritePage/index.tsx +++ b/src/Pages/NoticePage/NoticeWritePage/index.tsx @@ -94,9 +94,9 @@ export function NoticeWritePage() { writeNotice({ title, content, - attachments: [{url: '', type: 'FILE'}], + attachments: [{} as AttachmentRequest], }); - navigate('/Notice') + navigate('/Notice'); } };