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

Jiwon Yoon's avatar
Jiwon Yoon committed
8
9
10
11
12
13
14
const TicketingPage = ({ location }) => {
    const [ticketInfo, setTicketInfo] = useState({
        ...location.state,
        theater:"",
        selectedCinemaNum: 0,
        time: {}
    })
Jiwon Yoon's avatar
Jiwon Yoon committed
15
    const [theaterInfo, setTheaterInfo] = useState({
Jiwon Yoon's avatar
Jiwon Yoon committed
16
17
        theater: ["Butter Studio 조치원"],
        cinemaNum: [1, 2, 3, 4]
Jiwon Yoon's avatar
Jiwon Yoon committed
18
    })
Jiwon Yoon's avatar
Jiwon Yoon committed
19
20
21
22
23
    const [movieInfo, setMovieInfo] = useState()

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

Jiwon Yoon's avatar
Jiwon Yoon committed
25
26
27
28
29
30
31
32
33
    async function getMovieInfo() {
        try {
            const data = await movieApi.getMovieInfofromTM(ticketInfo.movieId)
            console.log(data)
            setMovieInfo(data)
        } catch (error) {
            console.log(error)
        }
    }
Jiwon Yoon's avatar
Jiwon Yoon committed
34

Jiwon Yoon's avatar
Jiwon Yoon committed
35
    return (
Jiwon Yoon's avatar
Jiwon Yoon committed
36
        <div className="container" style={{ backgroundColor: "black" }}>
Jiwon Yoon's avatar
Jiwon Yoon committed
37
38
39
            <div>
                {console.log(location.state)}
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
40
            <div className="row justify-content-center my-5">
Jiwon Yoon's avatar
Jiwon Yoon committed
41
42
43
                <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
44
                </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
45
46
47
                <div className="col-sm-3 mb-4 ">
                    <h3 className="py-2 mb-3 text-white text-center" style={{ border: "3px solid #000000", borderBottom: "3px solid #FEDC00" }}>극장</h3>
                    <TicketingTheater theaterInfo={theaterInfo} ticketInfo={ticketInfo} setTicketInfo={setTicketInfo} />
Jiwon Yoon's avatar
Jiwon Yoon committed
48
                </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
49
50
51
                <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>
                    <TicketingTimeTable ticketInfo={ticketInfo} theaterInfo={theaterInfo} />
Jiwon Yoon's avatar
Jiwon Yoon committed
52
53
                </div>
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
            <div className="row p-3" style={{ backgroundColor: "#252525"}}>
                <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>
                    {movieInfo && ticketInfo.theater
                        ? <ul>
                            <li>영화: {movieInfo.title}</li>
                            <li>극장: {ticketInfo.theater}</li>
                            <li>일시: </li>
                            <li>상영관: </li>
                        </ul>
                        : <div></div>}
                </div>
                <div className="col-sm-3 text-center">
                    <div className="mb-2" style={{ color: "white" }}>좌석선택</div>
                    {movieInfo && ticketInfo.theater
                        ?
                        <Link to={{
                            pathname: `/seat`,
                            state: {}
                        }}>
                            <img className="border border-3 rounded-3" src="/images/icons8-arrow-white.png" alt="예매하기" />
                        </Link>
                        :
                        <img className="border border-3 rounded-3" src="/images/icons8-arrow-white.png" alt="예매하기" />
Jiwon Yoon's avatar
Jiwon Yoon committed
83

Jiwon Yoon's avatar
Jiwon Yoon committed
84
85
86
                    }
                </div>
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
87
88
89
90
91
        </div>
    )
}

export default TicketingPage