import React, { useState } from 'react' import axios from 'axios'; import { Row, Col, Modal, Button, Form, Alert } from 'react-bootstrap'; import catchErrors from '../utils/catchErrors'; const INIT_ROOM = { roomName: '', interest: '', isOpen: false } function RoomMake(props) { const [room, setRoom] = useState(INIT_ROOM); const [error, setError] = useState(''); const [roomCode, setRoomCode] = useState('') const member = sessionStorage.getItem('userId'); const realTime = new Date().toISOString() async function recordEntryLog(Id) { const leaveInfo = { userId: member, roomCode: Id, leaveTime: realTime } try { const check = await axios.get('/room/entrylog', { params: leaveInfo }) if (check.data) { //있으면 put으로 await axios.put('/room/entrylog', leaveInfo) } else { //없으면 post await axios.post('/room/entrylog', leaveInfo) } } catch (error) { catchErrors(error, setError) } } function handleChange(event) { const { name, value } = event.target setRoom({ ...room, [name]: value, member }) // console.log(room) } async function handleSubmit(event) { event.preventDefault() try { setError('') let res = await axios.post('/room/makeRoom', room) const Id = res.data.roomId alert(`방암호는 ${Id}입니다`) props.handleCloseModal() setRoom(INIT_ROOM) // setRoomCode(Id) recordEntryLog(Id) } catch (error) { catchErrors(error, setError) } } return ( 방 생성 {error && {error} }
방 이름 관심 분야 공개방 setRoom({ ...room, isOpen: !room.isOpen })} /> { (room.isOpen) ? (

공개방으로 개설되어 공개방 목록에 공개되며, 코드를 공유하여 참가할 수도 있습니다.

) : (

비밀방으로 개설되며, 참여자들에게 코드를 공유해야합니다.

) }
) } export default RoomMake