Skip to content

Commit

Permalink
인가된 사용자 아니면 error page로 routing 되게 재설정 및 탭 유지되면서 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonc01 committed Aug 19, 2024
1 parent abd6759 commit e5e3abd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 9 additions & 5 deletions admin/src/components/header/AdminHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import NextDayArrow from '@/assets/icons/nextDayArrow.svg';
import PreviousDayArrow from '@/assets/icons/previousDayArrow.svg';
import dateFormatting from '@/utils/dateFormatting';
import { DateContext } from '@/context/dateContext';
import { useNavigate } from 'react-router-dom';
import { useNavigate, useLocation } from 'react-router-dom';
import { putEventSchedules, getEventSchedules } from '@/api/header/index';

function AdminHeader() {
const location = useLocation();
const navigator = useNavigate();
const { dateInfo } = useContext(DateContext);
const [isNextDayDisabled, setIsNextDayDisabled] = useState(false);
Expand All @@ -17,9 +18,8 @@ function AdminHeader() {
const getDate = async () => {
const response = await getEventSchedules();
const startDate = new Date(response[0].date);
const finishDate = new Date(startDate);
const finishDate = new Date(response[13].date);
const currentDate = new Date(dateInfo);
finishDate.setDate(startDate.getDate() + 13);
setIsPreviousDayDisabled(currentDate.getTime() === startDate.getTime());
setIsNextDayDisabled(currentDate.getTime() === finishDate.getTime());
};
Expand All @@ -34,15 +34,19 @@ function AdminHeader() {
if (!isPreviousDayDisabled) {
const previousDay = new Date(dateInfo);
previousDay.setDate(previousDay.getDate() - 1);
navigator(`/${dateFormatting(previousDay)}`);
const pathSegments = location.pathname.split('/');
const tabName = pathSegments[2];
navigator(`/${dateFormatting(previousDay)}/${tabName}`);
}
};

const handleNextDay = () => {
if (!isNextDayDisabled) {
const nextDay = new Date(dateInfo);
nextDay.setDate(nextDay.getDate() + 1);
navigator(`/${dateFormatting(nextDay)}`);
const pathSegments = location.pathname.split('/');
const tabName = pathSegments[2];
navigator(`/${dateFormatting(nextDay)}/${tabName}`);
}
};

Expand Down
10 changes: 6 additions & 4 deletions admin/src/router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const router = createBrowserRouter([
{
path: '/',
element: <App />,
children: {
path: 'error',
element: <ErrorPage />,
},
children: [
{
path: 'error',
element: <ErrorPage />,
},
],
},
{
path: '/:date',
Expand Down

0 comments on commit e5e3abd

Please sign in to comment.