Compare commits
4 Commits
fc1074cf4e
...
fcca4a0be7
| Author | SHA1 | Date | |
|---|---|---|---|
| fcca4a0be7 | |||
| c558369b10 | |||
| b884c5e998 | |||
| f37e2923e9 |
@@ -1,7 +1,17 @@
|
|||||||
import {redirect} from "next/navigation";
|
import {redirect} from "next/navigation";
|
||||||
|
import { ADMIN_QUERY_PARAM, ADMIN_ROUTE_KEY } from "@/lib/admin-route";
|
||||||
|
|
||||||
const MainPage = () => {
|
type MainPageProps = {
|
||||||
redirect("/safety-inspection");
|
searchParams?: Promise<Record<string, string | string[] | undefined>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const MainPage = async ({ searchParams }: MainPageProps) => {
|
||||||
|
const params = await searchParams;
|
||||||
|
const adminKey = params?.[ADMIN_QUERY_PARAM];
|
||||||
|
const adminKeyValue = Array.isArray(adminKey) ? adminKey[0] : adminKey;
|
||||||
|
const query = adminKeyValue === ADMIN_ROUTE_KEY ? `?${ADMIN_QUERY_PARAM}=${ADMIN_ROUTE_KEY}` : "";
|
||||||
|
|
||||||
|
redirect(`/safety-inspection${query}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MainPage;
|
export default MainPage;
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
import { useSearchParams } from "next/navigation";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import DataTable from "@/components/table/DataTable";
|
import DataTable from "@/components/table/DataTable";
|
||||||
import type { DataColumn } from "@/components/table/types";
|
import type { DataColumn } from "@/components/table/types";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { DIV_KEY_MAP } from "@/config/kfpaConfig";
|
import { DIV_KEY_MAP } from "@/config/kfpaConfig";
|
||||||
import { useAuth } from "@/hooks/useAuth";
|
|
||||||
import { formatKoreanBaseDate } from "@/lib/utils";
|
import { formatKoreanBaseDate } from "@/lib/utils";
|
||||||
import { useWriteDivCommentMutation } from "@/query/admin";
|
import { useWriteDivCommentMutation } from "@/query/admin";
|
||||||
import { statisticsQueryKeys } from "@/query/key/keys";
|
import { statisticsQueryKeys } from "@/query/key/keys";
|
||||||
@@ -15,6 +15,7 @@ import { useDivDetailDataQuery } from "@/query/statistics";
|
|||||||
import type { CommentValue, DivDetailData } from "@/types/kfpa";
|
import type { CommentValue, DivDetailData } from "@/types/kfpa";
|
||||||
import { Pencil, Save, X } from 'lucide-react';
|
import { Pencil, Save, X } from 'lucide-react';
|
||||||
import SectionTitle from "@/components/common/SectionTitle";
|
import SectionTitle from "@/components/common/SectionTitle";
|
||||||
|
import { hasAdminRouteParam } from "@/lib/admin-route";
|
||||||
|
|
||||||
export type SafetyInspectionDivDetailProps = {
|
export type SafetyInspectionDivDetailProps = {
|
||||||
selectedDiv: string;
|
selectedDiv: string;
|
||||||
@@ -85,7 +86,7 @@ const createDraft = (columns: Array<{ key: string }>, source?: Record<string, Co
|
|||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const SafetyInspectionDivDetail = ({ selectedDiv }: SafetyInspectionDivDetailProps) => {
|
const SafetyInspectionDivDetail = ({ selectedDiv }: SafetyInspectionDivDetailProps) => {
|
||||||
const { auth } = useAuth();
|
const searchParams = useSearchParams();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { data, isLoading, isError } = useDivDetailDataQuery(selectedDiv, selectedDiv !== "-1");
|
const { data, isLoading, isError } = useDivDetailDataQuery(selectedDiv, selectedDiv !== "-1");
|
||||||
const writeMutation = useWriteDivCommentMutation();
|
const writeMutation = useWriteDivCommentMutation();
|
||||||
@@ -103,7 +104,7 @@ const SafetyInspectionDivDetail = ({ selectedDiv }: SafetyInspectionDivDetailPro
|
|||||||
}, [commentColumns, detail?.commentValues, selectedDiv]);
|
}, [commentColumns, detail?.commentValues, selectedDiv]);
|
||||||
|
|
||||||
const baseDateLabel = useMemo(() => formatKoreanBaseDate(), []);
|
const baseDateLabel = useMemo(() => formatKoreanBaseDate(), []);
|
||||||
const isAuthenticated = auth.user != null;
|
const isAuthenticated = hasAdminRouteParam(searchParams);
|
||||||
|
|
||||||
const rankRows: RankRow[] = useMemo(() => {
|
const rankRows: RankRow[] = useMemo(() => {
|
||||||
const ranks = detail?.csiRanks ?? {};
|
const ranks = detail?.csiRanks ?? {};
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ const Header = ({
|
|||||||
<h1 className="font-bold content-text-2xl text-header-color">{SITE_TITLE}</h1>
|
<h1 className="font-bold content-text-2xl text-header-color">{SITE_TITLE}</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex min-w-0 items-center justify-end gap-4">
|
<div className="flex min-w-0 items-center justify-end gap-4">
|
||||||
|
{
|
||||||
|
/* 클라이언트 요청으로 로그인 제외
|
||||||
{isAuthenticated && (
|
{isAuthenticated && (
|
||||||
<span className="content-text-base text-header-color hidden max-w-40 truncate sm:inline font-bold">
|
<span className="content-text-base text-header-color hidden max-w-40 truncate sm:inline font-bold">
|
||||||
{userName}
|
{userName}
|
||||||
@@ -81,15 +83,17 @@ const Header = ({
|
|||||||
{isAuthenticated ? (
|
{isAuthenticated ? (
|
||||||
<>
|
<>
|
||||||
<LogOut className="w-4 h-4" />
|
<LogOut className="w-4 h-4" />
|
||||||
<span className="hidden sm:inline">{"로그아웃"}</span>
|
<span className="hidden sm:inline">{"관리자 로그아웃"}</span>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<LogIn className="w-4 h-4" />
|
<LogIn className="w-4 h-4" />
|
||||||
<span className="hidden sm:inline">{"로그인"}</span>
|
<span className="hidden sm:inline">{"관리자 로그인"}</span>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
|
*/
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import {ReactNode, useEffect, useState} from "react";
|
import {ReactNode, useEffect, useState} from "react";
|
||||||
import {useRouter} from "next/navigation";
|
import {useRouter, useSearchParams} from "next/navigation";
|
||||||
import {DivKey} from "@/types/kfpa";
|
import {DivKey} from "@/types/kfpa";
|
||||||
import {useAuth} from "@/hooks/useAuth";
|
import {useAuth} from "@/hooks/useAuth";
|
||||||
import {LayoutCategoryProvider} from "./LayoutCategoryContext";
|
import {LayoutCategoryProvider} from "./LayoutCategoryContext";
|
||||||
@@ -12,6 +12,7 @@ import {TOP_MENUS, SIDE_MENUS} from "@/config/menu.data";
|
|||||||
import {useLogoutMutation} from "@/query/auth";
|
import {useLogoutMutation} from "@/query/auth";
|
||||||
import {useDialog} from "@/hooks/useDialog";
|
import {useDialog} from "@/hooks/useDialog";
|
||||||
import LoginDialog from "@/components/dialog/loginDialog";
|
import LoginDialog from "@/components/dialog/loginDialog";
|
||||||
|
import { appendAdminRouteParam, hasAdminRouteParam } from "@/lib/admin-route";
|
||||||
|
|
||||||
type MainLayoutProps = {
|
type MainLayoutProps = {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -26,13 +27,15 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
|||||||
const { showDialog } = useDialog();
|
const { showDialog } = useDialog();
|
||||||
const logoutMutation = useLogoutMutation();
|
const logoutMutation = useLogoutMutation();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
const isMounted = useMounted();
|
const isMounted = useMounted();
|
||||||
|
|
||||||
const [menuOpen, setMenuOpen] = useState(true);
|
const [menuOpen, setMenuOpen] = useState(true);
|
||||||
const [selectedDiv, setSelectedDiv] = useState<DivKey>(getDivKey());
|
const [selectedDiv, setSelectedDiv] = useState<DivKey>(getDivKey());
|
||||||
|
const isRouteAdmin = hasAdminRouteParam(searchParams);
|
||||||
|
|
||||||
const movePage = (path: string) => {
|
const movePage = (path: string) => {
|
||||||
router.push(path);
|
router.push(appendAdminRouteParam(path, searchParams));
|
||||||
};
|
};
|
||||||
|
|
||||||
const openLoginDialog = () => {
|
const openLoginDialog = () => {
|
||||||
@@ -60,7 +63,7 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
|||||||
<Header
|
<Header
|
||||||
topMenus={TOP_MENUS}
|
topMenus={TOP_MENUS}
|
||||||
userName={auth.user?.userName || ""}
|
userName={auth.user?.userName || ""}
|
||||||
isAuthenticated={auth.user != null}
|
isAuthenticated={isRouteAdmin}
|
||||||
onNavigate={movePage}
|
onNavigate={movePage}
|
||||||
onLogin={openLoginDialog}
|
onLogin={openLoginDialog}
|
||||||
onLogout={handleLogout}
|
onLogout={handleLogout}
|
||||||
|
|||||||
21
src/lib/admin-route.ts
Normal file
21
src/lib/admin-route.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export const ADMIN_QUERY_PARAM = "admin-key";
|
||||||
|
export const ADMIN_ROUTE_KEY = "Kf7qP2x9";
|
||||||
|
|
||||||
|
type AdminSearchParams = Pick<URLSearchParams, "get" | "has">;
|
||||||
|
|
||||||
|
export const hasAdminRouteParam = (searchParams: AdminSearchParams) =>
|
||||||
|
searchParams.get(ADMIN_QUERY_PARAM) === ADMIN_ROUTE_KEY;
|
||||||
|
|
||||||
|
export const appendAdminRouteParam = (path: string, searchParams: AdminSearchParams) => {
|
||||||
|
if (!hasAdminRouteParam(searchParams)) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [pathWithoutHash, hash] = path.split("#");
|
||||||
|
const [pathname, queryString] = pathWithoutHash.split("?");
|
||||||
|
const params = new URLSearchParams(queryString);
|
||||||
|
params.set(ADMIN_QUERY_PARAM, ADMIN_ROUTE_KEY);
|
||||||
|
|
||||||
|
const query = params.toString();
|
||||||
|
return `${pathname}${query ? `?${query}` : ""}${hash ? `#${hash}` : ""}`;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user