import axios from 'axios' import { useEffect, useState } from 'react' import Kakaopay from '../../components/Kakaopay' import { useAuth } from '../../context/auth_context' import catchErrors from '../../utils/catchErrors' import styles from './PaymentPage.module.scss' const Payment = ({ location }) => { const [ticketInfo, setTicketInfo] = useState({ ...location.state }) const [error, setError] = useState("") const [userInfo, setUserInfo] = useState() const [guestInfo, setGuestInfo] = useState({}) const [guestID, setGuestID] = useState() const { user } = useAuth() useEffect(() => { console.log(user.id) if (user.id > 0) { getUserInfo() } }, []) async function getUserInfo() { try { const response = await axios.post(`/api/auth/getuserinfo`, { id: user.id }) setUserInfo(response.data) } catch (error) { catchErrors(error, setError) } } function handleChangeGuest(e) { setGuestInfo({ ...guestInfo, [e.target.name]: String(e.target.value) }) } async function handleClickGuest() { try { const response = await axios.post('/api/auth/guest/save', { ...guestInfo }) setGuestID(response.data.id) // console.log(response.data) } catch (error) { catchErrors(error, setError) } } async function reservationComplete() { try { if (userInfo) { const response = await axios.post(`/api/reservation/save`, { userType: "member", user: userInfo.id, ...ticketInfo, payment: "카카오페이", timetable: 1 }) console.log("회원예매완료===", response.data) } else { if (guestID) { const response = await axios.post(`/api/reservation/save`, { userType: "guest", user: guestID, ...ticketInfo, payment: "카카오페이", timetable: 1 }) console.log("비회원예매완료===", response.data) } else { alert("비회원 정보를 모두 입력 후 저장버튼을 눌러주세요.") } } const responseEmail = await axios.post('/api/email/send', { ...ticketInfo, ...userInfo, ...guestInfo, }) console.log("이메일전송완료===", responseEmail.data) } catch (error) { catchErrors(error, setError) } } return (
※ 비회원 정보 오기입 시 예매 내역 확인/취소 및 티켓 발권이 어려울 수 있으니 다시 한번 확인해 주시기 바랍니다.