diff --git a/ticketping/src/pages/SelectSchedule.js b/ticketping/src/pages/SelectSchedule.js index 663fb1f..1ab92c6 100644 --- a/ticketping/src/pages/SelectSchedule.js +++ b/ticketping/src/pages/SelectSchedule.js @@ -1,10 +1,10 @@ import React, { useEffect, useState } from "react"; import { useParams, useNavigate, useLocation } from "react-router-dom"; -import { useCheckExpiredToken } from "../component/CheckExpiredToken"; +import { useCheckExpiredToken } from "../component/CheckExpiredToken"; import { axiosInstance } from "../api"; import { useAppContext } from "../store"; -import { Calendar, Button } from 'antd'; -import dayjs from 'dayjs'; +import { Calendar, Button } from "antd"; +import dayjs from "dayjs"; import "../style/SelectSchedule.css"; export default function SelectSchedule() { @@ -14,28 +14,51 @@ export default function SelectSchedule() { const { performance } = location.state || {}; const { checkExpiredToken } = useCheckExpiredToken(); - const { store: { jwtToken } } = useAppContext(); + const { + store: { jwtToken }, + } = useAppContext(); const headers = { Authorization: jwtToken }; const [schedules, setSchedules] = useState([]); const [selectedDateId, setSelectedDateId] = useState(null); + useEffect(() => { + const extendWorkingQueueTokenTTL = async () => { + try { + await axiosInstance.post( + `/api/v1/working-queue/extend-ttl?performanceId=${performance.id}`, + {}, + { headers } + ); + } catch (err) { + checkExpiredToken(err.response.data); + } + }; + + extendWorkingQueueTokenTTL(); + }, []); + useEffect(() => { const fetchSchedules = async () => { try { - const response = await axiosInstance.get(`/api/v1/performances/${id}/schedules`, { headers }); + const response = await axiosInstance.get( + `/api/v1/performances/${id}/schedules`, + { headers } + ); setSchedules(response.data.data); } catch (err) { checkExpiredToken(err.response.data); - } + } }; fetchSchedules(); }, []); const disabledDate = (current) => { - const hasSchedule = schedules.some(schedule => schedule.startDate.startsWith(current.format('YYYY-MM-DD'))); - return !hasSchedule; + const hasSchedule = schedules.some((schedule) => + schedule.startDate.startsWith(current.format("YYYY-MM-DD")) + ); + return !hasSchedule; }; const monthCellRender = (value) => { @@ -43,22 +66,20 @@ export default function SelectSchedule() { const year = value.year(); const daysWithSchedules = schedules - .filter(schedule => { + .filter((schedule) => { const scheduleDate = dayjs(schedule.startDate); - return ( - scheduleDate.year() === year && - scheduleDate.month() === month - ); + return scheduleDate.year() === year && scheduleDate.month() === month; }) - .map(schedule => schedule.date()); + .map((schedule) => schedule.date()); return (
- {daysWithSchedules.length > 0 && daysWithSchedules.map((currentDay) => ( -
- {currentDay} -
- ))} + {daysWithSchedules.length > 0 && + daysWithSchedules.map((currentDay) => ( +
+ {currentDay} +
+ ))}
); }; @@ -66,10 +87,10 @@ export default function SelectSchedule() { const headerRender = ({ value, onChange }) => { return (
- {dayjs(value).format('MMMM YYYY')} -
- onChange(value.subtract(1, 'month'))}>< - onChange(value.add(1, 'month'))}>> + {dayjs(value).format("MMMM YYYY")} +
+ onChange(value.subtract(1, "month"))}>< + onChange(value.add(1, "month"))}>>
); @@ -77,14 +98,17 @@ export default function SelectSchedule() { const handleDateSelect = () => { if (selectedDateId) { - navigate(`/performance/${id}/schedule/${selectedDateId}/seat`, { state: { performance } }); + navigate(`/performance/${id}/schedule/${selectedDateId}/seat`, { + state: { performance }, + }); } else { - } }; const onDateSelect = (date) => { - const schedule = schedules.find(schedule => schedule.startDate.startsWith(date.format('YYYY-MM-DD'))); + const schedule = schedules.find((schedule) => + schedule.startDate.startsWith(date.format("YYYY-MM-DD")) + ); if (schedule) { setSelectedDateId(schedule.id); } @@ -94,19 +118,16 @@ export default function SelectSchedule() {

일정 선택

-
-