import { useState, useEffect } from "react";
import moment from 'moment';
import HorizontalCalender from "../Calender/HorizontalCalender.js";
import timetableApi from "../../apis/timetable.api.js";
import catchErrors from "../../utils/catchErrors.js";
import styles from "./admin.module.scss";
const TimeTable = ({ ticketInfo = { movieId: 0 }, setTicketInfo }) => {
const [selectDate, setSelectDate] = useState(moment().format('YYYY-MM-DD'))
const [timeList, setTimeList] = useState([])
const [error, setError] = useState("")
useEffect(() => {
getTimeTable(selectDate, ticketInfo.movieId)
}, [selectDate])
useEffect(() => {
getTimeTable(selectDate, ticketInfo.movieId)
}, [ticketInfo.movieId])
async function getTimeTable(selectDate, movieId) {
try {
setError("")
const res = await timetableApi.getAll(selectDate, movieId)
setTimeList(res)
} catch (error) {
catchErrors(error, setError)
}
}
async function deleteTime(timeId) {
try {
setError("")
await timetableApi.remove(timeId)
alert('해당 상영시간표 정보를 성공적으로 삭제하였습니다.')
getTimeTable(selectDate)
} catch (error) {
catchErrors(error, setError)
}
}
function handleClick(time) {
const date = new Date(time.start_time)
let hours = date.getHours()
let mins = date.getMinutes()
if (hours <= 9) hours = '0' + hours
if (mins <= 9) mins = '0' + mins
setTicketInfo({
...ticketInfo,
timetableId: time.id,
time: time.date.split('T')[0] + " " + hours + ":" + mins,
selectedTheater: time.theater.theaterName
})
}
return (
<>
{el.theaterTypeName}
{el.timetable.map(time => { console.log("timetable==",time) if (ticketInfo) return서버에 저장되어 있는 상영시간표가 존재하지 않습니다.
아래의 양식을 작성해 새로운 상영시간표를 등록해주세요.