import { useState, useEffect } from "react"; import movieApi from "../../apis/movie.api.js"; import theaterApi from "../../apis/theater.api.js"; import catchErrors from "../../utils/catchErrors.js"; import styles from "./admin.module.scss"; const INIT_MOVIE = { movieId: 0, title: "", release_date: "", end_date: "", theater: [], times: [] } const TimeTableEditForm = () => { const [movieList, setMovieList] = useState([]) const [theater, setTheater] = useState([]) const [selectId, setSelectId] = useState(0) const [selectMovie, setSelectMovie] = useState({}) const [selectTheater, setSelectTheater] = useState(0) const [sendMovie, setSendMovie] = useState(INIT_MOVIE) const [error, setError] = useState("") useEffect(() => { getMoviesfromDB() getTheater() }, []) async function getMoviesfromDB() { try { setError("") const res = await movieApi.getListfromDB() setMovieList(res) } catch (error) { catchErrors(error, setError) } } async function getTheater() { try { setError("") const res = await theaterApi.getAll() console.log("res==", res) setTheater(res) } catch (error) { catchErrors(error, setError) } } async function handleSelect(e) { const { name, value } = e.target if (name === "movieId") { setSelectId(value) const res = await movieApi.getMovieInfofromTM(value) setSelectMovie({ ...res }) setSendMovie({ ...sendMovie, movieId: value, title: res.title, release_date: res.release_date }) } else setSelectTheater(value) } function handleChange(e) { const { name, value } = e.target setSendMovie({ ...sendMovie, [name]: value }) } async function handleSubmit(e) { e.preventDefault() try { setError("") alert("해당 상영시간표 정보 등록이 성공적으로 완료되었습니다.") window.location.reload() } catch (error) { catchErrors(error, setError) } } return (
) } export default TimeTableEditForm