TicketingSeatPage.js 8.15 KB
Newer Older
1
2
3
import { Link, useHistory } from 'react-router-dom'
import { useState, useEffect, useRef } from 'react'
import { Modal } from 'bootstrap'
Jiwon Yoon's avatar
Jiwon Yoon committed
4
5
import CountButton from '../components/CountButton'
import SeatTable from '../components/SeatTable/SeatTable'
6
7
8
import styles from '../components/SeatTable/seatTable.module.scss'
import axios from 'axios'
import { useAuth } from '../context/auth_context.js'
Jiwon Yoon's avatar
Jiwon Yoon committed
9
10

const TicketingSeatPage = ({ location }) => {
11
12
13
14
    const history = useHistory()
    const modalRef = useRef(null)
    const modal = useRef()
    const { user } = useAuth()
Jiwon Yoon's avatar
Jiwon Yoon committed
15
    const [ticketInfo, setTicketInfo] = useState({ ...location.state })
16
    const [theaterInfo, setTheaterInfo] = useState()
Jiwon Yoon's avatar
Jiwon Yoon committed
17
    const [selectedSeats, setSelectedSeats] = useState([])
18
    const [reservedSeats, setReservedSeats] = useState([])
Jiwon Yoon's avatar
Jiwon Yoon committed
19
20
21
22
23
    const [count, setCount] = useState({
        adult: 0,
        teenager: 0,
        elderly: 0
    })
Jiwon Yoon's avatar
Jiwon Yoon committed
24

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

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    async function getInfo() {
        try {
            const response = await axios.post('/api/theater/getInfo', {
                theaterNum: ticketInfo.selectedTheater
            })
            console.log(response.data)
            setTheaterInfo(response.data)
            const response2 = await axios.post('/api/reservation/findreservation', {
                timetable: 1
            })
            console.log(response2.data)
            const reserve = response2.data.map((el) =>
                el.row + '-' + el.col
            )
            setReservedSeats(reserve)
        } catch (error) {
            console.log(error)
        }
    }
Jiwon Yoon's avatar
Jiwon Yoon committed
48

49
50
51
52
53
54
55
56
57
58
    function loginModal() {
        if (user) {
            history.push("/payment", {
                ...ticketInfo, selectedSeats: selectedSeats, ...count
            });
        } else {
            modal.current = new Modal(modalRef.current)
            modal.current?.show()
        }
    }
Jiwon Yoon's avatar
Jiwon Yoon committed
59

60
61
    return (
        <>
62
            <div ref={modalRef} className="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabIndex="-1" aria-labelledby="staticBackdropLabel" aria-hidden={modal}>
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
                <div className="modal-dialog">
                    <div className="modal-content">
                        { }
                        <div className="modal-header">
                            <h5 className="modal-title" id="staticBackdropLabel">로그인이 필요한 서비스입니다.</h5>
                            <button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div className="modal-body">
                            로그인을 하시겠습니까? 비회원예매로 진행하시겠습니까?
                        </div>
                        <div className="modal-footer">
                            <Link to={{ pathname: '/login' }}>
                                <button type="button" className="btn btn-secondary" data-bs-dismiss="modal" >
                                    로그인
                                </button>
                            </Link>
                            <Link to={{
                                pathname: `/payment`,
                                state: { ...ticketInfo, selectedSeats: selectedSeats, ...count }
                            }}>
                                <button type="button" className="btn btn-primary" data-bs-dismiss="modal">비회원예매</button>
                            </Link>
                        </div>
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
87
88
                </div>
            </div>
89
90
91
92
93
94
95
            <div className="container" style={{ color: "white" }}>
                {console.log(ticketInfo)}
                {console.log(reservedSeats)}
                <div className="row justify-content-center my-5">
                    <div className="col-sm-4 mb-3 ">
                        <h3 className="py-2 text-white text-center" style={{ border: "3px solid #000000", borderBottom: "3px solid #FEDC00" }}>좌석선택</h3>
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
96
                </div>
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
                <div className="row justify-content-center my-3">
                    <div className="col-sm-6 mb-4 text-center">
                        <div className="row">

                            <div className="col-sm-6 text-end">
                                <div className="my-1">일반</div>
                                <div className="my-1">청소년</div>
                                <div className="my-1">경로우대</div>
                            </div>
                            <div className="col-sm-6 text-start">
                                <CountButton name="adult" count={count} setCount={setCount} />
                                <CountButton name="teenager" count={count} setCount={setCount} />
                                <CountButton name="elderly" count={count} setCount={setCount} />
                            </div>
                        </div>
                    </div>
                    <div className="col-sm-6 mb-4 p-2 text-center" style={{ backgroundColor: '#252525' }}>
                        <div>{ticketInfo.cinema} | {ticketInfo.selectedTheater}</div>
                        <div>{ticketInfo.title}</div>
                        <div>{ticketInfo.time}</div>
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
118
                </div>
119
120
121
122
123
124
125
126
127
128
129
130
131
132
                <div className="row justify-content-center border p-5 ">
                    <div className="col-sm-8">
                        <SeatTable count={count} setSelectedSeats={setSelectedSeats} selectedSeats={selectedSeats} theaterInfo={theaterInfo} reservedSeats={reservedSeats} />
                    </div>
                    <div className="col-sm-4 mt-5">
                        <div>
                            <button className={styles.on} style={{ height: '1rem', width: '1rem' }} disabled></button>
                            <span> 선택됨</span>
                        </div>
                        <div>
                            <button className={styles.btnBlock} style={{ height: '1rem', width: '1rem' }} disabled></button>
                            <span> 선택불가</span>
                        </div>
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
133
                </div>
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
                <div className="row p-3 mt-5" style={{ backgroundColor: "#252525" }}>
                    <div className="col-sm-3 border-end text-center">
                        {ticketInfo
                            ? <img style={{ maxHeight: "10rem" }} src={`https://image.tmdb.org/t/p/original${ticketInfo.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>
                        {ticketInfo
                            ? <ul>
                                <li>영화: {ticketInfo.title}</li>
                                <li>극장: {ticketInfo.cinema}</li>
                                <li>일시: 2021/07/21 10:00 </li>
                                <li>상영관: 3</li>
                                <li>좌석: {selectedSeats}</li>
                            </ul>
                            : <div></div>}
                    </div>
                    <div className="col-sm-3 text-center">
                        <div className="mb-2" style={{ color: "white" }}>결제하기</div>
                        {ticketInfo
                            ?
                            <button onClick={loginModal} style={{ backgroundColor: '#252525', border: 0 }} >
                                <img className="border border-3 rounded-3" src="/images/icons8-arrow-white.png" alt="결제하기" />
                            </button>
                            :
                            <button disabled>
                                <img className="border border-3 rounded-3" src="/images/icons8-arrow-white.png" alt="결제하기" />
                            </button>
Jiwon Yoon's avatar
Jiwon Yoon committed
163

164
165
                        }
                    </div>
Jiwon Yoon's avatar
Jiwon Yoon committed
166
167
                </div>
            </div>
168
        </>
Jiwon Yoon's avatar
Jiwon Yoon committed
169
170
171
172
    )
}

export default TicketingSeatPage