Skip to content

Commit 4d17f73

Browse files
committed
Feat: 업로드 post #65
1 parent db4d54a commit 4d17f73

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

components/pages/main/Feed/BoardsList/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export default function BoardsList({
3131
<FeedBoardCard
3232
userId={board.userName}
3333
content={board.title}
34-
imgs={[board.image[0], board.image[1], board.image[2]]}
34+
// TODO: 이미지 연결
35+
imgs={[]}
3536
setShowModal={setShowModal}
3637
comments={board.comments}
3738
/>

components/pages/main/Feed/FeedHeader/Upload.tsx

+17-8
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,34 @@ export default function Upload() {
1818
setPostText(event.target.value);
1919
};
2020

21-
const onUploadBoard = async (data: string) => {
21+
// 데이터 전송을 위한 함수
22+
const onUploadBoard = async () => {
23+
if (!postText || isOverMaxChar) {
24+
return; // Don't proceed if postText is empty or over the character limit.
25+
}
26+
2227
setIsLoading(true);
2328
try {
2429
const response = await postBoard({
2530
title: 'title',
26-
content: data,
31+
content: postText,
2732
});
33+
console.log(response);
34+
if (response.ok) {
35+
Toast.success('게시물이 성공적으로 업로드되었습니다.');
36+
setPostText('');
37+
} else {
38+
Toast.error('업로드에 실패했습니다. 잠시 후 다시 시도해주세요.');
39+
}
2840
} catch (error) {
29-
Toast.error('잠시 후 다시 시도해주세요.');
41+
Toast.error('오류가 발생했습니다. 잠시 후 다시 시도해주세요.');
3042
} finally {
3143
setIsLoading(false);
3244
}
3345
};
3446

3547
return (
36-
<form
37-
onSubmit={onUploadBoard}
38-
className="flex flex-col bg-primary-50 p-5 border-[1px] border-primary-300 rounded-[10px] w-full"
39-
>
48+
<form className="flex flex-col bg-primary-50 p-5 border-[1px] border-primary-300 rounded-[10px] w-full">
4049
<FlexBox justify="between" className="w-full gap-[24px]">
4150
<Avatar
4251
size="xxl"
@@ -73,7 +82,7 @@ export default function Upload() {
7382
size="lg"
7483
disabled={isOverMaxChar}
7584
className="w-40"
76-
onClickAction={() => Toast.success('성공')}
85+
onClickAction={() => onUploadBoard()}
7786
>
7887
업로드
7988
</Button>

service/board.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ export async function postBoard(postBoardData: PostBoardType) {
1515
const url = `/endpoint/api/board/register`;
1616
const formData = new FormData();
1717
const { title, content } = postBoardData;
18-
formData.append(title, content);
18+
formData.append('title', title);
19+
formData.append('content', content);
1920

2021
const response = await fetch(url, {
2122
method: 'POST',
2223
credentials: 'include',
24+
headers: {
25+
'Content-Type': 'multipart/form-data',
26+
},
2327
body: formData,
2428
});
25-
return response.json();
29+
// return response.json();
30+
const data = await response.json();
31+
console.log(data);
2632
}
2733

2834
export default async function getBoardList({

0 commit comments

Comments
 (0)