Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

공지사항 버그 수정 #89

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading