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 (