Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions src/routes/guards/reservationGuard.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import { Navigate, Outlet, useParams } from 'react-router-dom';
import { useGetLessonDetail } from '@/pages/class/apis/queries';
import { ROUTES_CONFIG } from '@/routes/routesConfig';
import { WITHDRAW_USER_NAME } from '@/shared/constants/withdrawUser';
// import { Navigate, Outlet, useParams } from 'react-router-dom';
// import { useGetLessonDetail } from '@/pages/class/apis/queries';
// import { ROUTES_CONFIG } from '@/routes/routesConfig';
// import { WITHDRAW_USER_NAME } from '@/shared/constants/withdrawUser';

export const ReservationGuard = () => {
const { id } = useParams<{ id: string }>();
const lessonId = Number(id);
// export const ReservationGuard = () => {
// const { id } = useParams<{ id: string }>();
// const lessonId = Number(id);

const isValidLessonId = Number.isInteger(lessonId) && lessonId > 0;
// const isValidLessonId = Number.isInteger(lessonId) && lessonId > 0;

const { data, isPending, isError } = useGetLessonDetail(lessonId, {
enabled: isValidLessonId,
});
// const { data, isPending, isError } = useGetLessonDetail(lessonId, {
// enabled: isValidLessonId,
// });

if (!isValidLessonId) {
return <Navigate to={ROUTES_CONFIG.error.path} replace />;
}
// if (!isValidLessonId) {
// return <Navigate to={ROUTES_CONFIG.error.path} replace />;
// }

if (isPending) return null;
// if (isPending) return null;

if (isError || !data) {
return <Navigate to={ROUTES_CONFIG.error.path} replace />;
}
// if (isError || !data) {
// return <Navigate to={ROUTES_CONFIG.error.path} replace />;
// }

const { status, bookStatus, teacherNickname, isMyLesson } = data;
// const { status, bookStatus, teacherNickname, isMyLesson } = data;

const isButtonEnabled =
status === 'OPEN' && isMyLesson === false && bookStatus === false && teacherNickname !== WITHDRAW_USER_NAME;
// const isButtonEnabled =
// status === 'OPEN' && isMyLesson === false && bookStatus === false && teacherNickname !== WITHDRAW_USER_NAME;

if (!isButtonEnabled) {
return <Navigate to={ROUTES_CONFIG.class.path(lessonId.toString())} replace />;
}
// if (!isButtonEnabled) {
// return <Navigate to={ROUTES_CONFIG.class.path(lessonId.toString())} replace />;
// }

return <Outlet />;
};
// return <Outlet />;
// };
12 changes: 5 additions & 7 deletions src/routes/router.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { lazy } from 'react';
import { createBrowserRouter } from 'react-router-dom';
import Withdraw from '@/pages/mypage/components/Withdraw/Withdraw';
import Reservation from '@/pages/reservation/Reservation';
import AuthGuard from '@/routes/guards/authGuard';
import GuestGuard from '@/routes/guards/guestGuard';
import OnboardingGuard from '@/routes/guards/onboardingGuard';
import { ReservationGuard } from '@/routes/guards/reservationGuard';
import WithdrawGuard from '@/routes/guards/withdrawGuard';
import { guestRoutes } from '@/routes/modules/guestRoutes';
import { protectedRoutes } from '@/routes/modules/protectedRoutes';
Expand Down Expand Up @@ -40,11 +38,11 @@ export const router = createBrowserRouter([
element: <WithdrawGuard />,
children: [{ index: true, element: <Withdraw /> }],
},
{
path: ROUTES_CONFIG.reservation.path(':id'),
element: <ReservationGuard />,
children: [{ index: true, element: <Reservation /> }],
},
// {
// path: ROUTES_CONFIG.reservation.path(':id'),
// element: <ReservationGuard />,
// children: [{ index: true, element: <Reservation /> }],
// },
{ path: '*', element: <Error /> },
],
},
Expand Down