TicketingPage.js 4.34 KB
Newer Older
1
import axios from 'axios'
Jiwon Yoon's avatar
Jiwon Yoon committed
2
3
4
5
6
7
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
8

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

19
20
21
22
    useEffect(() => {
        getCinemaInfo()
    }, [])

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

Jiwon Yoon's avatar
Jiwon Yoon committed
27
28
29
30
31
32
33
34
    async function getMovieInfo() {
        try {
            const data = await movieApi.getMovieInfofromTM(ticketInfo.movieId)
            setMovieInfo(data)
        } catch (error) {
            console.log(error)
        }
    }
35
36
37
38
39
40
41
42
43
    async function getCinemaInfo() {
        try {
            const response = await axios.get('/api/info/cinema')
            console.log(response.data)
            setCinemaInfo(response.data)
        } catch (error) {
            console.log(error)
        }
    }
Jiwon Yoon's avatar
Jiwon Yoon committed
44
    return (
Jiwon Yoon's avatar
Jiwon Yoon committed
45
        <div className="container" style={{ backgroundColor: "black" }}>
Jiwon Yoon's avatar
Jiwon Yoon committed
46
            <div>
Jiwon Yoon's avatar
Jiwon Yoon committed
47
                {console.log(ticketInfo)}
Jiwon Yoon's avatar
Jiwon Yoon committed
48
            </div>
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
55
                <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>
56
                    <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>
60
                    <TicketingTimeTable ticketInfo={ticketInfo} cinemaInfo={cinemaInfo} />
Jiwon Yoon's avatar
Jiwon Yoon committed
61
62
                </div>
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
63
64
65
66
67
68
69
70
            <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>
71
                    {movieInfo && ticketInfo.cinema
Jiwon Yoon's avatar
Jiwon Yoon committed
72
73
                        ? <ul>
                            <li>영화: {movieInfo.title}</li>
74
                            <li>극장: {ticketInfo.cinema}</li>
Jiwon Yoon's avatar
Jiwon Yoon committed
75
                            <li>일시: {ticketInfo.time}</li>
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>
82
                    {movieInfo && ticketInfo.cinema
Jiwon Yoon's avatar
Jiwon Yoon committed
83
84
                        ?
                        <Link to={{
Jiwon Yoon's avatar
Jiwon Yoon committed
85
86
                            pathname: `/ticket/seat`,
                            state: {...ticketInfo,...movieInfo}
Jiwon Yoon's avatar
Jiwon Yoon committed
87
88
89
90
91
                        }}>
                            <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
92

Jiwon Yoon's avatar
Jiwon Yoon committed
93
94
95
                    }
                </div>
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
96
97
98
99
100
        </div>
    )
}

export default TicketingPage