Skip to content

Commit ef9a451

Browse files
committed
Fix: Upload 요청 수정 #65
1 parent e965317 commit ef9a451

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

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

+17-15
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import FlexBox from '../../../../ui/FlexBox';
99

1010
export default function Upload() {
1111
const [postText, setPostText] = useState('');
12-
const [isLoading, setIsLoading] = useState(false);
12+
const [isUploading, setIsUploading] = useState(false);
1313

1414
const maxCharacters = 100;
1515
const isOverMaxChar = postText.length > maxCharacters;
@@ -21,17 +21,15 @@ export default function Upload() {
2121
// 데이터 전송을 위한 함수
2222
const onUploadBoard = async () => {
2323
if (!postText || isOverMaxChar) {
24-
return; // Don't proceed if postText is empty or over the character limit.
24+
return;
2525
}
26-
27-
setIsLoading(true);
26+
setIsUploading(true);
2827
try {
2928
const response = await postBoard({
3029
title: 'title',
3130
content: postText,
3231
});
33-
console.log(response);
34-
if (response.ok) {
32+
if (response.content) {
3533
Toast.success('게시물이 성공적으로 업로드되었습니다.');
3634
setPostText('');
3735
} else {
@@ -40,7 +38,7 @@ export default function Upload() {
4038
} catch (error) {
4139
Toast.error('오류가 발생했습니다. 잠시 후 다시 시도해주세요.');
4240
} finally {
43-
setIsLoading(false);
41+
setIsUploading(false);
4442
}
4543
};
4644

@@ -78,14 +76,18 @@ export default function Upload() {
7876
>
7977
파일
8078
</Button>
81-
<Button
82-
size="lg"
83-
disabled={isOverMaxChar}
84-
className="w-40"
85-
onClickAction={() => onUploadBoard()}
86-
>
87-
업로드
88-
</Button>
79+
{isUploading ? (
80+
<div>업로드 중</div>
81+
) : (
82+
<Button
83+
size="lg"
84+
disabled={isOverMaxChar}
85+
className="w-40"
86+
onClickAction={() => onUploadBoard()}
87+
>
88+
업로드
89+
</Button>
90+
)}
8991
<div className="mt-4" id="renderedText" />
9092
</FlexBox>
9193
</form>

service/board.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@ interface TempPostListApiProps {
1111
}
1212

1313
export async function postBoard(postBoardData: PostBoardType) {
14-
const url = `/endpoint/api/board/register`;
15-
const formData = new FormData();
16-
const { title, content } = postBoardData;
17-
formData.append('title', title);
18-
formData.append('content', content);
14+
const url = `endpoint/api/board/register`;
1915

2016
const response = await fetch(url, {
2117
method: 'POST',
2218
credentials: 'include',
2319
headers: {
24-
'Content-Type': 'multipart/form-data',
20+
'Content-Type': 'application/json',
2521
},
26-
body: formData,
22+
body: JSON.stringify(postBoardData),
2723
});
2824
return response.json();
2925
}

0 commit comments

Comments
 (0)