import { Link, useHistory } from 'react-router-dom' import { useState, useEffect, useRef } from 'react' import { Modal } from 'bootstrap' import CountButton from '../components/CountButton' import SeatTable from '../components/SeatTable/SeatTable' import styles from '../components/SeatTable/seatTable.module.scss' import axios from 'axios' import { useAuth } from '../context/auth_context.js' const TicketingSeatPage = ({ location }) => { const history = useHistory() const modalRef = useRef(null) const modal = useRef() const { user } = useAuth() const [ticketInfo, setTicketInfo] = useState({ ...location.state }) const [theaterInfo, setTheaterInfo] = useState() const [selectedSeats, setSelectedSeats] = useState([]) const [reservedSeats, setReservedSeats] = useState([]) const [count, setCount] = useState({ adult: 0, teenager: 0, elderly: 0 }) useEffect(() => { getInfo() }, []) async function getInfo() { try { const response = await axios.post('/api/theater/getInfo', { theaterName: 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) } } function loginModal() { if (user.role==="member") { history.push("/payment", { ...ticketInfo, selectedSeats: selectedSeats, ...count }); } else { modal.current = new Modal(modalRef.current) modal.current?.show() } } return ( <>