TicketingPage.js 4.67 KB
Newer Older
1
import axios from 'axios'
Jiwon Yoon's avatar
Jiwon Yoon committed
2
3
4
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
5
import cinemaApi from "../apis/cinema.api.js"
Jiwon Yoon's avatar
Jiwon Yoon committed
6
7
8
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
9
import catchErrors from "../utils/catchErrors.js"
Jiwon Yoon's avatar
Jiwon Yoon committed
10

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

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

26
27
28
29
    useEffect(() => {
        getCinemaInfo()
    }, [])

Jiwon Yoon's avatar
Jiwon Yoon committed
30
31
32
    useEffect(() => {
        getMovieInfo()
    }, [ticketInfo])
Jiwon Yoon's avatar
Jiwon Yoon committed
33

Jiwon Yoon's avatar
Jiwon Yoon committed
34
35
36
37
38
    async function getMovieInfo() {
        try {
            const data = await movieApi.getMovieInfofromTM(ticketInfo.movieId)
            setMovieInfo(data)
        } catch (error) {
Kim, Subin's avatar
Kim, Subin committed
39
40
41
42
43
44
45
46
47
48
            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
49
50
        }
    }
51
52
53
54
55
56
57
58
59
    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
60
    return (
Jiwon Yoon's avatar
Jiwon Yoon committed
61
        <div className="container" style={{ backgroundColor: "black" }}>
Jiwon Yoon's avatar
Jiwon Yoon committed
62
            <div className="row justify-content-center my-5">
Jiwon Yoon's avatar
Jiwon Yoon committed
63
64
65
                <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
66
                </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
67
                <div className="col-sm-3 mb-4 ">
Jiwon Yoon's avatar
Jiwon Yoon committed
68
                    <h3 className="py-2 text-white text-center" style={{ border: "3px solid #000000", borderBottom: "3px solid #FEDC00" }}>극장</h3>
69
                    <TicketingTheater cinemaInfo={cinemaInfo} ticketInfo={ticketInfo} setTicketInfo={setTicketInfo} />
Jiwon Yoon's avatar
Jiwon Yoon committed
70
                </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
71
72
                <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>
73
                    <TicketingTimeTable ticketInfo={ticketInfo} cinemaInfo={cinemaInfo} />
Jiwon Yoon's avatar
Jiwon Yoon committed
74
75
                </div>
            </div>
Kim, Subin's avatar
Kim, Subin committed
76
            <div className="row p-3" style={{ backgroundColor: "#252525" }}>
Jiwon Yoon's avatar
Jiwon Yoon committed
77
78
79
80
81
82
83
                <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>
84
                    {movieInfo && ticketInfo.cinema
Jiwon Yoon's avatar
Jiwon Yoon committed
85
86
                        ? <ul>
                            <li>영화: {movieInfo.title}</li>
87
                            <li>극장: {ticketInfo.cinema}</li>
Jiwon Yoon's avatar
Jiwon Yoon committed
88
                            <li>일시: {ticketInfo.time}</li>
89
                            <li>상영관: {ticketInfo.selectedTheater}</li>
Jiwon Yoon's avatar
Jiwon Yoon committed
90
91
92
93
94
                        </ul>
                        : <div></div>}
                </div>
                <div className="col-sm-3 text-center">
                    <div className="mb-2" style={{ color: "white" }}>좌석선택</div>
95
                    {movieInfo && ticketInfo.cinema
Jiwon Yoon's avatar
Jiwon Yoon committed
96
97
                        ?
                        <Link to={{
Jiwon Yoon's avatar
Jiwon Yoon committed
98
                            pathname: `/ticket/seat`,
Kim, Subin's avatar
Kim, Subin committed
99
                            state: { ...ticketInfo, ...movieInfo }
Jiwon Yoon's avatar
Jiwon Yoon committed
100
101
102
                        }}>
                            <img className="border border-3 rounded-3" src="/images/icons8-arrow-white.png" alt="예매하기" />
                        </Link>
Kim, Subin's avatar
Kim, Subin committed
103
                        : <img className="border border-3 rounded-3" src="/images/icons8-arrow-white.png" alt="예매하기" />
Jiwon Yoon's avatar
Jiwon Yoon committed
104
105
106
                    }
                </div>
            </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
107
108
109
110
111
        </div>
    )
}

export default TicketingPage