import { useParams } from "react-router-dom"; import React, { useEffect, useState } from "react"; import RoomApi from "../../apis/room.api"; import catchErrors from "../../context/catchError"; const INIT_Room = { id: "", name: "", profileimg: "", }; const RoomSettingChange = () => { const { roomId } = useParams(); const [Room, setRoom] = useState(INIT_Room); const [error, setError] = useState(""); Room.id = roomId; async function getdata(Roomdata) { try { const data = await RoomApi.getRoom([Roomdata]); setRoom(data); console.log(data); } catch (error) { catchErrors(error, setError); } } useEffect(() => { getdata(roomId); }, []); const updateinfo = (event) => { const { name, value } = event.target; setRoom({ ...Room, [name]: value }); console.log(Room.name); }; const handleChange = async (event) => { const { files } = event.target; console.log("files:", files); let formData = new FormData(); formData.append("profileimg", files[0]); formData.append("id", roomId); try { const res = await RoomApi.profileimg(formData); // if (files) { // setRoom({ ...Room, profileimg: res }); // } else { // setRoom(); // } } catch (error) { catchErrors(error, setError); } }; const changeinfo = async (event) => { window.location.reload(); // window.location.href = window.location.href; const req = await RoomApi.changename(Room); }; return (
); }; export default RoomSettingChange;