1
1
import styled from 'styled-components' ;
2
2
import React , { useState , KeyboardEvent } from 'react' ;
3
+ import axios from 'axios' ;
3
4
import { ReactComponent as DeleteTag } from '../../assets/svg/deleteTag.svg' ;
4
5
import { ReactComponent as Up } from '../../assets/svg/up.svg' ;
5
6
import { ReactComponent as Down } from '../../assets/svg/down.svg' ;
7
+ import { API } from '../../config' ;
6
8
7
9
export default function CreateRoomForm ( ) {
8
10
const [ newTag , setNewTag ] = useState ( '' ) ;
9
11
const [ title , setTitle ] = useState ( '' ) ;
10
- const [ detail , setDetail ] = useState ( '' ) ;
11
- // const [total, setTotal] = useState(1 );
12
- // const [theme, setTheme] = useState('fire ');
12
+ const [ details , setDetails ] = useState ( '' ) ;
13
+ const [ total , setTotal ] = useState ( '' ) ;
14
+ const [ theme , setTheme ] = useState ( '' ) ;
13
15
const [ tags , setTags ] = useState ( [ ] ) ;
14
16
15
17
const handleRoomNameChange = ( e ) => {
16
18
setTitle ( e . target . value ) ;
17
19
} ;
18
20
19
- const handleRoomDescriptionChange = ( e ) => {
20
- setDetail ( e . target . value ) ;
21
+ const handleDetailsChange = ( e ) => {
22
+ setDetails ( e . target . value ) ;
21
23
} ;
22
24
23
25
const handleTagChange = ( e ) => {
@@ -34,18 +36,41 @@ export default function CreateRoomForm() {
34
36
}
35
37
} ;
36
38
39
+ const handleTotalChange = ( e ) => {
40
+ setTotal ( e . target . value ) ;
41
+ } ;
42
+
43
+ const handleThemeChange = ( e ) => {
44
+ setTheme ( e . target . value ) ;
45
+ } ;
46
+
37
47
const onAddTag = ( ) => {
38
48
setTags ( [ ...tags , newTag . trim ( ) ] ) ;
39
49
setNewTag ( '' ) ;
40
50
} ;
41
51
42
52
const onDeleteTag = ( e , index ) => {
43
- console . log ( e , index ) ;
44
53
setTags ( tags . filter ( ( _ , i ) => i !== index ) ) ;
45
54
} ;
46
55
47
- const onSubmit = ( e ) => {
48
- console . log ( e ) ;
56
+ const onSubmit = ( ) => {
57
+ axios
58
+ . post ( API . ROOM , {
59
+ moderator : {
60
+ uid : localStorage . getItem ( 'uid' ) ,
61
+ } ,
62
+ title,
63
+ details,
64
+ tags,
65
+ total : Number ( total ) ,
66
+ theme,
67
+ } )
68
+ . then ( ( res ) => {
69
+ console . log ( '[success]' , res ) ;
70
+ } )
71
+ . catch ( ( err ) => {
72
+ console . log ( '[error] ' , err ) ;
73
+ } ) ;
49
74
} ;
50
75
51
76
return (
@@ -66,8 +91,8 @@ export default function CreateRoomForm() {
66
91
< Input
67
92
id = "description"
68
93
type = "text"
69
- value = { detail }
70
- onChange = { handleRoomDescriptionChange }
94
+ value = { details }
95
+ onChange = { handleDetailsChange }
71
96
placeholder = "설명을 입력해주세요."
72
97
/>
73
98
</ Section >
@@ -99,6 +124,8 @@ export default function CreateRoomForm() {
99
124
id = "total"
100
125
placeholder = "최대 인원 수를 선택해주세요."
101
126
required
127
+ value = { total }
128
+ onChange = { handleTotalChange }
102
129
>
103
130
< option value = "" disabled selected >
104
131
최대 인원 수를 선택해주세요.
@@ -117,15 +144,21 @@ export default function CreateRoomForm() {
117
144
< Section >
118
145
< Label htmlFor = "theme" > 테마 *</ Label >
119
146
< div style = { { width : '100%' , display : 'flex' } } >
120
- < Select id = "theme" placeholder = "테마를 선택해주세요." required >
147
+ < Select
148
+ id = "theme"
149
+ placeholder = "테마를 선택해주세요."
150
+ required
151
+ value = { theme }
152
+ onChange = { handleThemeChange }
153
+ >
121
154
< option value = "" disabled selected >
122
155
원하는 방 테마를 선택해주세요.
123
156
</ option >
124
- < option value = "theme1 " > 모닥불</ option >
125
- < option value = "theme2 " > 바다</ option >
126
- < option value = "theme3 " > 캠핑</ option >
127
- < option value = "theme4 " > 여행</ option >
128
- < option value = "theme5 " > 우주인</ option >
157
+ < option value = "fire " > 모닥불</ option >
158
+ < option value = "ocean " > 바다</ option >
159
+ < option value = "camping " > 캠핑</ option >
160
+ < option value = "travel " > 여행</ option >
161
+ < option value = "cosmos " > 우주인</ option >
129
162
</ Select >
130
163
< SelectIcon >
131
164
< Up />
@@ -138,7 +171,7 @@ export default function CreateRoomForm() {
138
171
) ;
139
172
}
140
173
141
- const Form = styled . div `
174
+ const Form = styled . form `
142
175
display: flex;
143
176
flex-direction: column;
144
177
align-items: flex-start;
@@ -197,6 +230,9 @@ const TagComponent = styled.div`
197
230
const TagButton = styled . button `
198
231
cursor: pointer;
199
232
margin-left: 1rem;
233
+ display: flex;
234
+ flex-direction: column;
235
+ align-items: center;
200
236
` ;
201
237
202
238
const Tag = styled . div `
0 commit comments