AddRoom.js 7.11 KB
Newer Older
우지원's avatar
0716    
우지원 committed
1
2
3
4
5
6
7
8
9
10
import { useEffect, useState } from "react";
import axios from 'axios'

const INIT_ROOM = {
  roomName: '',
  owner: '123456',
  member: '123456',
  profileimg: [],
}

Kim, Chaerin's avatar
Kim, Chaerin committed
11
const AddRoom = () => {
우지원's avatar
0716    
우지원 committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  const [room, setRoom] = useState(INIT_ROOM)
  const [error, setError] = useState("");
  const [success, setSuccess] = useState(false)
  const [disabled, setDisabled] = useState(true)

  useEffect(() => {
    setDisabled(
      !(
        room.name &&
        room.owner &&
        room.member &&
        room.profileimg
      )
    );
  }, [room]);

  //LocalStorage에 user id를 저장할때 id를 owner, member에 저장하기
  //const userId = localStorage.getItem('id')
  // setRoom({...room, [owner]: userId})
  // setRoom({...room, [member]: userId})

  function handleChange(event) {
    const { name, value } = event.target
    setRoom({ ...room, [name]: value })
    console.log(room)
  }

  async function handleSubmit(event) {
    event.preventDefault()
    try {
      console.log('룸룸', room)
      let res = await axios.post("/room/create", room)
      const Id = res.data.id
      alert(`방참여코드는 ${Id}입니다`)
      setSuccess(true)
    } catch (error) {
      // catchErrors(error, setError);
    } finally {
      // setLoading(false);
    }
  }

  if (success) {
    console.log('success', success)
    alert('룸생성이 완료되었습니다!')
    //return <Redirect to='/' />
  }

  const { name, owner, member, profileimg } = room;

Kim, Chaerin's avatar
Kim, Chaerin committed
62
  return (
우지원's avatar
우지원 committed
63
64
65
66
    <div>
      <div className="mx-4 my-3 d-flex justify-content-between">
        <div className="fs-4">
          참여중인 방목록
Kim, Chaerin's avatar
Kim, Chaerin committed
67
68
69
        </div>
        <button
          type="button"
우지원's avatar
우지원 committed
70
          className="py-1 px-2"
Kim, Chaerin's avatar
Kim, Chaerin committed
71
72
          data-bs-toggle="modal"
          data-bs-target="#myModal"
우지원's avatar
우지원 committed
73
74
75
76
77
78
79
80
          style={{
            display: "flex",
            flexDirection: "column",
            borderStyle: "solid",
            borderRadius: "5px",
            backgroundColor: "#E0CEE8",
            borderColor: "#E0CEE8",
          }}
Kim, Chaerin's avatar
Kim, Chaerin committed
81
        >
우지원's avatar
우지원 committed
82
          추가
Kim, Chaerin's avatar
Kim, Chaerin committed
83
84
        </button>
      </div>
우지원's avatar
0628    
우지원 committed
85

Kim, Chaerin's avatar
Kim, Chaerin committed
86
87
88
89
90
91
92
93
94
95
      <div className="modal" id="myModal" tabIndex="-1" aria-hidden="true">
        <div className="modal-dialog">
          <div className="modal-content">
            <div className="modal-header">
              <button
                type="button"
                className="btn-close"
                data-bs-dismiss="modal"
                aria-label="Close"
              ></button>
우지원's avatar
0628    
우지원 committed
96
            </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
97
            <div className="modal-body">
우지원's avatar
우지원 committed
98
99
              <div className="row justify-content-evenly mt-4 mb-4 fs-6">
                <div className="col-6 d-flex justify-content-center">
Kim, Chaerin's avatar
Kim, Chaerin committed
100
101
                  <button
                    type="button"
우지원's avatar
우지원 committed
102
                    className="p-3"
Kim, Chaerin's avatar
Kim, Chaerin committed
103
104
105
106
107
108
109
                    data-bs-toggle="modal"
                    data-bs-target="#joinModal"
                    style={{
                      display: "flex",
                      flexDirection: "column",
                      borderStyle: "solid",
                      borderRadius: "5px",
우지원's avatar
우지원 committed
110
111
                      backgroundColor: "#E0CEE8",
                      borderColor: "#E0CEE8",
Kim, Chaerin's avatar
Kim, Chaerin committed
112
113
                    }}
                  >
우지원's avatar
우지원 committed
114
115
116
                    <div style={{ width: "6rem" }} >
                      방참여하기
                    </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
117
118
                  </button>
                </div>
우지원's avatar
우지원 committed
119
                <div className="col-6 d-flex justify-content-center">
Kim, Chaerin's avatar
Kim, Chaerin committed
120
121
                  <button
                    type="button"
우지원's avatar
우지원 committed
122
                    className="p-3"
Kim, Chaerin's avatar
Kim, Chaerin committed
123
124
125
126
127
128
129
                    data-bs-toggle="modal"
                    data-bs-target="#makeModal"
                    style={{
                      display: "flex",
                      flexDirection: "column",
                      borderStyle: "solid",
                      borderRadius: "5px",
우지원's avatar
우지원 committed
130
131
                      backgroundColor: "#f5cfe3",
                      borderColor: "#f5cfe3",
Kim, Chaerin's avatar
Kim, Chaerin committed
132
133
                    }}
                  >
우지원's avatar
우지원 committed
134
135
136
                    <div style={{ width: "6rem" }} >
                      방생성하기
                    </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
137
                  </button>
우지원's avatar
0628    
우지원 committed
138
                </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
139
              </div>
우지원's avatar
0628    
우지원 committed
140
            </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
141
142
143
          </div>
        </div>
      </div>
우지원's avatar
0628    
우지원 committed
144

Kim, Chaerin's avatar
Kim, Chaerin committed
145
      {/* 방참여하기 모달 */}
우지원's avatar
0716    
우지원 committed
146
147
148
149
150
151
152
153
154
155
156
157
      <div className="form" onSubmit={handleSubmit}>
        <div className="modal" id="joinModal" tabIndex="-1" aria-hidden="true">
          <div className="modal-dialog">
            <div className="modal-content">
              <div className="modal-header">
                <div>방참여하기</div>
                <button
                  type="button"
                  className="btn-close"
                  data-bs-dismiss="modal"
                  aria-label="Close"
                ></button>
Kim, Chaerin's avatar
Kim, Chaerin committed
158
              </div>
우지원's avatar
0716    
우지원 committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
              <div className="modal-body">
                <div className="input-group mb-3">
                  <input
                    type="text"
                    className="form-control"
                    placeholder="참여코드를 입력하세요"
                    aria-label="참여코드를 입력하세요"
                    aria-describedby="basic-addon1"
                  />
                </div>
                <div className="modal-footer">
                  <button type="submit" className="btn btn-primary">
                    확인
                  </button>
                </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
174
175
176
177
178
              </div>
            </div>
          </div>
        </div>
      </div>
우지원's avatar
0628    
우지원 committed
179

우지원's avatar
0716    
우지원 committed
180

Kim, Chaerin's avatar
Kim, Chaerin committed
181
      {/* 방생성하기 모달 */}
우지원's avatar
0716    
우지원 committed
182
183
184
185
186
187
188
189
190
191
192
193
      <div className="form" onSubmit={handleSubmit}>
        <div className="modal" id="makeModal" tabIndex="-1" aria-hidden="true">
          <div className="modal-dialog">
            <div className="modal-content">
              <div className="modal-header">
                <div>방생성하기</div>
                <button
                  type="button"
                  className="btn-close"
                  data-bs-dismiss="modal"
                  aria-label="Close"
                ></button>
Kim, Chaerin's avatar
Kim, Chaerin committed
194
              </div>
우지원's avatar
0716    
우지원 committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
              <div className="modal-body">
                <h6>방프로필사진</h6>
                <div className="mb-4">
                  <input
                    type="file"
                    className="upload-hidden"
                    onChange={handleChange}
                    name="profileimg"
                    value={room.profileimg} />
                </div>
                <h6>방이름</h6>
                <div className="input-group">
                  <input
                    type="text"
                    className="form-control"
                    placeholder="방이름을 입력해주세요"
                    aria-label="방이름 입력해주세요"
                    aria-describedby="basic-addon1"
                    onChange={handleChange}
                    name="name"
                    value={room.name}
                  />
                </div>
                <div className="modal-footer">
                  <button type="submit" className="btn btn-primary">
                    생성
                  </button>
                </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
223
              </div>
우지원's avatar
0628    
우지원 committed
224
            </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
225
226
227
          </div>
        </div>
      </div>
우지원's avatar
우지원 committed
228
    </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
229
230
  );
};
Kim, Chaerin's avatar
Kim, Chaerin committed
231
232

export default AddRoom;