261022_04_ENH: 프로젝트 제목 코드·명 병행 표기 및 URL 파라미터 프로젝트 선택 제거

This commit is contained in:
2026-10-22 11:54:39 +09:00
parent 86e7ce3e32
commit 642350bc6c
4 changed files with 14 additions and 43 deletions

View File

@@ -10,7 +10,7 @@ import { kartMenus } from "@/config/menu.data";
import type { KartMenuItem } from "@/config/menu.type";
import { ProjectSelector } from "@/components/project/ProjectSelector";
import { useProjectTitle } from "@/query/project";
import { useProjectParamsMigration, useSelectedProject } from "@/hooks/useSelectedProject";
import { useSelectedProject } from "@/hooks/useSelectedProject";
import { projectPagePath } from "@/lib/report-navigation";
import { useAuth } from "@/hooks/useAuth";
import { useMutation } from "@tanstack/react-query";
@@ -28,13 +28,18 @@ export function AppHeader({ user }: AppHeaderProps) {
const { auth } = useAuth();
const external = isExternalUser(user);
const { project } = useSelectedProject();
useProjectParamsMigration();
const title = useProjectTitle(project);
const [mobileOpen, setMobileOpen] = useState(false);
const menus = project && !(external && auth.external?.pageOnly)
? kartMenus.filter((menu) => !menu.visible || menu.visible(user))
: [];
const projectTitle = project ? title : "Project Overview TOP 6";
// "(code) name" like the project selector; the code alone until the project list provides the
// name (useProjectTitle falls back to pkey). External links keep their link title.
const projectTitle = !project
? "Project Overview TOP 6"
: external || title === project.pkey
? title
: "(" + project.pkey + ") " + title;
const canCopyUrl = !!project && user.userRole < REPORT_MEMBER_ROLE;
const copy = useMutation({
mutationFn: async (mode: "P" | "U") => {

View File

@@ -1,9 +1,7 @@
"use client";
import { useCallback, useEffect } from "react";
import { useCallback } from "react";
import { useAtom, useAtomValue } from "jotai";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import type { Route } from "next";
import { createPersistentAtom } from "@kri/common/jotai";
import { useAuth } from "@/hooks/useAuth";
import { isExternalUser } from "@/types/share";
@@ -13,7 +11,7 @@ import {
setLocalStorage,
} from "@/store/storage/secure-storage";
import { StorageKeys } from "@/store/storage/storage-keys";
import { isProjectRef, isRecord, readProjectParams, type ProjectRef } from "@/types/kart";
import { isProjectRef, isRecord, type ProjectRef } from "@/types/kart";
/** The project chosen for the project pages, owned by the user who chose it. */
export type SelectedProject = { userId: string; project: ProjectRef } | null;
@@ -46,16 +44,14 @@ export const selectedProjectAtom = createPersistentAtom<SelectedProject>(
);
/**
* Current project for the signed-in user. An old `?projectType=&pkey=` link takes precedence
* until ProjectParamsMigration stores it and removes the parameters from the address.
* Current project for the signed-in user. Address parameters (old `?projectType=&pkey=` links)
* never select a project; links are shared only through generated Page Copy / URL Copy links.
*/
export function useSelectedProject() {
const { auth, hydrated: authHydrated } = useAuth();
const [selected, setSelected] = useAtom(selectedProjectAtom);
const storeHydrated = useAtomValue(selectedProjectAtom.hydratedAtom);
const urlProject = readProjectParams(useSearchParams());
const external = isExternalUser(auth.user);
const fromUrl = external ? null : urlProject;
const userId = auth.user?.userId;
const stored =
selected && userId && selected.userId === userId
@@ -73,30 +69,10 @@ export function useSelectedProject() {
);
const clear = useCallback(() => setSelected(null), [setSelected]);
return {
project: external ? auth.external ?? null : fromUrl ?? stored,
fromUrl,
project: external ? auth.external ?? null : stored,
/** False until both the login state and the stored selection have been read. */
hydrated: authHydrated && storeHydrated,
select,
clear,
} as const;
}
/**
* Old bookmarks and shared links still carry `?projectType=&pkey=`: store that project and
* replace the address with the bare path. Mounted once in the app header.
*/
export function useProjectParamsMigration() {
const router = useRouter();
const pathname = usePathname();
const { auth, hydrated } = useAuth();
const { fromUrl, select } = useSelectedProject();
const projectType = fromUrl?.projectType;
const pkey = fromUrl?.pkey;
const signedIn = hydrated && !!auth.user;
useEffect(() => {
if (!signedIn || projectType === undefined || pkey === undefined) return;
select({ projectType, pkey });
router.replace(pathname as Route);
}, [signedIn, projectType, pkey, select, router, pathname]);
}

View File

@@ -141,16 +141,6 @@ export function readRows<T>(
export function projectKey(project: ProjectRef): string {
return project.projectType + ":" + project.pkey;
}
export function readProjectParams(
params: Pick<URLSearchParams, "get">,
): ProjectRef | null {
const type = params.get("projectType");
const project = {
projectType: type === "0" ? 0 : type === "1" ? 1 : null,
pkey: params.get("pkey"),
};
return isProjectRef(project) ? project : null;
}
export function validDateRange(range: DateRange): boolean {
const validDate = (date: string) =>
/^\d{4}-\d{2}-\d{2}$/.test(date) &&