Skip to content

Commit 2445283

Browse files
authored
Merge pull request #89 from SWM-FIRE/FIRE-394-fe-be에-방-생성-api-요청-보내기
Fire 394 fe be에 방 생성 api 요청 보내기
2 parents 48e08b3 + 48478bf commit 2445283

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

src/components/main/CreateRoomForm.tsx

+53-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import styled from 'styled-components';
22
import React, { useState, KeyboardEvent } from 'react';
3+
import axios from 'axios';
34
import { ReactComponent as DeleteTag } from '../../assets/svg/deleteTag.svg';
45
import { ReactComponent as Up } from '../../assets/svg/up.svg';
56
import { ReactComponent as Down } from '../../assets/svg/down.svg';
7+
import { API } from '../../config';
68

79
export default function CreateRoomForm() {
810
const [newTag, setNewTag] = useState('');
911
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('');
1315
const [tags, setTags] = useState([]);
1416

1517
const handleRoomNameChange = (e) => {
1618
setTitle(e.target.value);
1719
};
1820

19-
const handleRoomDescriptionChange = (e) => {
20-
setDetail(e.target.value);
21+
const handleDetailsChange = (e) => {
22+
setDetails(e.target.value);
2123
};
2224

2325
const handleTagChange = (e) => {
@@ -34,18 +36,41 @@ export default function CreateRoomForm() {
3436
}
3537
};
3638

39+
const handleTotalChange = (e) => {
40+
setTotal(e.target.value);
41+
};
42+
43+
const handleThemeChange = (e) => {
44+
setTheme(e.target.value);
45+
};
46+
3747
const onAddTag = () => {
3848
setTags([...tags, newTag.trim()]);
3949
setNewTag('');
4050
};
4151

4252
const onDeleteTag = (e, index) => {
43-
console.log(e, index);
4453
setTags(tags.filter((_, i) => i !== index));
4554
};
4655

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+
});
4974
};
5075

5176
return (
@@ -66,8 +91,8 @@ export default function CreateRoomForm() {
6691
<Input
6792
id="description"
6893
type="text"
69-
value={detail}
70-
onChange={handleRoomDescriptionChange}
94+
value={details}
95+
onChange={handleDetailsChange}
7196
placeholder="설명을 입력해주세요."
7297
/>
7398
</Section>
@@ -99,6 +124,8 @@ export default function CreateRoomForm() {
99124
id="total"
100125
placeholder="최대 인원 수를 선택해주세요."
101126
required
127+
value={total}
128+
onChange={handleTotalChange}
102129
>
103130
<option value="" disabled selected>
104131
최대 인원 수를 선택해주세요.
@@ -117,15 +144,21 @@ export default function CreateRoomForm() {
117144
<Section>
118145
<Label htmlFor="theme">테마 *</Label>
119146
<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+
>
121154
<option value="" disabled selected>
122155
원하는 방 테마를 선택해주세요.
123156
</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>
129162
</Select>
130163
<SelectIcon>
131164
<Up />
@@ -138,7 +171,7 @@ export default function CreateRoomForm() {
138171
);
139172
}
140173

141-
const Form = styled.div`
174+
const Form = styled.form`
142175
display: flex;
143176
flex-direction: column;
144177
align-items: flex-start;
@@ -197,6 +230,9 @@ const TagComponent = styled.div`
197230
const TagButton = styled.button`
198231
cursor: pointer;
199232
margin-left: 1rem;
233+
display: flex;
234+
flex-direction: column;
235+
align-items: center;
200236
`;
201237

202238
const Tag = styled.div`

src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const BASE_URL = process.env.REACT_APP_BASE_URL;
22
const API_VER = '/api/v1';
33
const USER = '/users/';
4-
const ROOM = '/rooms/';
4+
const ROOM = '/rooms';
55
const SOCKET = '/socket/room';
66

77
export const API = {

0 commit comments

Comments
 (0)