TicketingPage.js 4.33 KB
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
2
3
import { useState, useEffect } from 'react'
import { Link } from 'react-router-dom'
import movieApi from '../apis/movie.api.js'
Kim, Subin's avatar
Kim, Subin committed
4
import cinemaApi from "../apis/cinema.api.js"
Jiwon Yoon's avatar
Jiwon Yoon committed
5
6
7
import TicketingMovie from "../components/TicketingMovie/TicketingMovie.js"
import TicketingTheater from "../components/TicketingTheater/TicketingTheater.js"
import TicketingTimeTable from "../components/TicketingTimeTable/TicketingTimeTable.js"
Kim, Subin's avatar
Kim, Subin committed
8
import catchErrors from "../utils/catchErrors.js"
Jiwon Yoon's avatar
Jiwon Yoon committed
9

Jiwon Yoon's avatar
Jiwon Yoon committed
10
11
12
const TicketingPage = ({ location }) => {
    const [ticketInfo, setTicketInfo] = useState({
        ...location.state,
Kim, Subin's avatar
Kim, Subin committed
13
14
        cinema: "",
        selectedTheater: "1",
Jiwon Yoon's avatar
Jiwon Yoon committed
15
        time: "2021/07/21 10:00"
Jiwon Yoon's avatar
Jiwon Yoon committed
16
    })
Kim, Subin's avatar
Kim, Subin committed
17
    const [cinemaInfo, setCinemaInfo] = useState({})
Jiwon Yoon's avatar
Jiwon Yoon committed
18
    const [movieInfo, setMovieInfo] = useState()
Kim, Subin's avatar
Kim, Subin committed
19
20
21
22
23
    const [error, setError] = useState("")

    useEffect(() => {
        getCinemaInfo()
    }, [])
Jiwon Yoon's avatar
Jiwon Yoon committed
24
25
26
27

    useEffect(() => {
        getMovieInfo()
    }, [ticketInfo])
Jiwon Yoon's avatar
Jiwon Yoon committed
28

Jiwon Yoon's avatar
Jiwon Yoon committed
29
30
31
32
33
    async function getMovieInfo() {
        try {
            const data = await movieApi.getMovieInfofromTM(ticketInfo.movieId)
            setMovieInfo(data)
        } catch (error) {
Kim, Subin's avatar
Kim, Subin committed
34
35
36
37
38
39
40
41
42
43
            catchErrors(error, setError)
        }
    }

    async function getCinemaInfo() {
        try {
            const response = await cinemaApi.getCinemaInfo()
            setCinemaInfo(response.data)
        } catch (error) {
            catchErrors(error, setError)
Jiwon Yoon's avatar
Jiwon Yoon committed
44
45
        }
    }
Jiwon Yoon's avatar
Jiwon Yoon committed
46

Jiwon Yoon's avatar
Jiwon Yoon committed
47
    return (
Jiwon Yoon's avatar
Jiwon Yoon committed
48
        <div className="container" style={{ backgroundColor: "black" }}>
Jiwon Yoon's avatar
Jiwon Yoon committed
49
            <div className="row justify-content-center my-5">
Jiwon Yoon's avatar
Jiwon Yoon committed
50
51
52
                <div className="col-sm-4 mb-4 ">
                    <h3 className="py-2 text-white text-center" style={{ border: "3px solid #000000", borderBottom: "3px solid #FEDC00" }}>영화</h3>
                    <TicketingMovie ticketInfo={ticketInfo} setTicketInfo={setTicketInfo} />
Jiwon Yoon's avatar
Jiwon Yoon committed
53
                </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
54
                <div className="col-sm-3 mb-4 ">
Kim, Subin's avatar
Kim, Subin committed
55
56
                    <h3 className="py-2 text-white text-center" style={{ border: "3px solid #000000", borderBottom: "3px solid #FEDC00" }}>극장</h3>
                    <TicketingTheater cinemaInfo={cinemaInfo} ticketInfo={ticketInfo} setTicketInfo={setTicketInfo} />
Jiwon Yoon's avatar
Jiwon Yoon committed
57
                </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
58
59
                <div className="col-sm-5 mb-4 ">
                    <h3 className="py-2 text-white text-center" style={{ border: "3px solid #000000", borderBottom: "3px solid #FEDC00" }}>시간표</h3>
Kim, Subin's avatar
Kim, Subin committed
60
                    <TicketingTimeTable ticketInfo={ticketInfo} cinemaInfo={cinemaInfo} />
Jiwon Yoon's avatar
Jiwon Yoon committed
61
62
                </div>
            </div>
Kim, Subin's avatar
Kim, Subin committed
63
            <div className="row p-3" style={{ backgroundColor: "#252525" }}>
Jiwon Yoon's avatar
Jiwon Yoon committed
64
65
66
67
68
69
70
                <div className="col-sm-3 border-end text-center">
                    {movieInfo
                        ? <img style={{ maxHeight: "10rem" }} src={`https://image.tmdb.org/t/p/original${movieInfo.poster_path}`} alt="영화포스터" />
                        : <div className="mb-2" style={{ color: "white" }}>영화선택</div>}
                </div>
                <div className="col-sm-6 border-end" style={{ color: "white" }}>
                    <div className="mb-2  text-center">극장선택</div>
Kim, Subin's avatar
Kim, Subin committed
71
                    {movieInfo && ticketInfo.cinema
Jiwon Yoon's avatar
Jiwon Yoon committed
72
73
                        ? <ul>
                            <li>영화: {movieInfo.title}</li>
Kim, Subin's avatar
Kim, Subin committed
74
                            <li>극장: {ticketInfo.cinema}</li>
Jiwon Yoon's avatar
Jiwon Yoon committed
75
                            <li>일시: {ticketInfo.time}</li>
Kim, Subin's avatar
Kim, Subin committed
76
                            <li>상영관: {ticketInfo.selectedTheater}</li>
Jiwon Yoon's avatar
Jiwon Yoon committed
77
78
79
80
81
                        </ul>
                        : <div></div>}
                </div>
                <div className="col-sm-3 text-center">
                    <div className="mb-2" style={{ color: "white" }}>좌석선택</div>
Kim, Subin's avatar
Kim, Subin committed
82
                    {movieInfo && ticketInfo.cinema
Jiwon Yoon's avatar
Jiwon Yoon committed
83
84
                        ?
                        <Link to={{
Jiwon Yoon's avatar
Jiwon Yoon committed
85
                            pathname: `/ticket/seat`,
Kim, Subin's avatar
Kim, Subin committed
86
                            state: { ...ticketInfo, ...movieInfo }
Jiwon Yoon's avatar
Jiwon Yoon committed
87
88
89
                        }}>
                            <img className="border border-3 rounded-3" src="/images/icons8-arrow-white.png" alt="예매하기" />
                        </Link>
Kim, Subin's avatar
Kim, Subin committed
90
                        : <img className="border border-3 rounded-3" src="/images/icons8-arrow-white.png" alt="예매하기" />
Jiwon Yoon's avatar
Jiwon Yoon committed
91
92
93
                    }
                </div>
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
94
95
96
97
98
        </div>
    )
}

export default TicketingPage