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

Kim, Subin's avatar
Kim, Subin committed
8
const TimeTable = () => {
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    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)
        }
    }

27
    async function deleteTime(timeId) {
28
29
        try {
            setError("")
30
            await timetableApi.remove(timeId)
31
32
33
34
35
36
37
            alert('해당 상영시간표 정보를 성공적으로 삭제하였습니다.')
            getTimeTable(selectDate)
        } catch (error) {
            catchErrors(error, setError)
        }
    }

Kim, Subin's avatar
Kim, Subin committed
38
    return (
39
        <div className="col-12 col-lg-6 ms-lg-1 mb-5">
40
            <HorizontalCalender selectDate={selectDate} setSelectDate={setSelectDate} />
41
            {timeList.length !== 0 ?
42
43
44
45
                timeList.map(el => <div className="mt-4">
                    <h5 className="mb-0">{el.theaterName}  / <p className="d-inline fs-6 mb-0">{el.theatertype.theaterTypeName}</p></h5>
                    {el.timetable.map(time => <div className="d-inline-flex flex-column m-2">
                        <div className="d-flex justify-content-end">
Kim, Subin's avatar
Kim, Subin committed
46
                            <button type="button" className={`btn btn-dark btn-sm shadow-none ${styles.customBtn}`} onClick={() => deleteTime(time.id)}>X</button>
47
48
49
50
51
52
53
54
                        </div>
                        <div className="card">
                            <div className="card-body py-1">{moment(time.start_time).format('HH:mm')} ~ {moment(time.end_time).format('HH:mm')}</div>
                            <div className="card-footer text-center py-1">{time.title}</div>
                        </div>
                    </div>)}
                </div>)
                : <p className="text-center mt-5 mb-0">서버에 저장되어 있는 상영시간표가 존재하지 않습니다.<br />아래의 양식을 작성해 새로운 상영시간표를 등록해주세요.</p>}
Kim, Subin's avatar
Kim, Subin committed
55
        </div>
Kim, Subin's avatar
Kim, Subin committed
56
57
58
59
    )
}

export default TimeTable