Skip to content

Commit adfe13e

Browse files
committed
Feat: 업로드 부분 form 태그로 변경 #65
1 parent 6b9241f commit adfe13e

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

+20-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import { useState } from 'react';
44
import Toast from '@/utils/notification';
5+
import { postBoard } from '@/service/board';
56
import Avatar from '../../../../ui/Avatar';
67
import Button from '../../../../ui/Button';
78
import FlexBox from '../../../../ui/FlexBox';
89

910
export default function Upload() {
1011
const [postText, setPostText] = useState('');
12+
const [isLoading, setIsLoading] = useState(false);
1113

1214
const maxCharacters = 100;
1315
const isOverMaxChar = postText.length > maxCharacters;
@@ -16,10 +18,24 @@ export default function Upload() {
1618
setPostText(event.target.value);
1719
};
1820

21+
const onUploadBoard = async (data: string) => {
22+
setIsLoading(true);
23+
try {
24+
const response = await postBoard({
25+
title: 'title',
26+
content: data,
27+
});
28+
} catch (error) {
29+
Toast.error('잠시 후 다시 시도해주세요.');
30+
} finally {
31+
setIsLoading(false);
32+
}
33+
};
34+
1935
return (
20-
<FlexBox
21-
direction="column"
22-
className="bg-primary-50 p-5 border-[1px] border-primary-300 rounded-[10px] w-full"
36+
<form
37+
onSubmit={onUploadBoard}
38+
className="flex flex-col bg-primary-50 p-5 border-[1px] border-primary-300 rounded-[10px] w-full"
2339
>
2440
<FlexBox justify="between" className="w-full gap-[24px]">
2541
<Avatar
@@ -63,6 +79,6 @@ export default function Upload() {
6379
</Button>
6480
<div className="mt-4" id="renderedText" />
6581
</FlexBox>
66-
</FlexBox>
82+
</form>
6783
);
6884
}

0 commit comments

Comments
 (0)