Skip to content

Commit

Permalink
Metro Validate
Browse files Browse the repository at this point in the history
  • Loading branch information
happycastle114 committed Dec 1, 2023
1 parent a4815ac commit 81b06d4
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/components/pages/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useNavigate, useParams } from "react-router-dom";
import { Navigate, useParams } from "react-router-dom";
import { Divider } from "antd";
import { Layout } from "@/components/templates";
import { Card } from "@/components/atoms";
Expand All @@ -14,6 +14,27 @@ const BANNED_METRO = ["제주특별자치도", "세종특별자치시"];

const BANNED_LOCAL = ["군위군"];

const METRO_NAMES: string[] = [
"제주특별자치도",
"경상남도",
"경상북도",
"전라남도",
"전라북도",
"충청남도",
"충청북도",
"강원도",
"경기도",
"세종특별자치시",
"울산광역시",
"대전광역시",
"광주광역시",
"대구광역시",
"부산광역시",
"인천광역시",
"서울특별시",
"",
];

const vaildateLocalAndMetroName = (
reportType: string,
metroName: string,
Expand All @@ -25,14 +46,17 @@ const vaildateLocalAndMetroName = (
) {
return false;
}
if (!METRO_NAMES.includes(metroName)) {
return false;
}

return true;
};

const MainPage = () => {
const { reportType = "", metroName = "", localName = "" } = useParams();
const navigate = useNavigate();
if (!vaildateLocalAndMetroName(reportType, metroName, localName)) {
navigate("/localCouncil", { replace: true });
return <Navigate to="/localCouncil" replace />;
}

return (
Expand Down

0 comments on commit 81b06d4

Please sign in to comment.