TimeTable.js 2.03 KB
Newer Older
1
2
3
4
5
6
import { useState, useEffect } from "react";
import moment from 'moment';
import Calender from "../Calender/Calender.js";
import timetableApi from "../../apis/timetable.api.js";
import catchErrors from "../../utils/catchErrors.js";

Kim, Subin's avatar
Kim, Subin committed
7
const TimeTable = () => {
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    const [selectDate, setSelectDate] = useState(moment().format('YYYY-MM-DD'))
    const [timeList, setTimeList] = useState([])
    const [error, setError] = useState("")

    useEffect(() => {
        getTimeTable(selectDate)
    }, [selectDate])

    async function getTimeTable() {
        try {
            setError("")
            const res = await timetableApi.getAll(selectDate)
            setTimeList(res)
        } catch (error) {
            catchErrors(error, setError)
        }
    }

    async function deleteTime() {
        try {
            setError("")
            await timetableApi.remove()
            alert('해당 상영시간표 정보를 성공적으로 삭제하였습니다.')
            getTimeTable(selectDate)
        } catch (error) {
            catchErrors(error, setError)
        }
    }

Kim, Subin's avatar
Kim, Subin committed
37
    return (
Kim, Subin's avatar
Kim, Subin committed
38
        <div className="col-12 col-lg-6">
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
            {console.log("list==", timeList)}
            <Calender selectDate={selectDate} setSelectDate={setSelectDate} />
            {timeList.length !== 0 ?
                timeList.map(el => <>
                    <h5>{el.theaterName} </h5>
                    {/* {arr = el.timetable.map(time => <div className="card">
                        <div className="card-body">{moment(time.start_time, 'hh:mm')} ~ {moment(time.end_time, 'hh:mm')}</div>
                    </div>
                    )
                    } */}
                    {/* {el.timetable.map(time => {
                        if (el.id === time.id) return <div className="card">
                        <div className="card-body">{moment(time.start_time, 'hh:mm')} ~ {moment(time.end_time, 'hh:mm')}</div>
                    </div>
                    })} */}
                </>)
                : <></>}
Kim, Subin's avatar
Kim, Subin committed
56
        </div>
Kim, Subin's avatar
Kim, Subin committed
57
58
59
60
    )
}

export default TimeTable