Skip to content

Commit

Permalink
merge :: 공지사항 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
eejx0 authored Nov 20, 2024
2 parents d666c13 + 04d74f2 commit dfc1d63
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
12 changes: 7 additions & 5 deletions src/Apis/Notices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -120,7 +123,6 @@ export const useNoticeListData = () => {

useEffect(() => {
fetchNoticeList();

}, [fetchNoticeList]);

return { notices };
Expand Down
24 changes: 11 additions & 13 deletions src/Apis/Notices/response.ts
Original file line number Diff line number Diff line change
@@ -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;
}
url: string;
type: AttachmentType;
}
4 changes: 2 additions & 2 deletions src/Components/Notice/AttachedBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -43,7 +43,7 @@ export function AttachedBox({ props }: PropsType) {
<_.AttachedWrapper>
<_.AttachmentTitle>첨부자료</_.AttachmentTitle>
<_.Attachments>
{props.map((attachment, index) => (
{props?.map((attachment, index) => (
<_.Attachment key={index}>
<div>{file_name_regex(attachment.url)}</div>
<Icon
Expand Down
5 changes: 4 additions & 1 deletion src/Pages/NoticePage/NoticeDetailPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ export function NoticeDetailPage() {
</_.HeaderWrapper>
<_.Date>{date}</_.Date>
<_.Contents>{noticeDetail?.content}</_.Contents>
<AttachedBox props={noticeDetail?.attachments || []} />
{noticeDetail?.attachments &&
noticeDetail.attachments.length > 0 && (
<AttachedBox props={noticeDetail.attachments} />
)}
</_.Box>
</_.Background>
</_.Wrapper>
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/NoticePage/NoticeWritePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ export function NoticeWritePage() {
writeNotice({
title,
content,
attachments: [{url: '', type: 'FILE'}],
attachments: [{} as AttachmentRequest],
});
navigate('/Notice')
navigate('/Notice');
}
};

Expand Down

0 comments on commit dfc1d63

Please sign in to comment.