import { useEffect, useState } from "react"; import axios from 'axios' const INIT_ROOM = { roomName: '', owner: '123456', member: '123456', profileimg: [], } const AddRoom = () => { 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 } const { name, owner, member, profileimg } = room; return (
참여중인 방목록
{/* 방참여하기 모달 */}
{/* 방생성하기 모달 */}
); }; export default AddRoom;