TheaterPage.js 4.52 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import { useState, useEffect } from 'react'
Kim, Subin's avatar
Kim, Subin committed
2
3
import TicketFeeTable from '../components/Admin/TicketFeeTable'
import TheaterInfo from '../components/TheaterInfo'
Kim, Subin's avatar
Kim, Subin committed
4
import cinemaApi from "../apis/cinema.api.js"
Kim, Subin's avatar
Kim, Subin committed
5
import theaterApi  from '../apis/theater.api.js'
Kim, Subin's avatar
Kim, Subin committed
6
import catchErrors from "../utils/catchErrors.js"
Jiwon Yoon's avatar
Jiwon Yoon committed
7

8
const TheaterPage = () => {
Kim, Subin's avatar
Kim, Subin committed
9
    const [theaterTypeList, setTheaterTypeList] = useState([])
Kim, Subin's avatar
Kim, Subin committed
10
    const [ticketFeeInfo, setTicketFeeInfo] = useState("")
Jiwon Yoon's avatar
Jiwon Yoon committed
11
    const [state, setState] = useState(0)
Kim, Subin's avatar
Kim, Subin committed
12
13
14
15
16
    const [selectTheater, setSelectTheater] = useState(0)
    const [error, setError] = useState("")

    useEffect(() => {
        getTicketFeeInfo()
Kim, Subin's avatar
Kim, Subin committed
17
        getTheaterType()
Kim, Subin's avatar
Kim, Subin committed
18
19
    }, [])

Kim, Subin's avatar
Kim, Subin committed
20
    async function getTheaterType() {
Kim, Subin's avatar
Kim, Subin committed
21
22
23
24
25
26
27
28
29
        try {
            setError("")
            const res = await theaterApi.getTheaterType()
            setTheaterTypeList(res)
        } catch (error) {
            catchErrors(error, setError)
        }
    }

Kim, Subin's avatar
Kim, Subin committed
30
31
32
33
34
35
36
37
38
39
    async function getTicketFeeInfo() {
        try {
            setError("")
            const res = await cinemaApi.getCinemaInfo()
            setTicketFeeInfo(res.moreFeeInfo)
        } catch (error) {
            catchErrors(error, setError)
        }
    }

40
    return (
Kim, Subin's avatar
Kim, Subin committed
41
        <>
Kim, Subin's avatar
Kim, Subin committed
42
            <div>
Jiwon Yoon's avatar
Jiwon Yoon committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
                <ul className="nav nav-tabs justify-content-center my-4 border-0" id="myTab" role="tablist">
                    <li className="nav-item" role="presentation">
                        <button className="nav-link active mx-auto" style={{ color: "white", borderColor: "black", backgroundColor: "black", borderBottom: state === 0 ? "3px solid" : "none", borderBottomColor: state === 0 ? "#FEDC00" : "black" }} id="overview-tab" data-bs-toggle="tab" data-bs-target="#overview" type="button" role="tab" aria-controls="overview" aria-selected="true" onClick={() => setState(0)}>극장정보</button>
                    </li>
                    <li className="nav-item" role="presentation">
                        <button className="nav-link mx-auto" style={{ color: "white", borderColor: "black", backgroundColor: "black", borderBottom: state === 1 ? "3px solid" : "none", borderBottomColor: state === 1 ? "#FEDC00" : "black" }} id="stillcut-tab" data-bs-toggle="tab" data-bs-target="#stillcut" type="button" role="tab" aria-controls="stillcut" aria-selected="false" onClick={() => setState(1)}>상영시간표</button>
                    </li>
                    <li className="nav-item" role="presentation">
                        <button className="nav-link mx-auto" style={{ color: "white", borderColor: "black", backgroundColor: "black", borderBottom: state === 2 ? "3px solid" : "none", borderBottomColor: state === 2 ? "#FEDC00" : "black" }} id="review-tab" data-bs-toggle="tab" data-bs-target="#review" type="button" role="tab" aria-controls="review" aria-selected="false" onClick={() => setState(2)}>관람료</button>
                    </li>
                </ul>
            </div>
            <div className="tab-content text-center" id="myTabContent" style={{ color: "white" }}>
                <div className="tab-pane fade show active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
Kim, Subin's avatar
Kim, Subin committed
57
                    <TheaterInfo />
Jiwon Yoon's avatar
Jiwon Yoon committed
58
59
                </div>
                <div className="tab-pane fade" id="stillcut" role="tabpanel" aria-labelledby="stillcut-tab">
60
                    <div className="pb-5">상영시간표</div>
Jiwon Yoon's avatar
Jiwon Yoon committed
61
62
                </div>
                <div className="tab-pane fade" id="review" role="tabpanel" aria-labelledby="review-tab">
Kim, Subin's avatar
Kim, Subin committed
63
                    <div className="d-flex justify-content-center">
Kim, Subin's avatar
Kim, Subin committed
64
                        <div className="col-sm-9 pb-5">
Kim, Subin's avatar
Kim, Subin committed
65
66
67
68
69
70
71
                            <nav aria-label="breadcrumb">
                                <ol className={"breadcrumb" + (theaterTypeList.length === 0 ? " d-flex justify-content-center" : "")}>
                                    {theaterTypeList.length !== 0 ? theaterTypeList.map(theater => <li className="breadcrumb-item" key={theater.id} onClick={() => setSelectTheater(theater.id)} style={{ cursor: "pointer" }}>{theater.theaterTypeName}</li>)
                                        : <li>등록된 관람료 관련 정보가 없습니다.</li>}
                                </ol>
                            </nav>
                            <TicketFeeTable selectTheater={selectTheater} />
Kim, Subin's avatar
Kim, Subin committed
72
                            <div className="text-start mt-5" style={{ whiteSpace: "pre-line" }}>{ticketFeeInfo}</div>
Kim, Subin's avatar
Kim, Subin committed
73
74
                        </div>
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
75
76
                </div>
            </div>
Kim, Subin's avatar
Kim, Subin committed
77
        </>
78
79
80
81
    )
}

export default TheaterPage