import { useState, useEffect } from "react"; import theaterApi from "../../apis/theater.api.js"; import catchErrors from "../../utils/catchErrors.js"; import styles from "./admin.module.scss"; const INIT_THEATER = { theaterName: "", theaterType: 0, rows: 1, columns: 1 } const TheaterEditForm = ({ edit, formRef }) => { const [theater, setTheater] = useState(INIT_THEATER) const [types, setTypes] = useState([]) const [error, setError] = useState("") useEffect(() => { getTypeList() }, []) useEffect(() => { setTheater({ ...theater, ...edit }) }, [edit]) async function getTypeList() { try { setError("") const resTypes = await theaterApi.getTheaterType() setTypes(resTypes) } catch (error) { catchErrors(error, setError) } } function handleChange(e) { const { name, value } = e.target setTheater({ ...theater, [name]: value }) } async function handleSubmit(e) { e.preventDefault() try { setError("") await theaterApi.sendData(theater) alert("해당 상영관 정보 등록이 성공적으로 완료되었습니다.") window.location.reload() } catch (error) { catchErrors(error, setError) } } return (
) } export default TheaterEditForm