develop #1
@@ -13,7 +13,7 @@
|
||||
|
||||
- New backend only; development front 4014/backend 4015/api/v1. Use published @kri/common HTTP and persistent hydratedAtom plus TanStack Query; do not add axios or duplicate common storage/auth helpers. Repository package.json and lockfile are authoritative for versions. Add dependencies only after user approval; preserve existing chart, drag-and-drop and registry integrations.
|
||||
- Next stores the 24-hour token in an HttpOnly cookie and returns validated LoginUser only. Secure for ENV prod/production. Backend logout/session endpoints do not exist: Next logout clears its cookie, client auth and query cache. BFF accepts only fixed implemented project reads and whitelisted query fields; never trust browser role/id headers or send API keys to the browser.
|
||||
- Basic routes are /, /login, /logout and project pages without query parameters (/Report/Current, /Report/Quota, /Report/Tabulation, /Report/Crosstab, /Management/Derived, /Management/Exim). The selected project {projectType, pkey} lives in the user-scoped persistent atom `useSelectedProject` (localStorage, like legacy ptokenState); home, login and logout clear it, and old `?projectType=0|1&pkey=rawKey` links are stored and stripped. Preserve pkey case and use projectType+pkey in query keys and BFF paths, with current user id/role/team in query keys. Runtime-validate data, use existing UI components, retain raw server count/LOI semantics and display-only padded date cleanup. Keep loading/error/empty/retry states.
|
||||
- Basic routes are /, /login, /logout and project pages without query parameters (/Report/Current, /Report/Quota, /Report/Tabulation, /Report/Crosstab, /Management/Derived, /Management/Exim). The selected project {projectType, pkey} lives in the user-scoped persistent atom `useSelectedProject` (localStorage, like legacy ptokenState); home, login and logout clear it. Address parameters never select a project: old `?projectType=0|1&pkey=rawKey` links are ignored, and sharing is only through generated Page Copy/URL Copy links. This is not access control; server project scope is authoritative. Preserve pkey case and use projectType+pkey in query keys and BFF paths, with current user id/role/team in query keys. Runtime-validate data, use existing UI components, retain raw server count/LOI semantics and display-only padded date cleanup. Keep loading/error/empty/retry states.
|
||||
- Basic progress uses type/loi/day/screen; date filters affect type/loi/screen, never day, matching the server. Logging is a best-effort /log/visit call with server cookie identity, no /log/site HTTP.
|
||||
- The second migration phase is closed. Until the user explicitly announces launch, this application is unlaunched and old External token compatibility is unnecessary. The user performs every operation that writes to the shared database (live login, bookmark/derived saves, imports, share issuance and External login) and live Excel generation checks. No shared DB calls in local validation. Phase closure does not certify unexecuted live checks.
|
||||
- ReportMember/URL Copy/Page Copy roles are 9001/9002/9003. External login replaces the prior identity; validate the server-returned user and link together. Keep the link's project and page scope, disable project-list/summary reads, and use the link title. Page Copy has no GNB menus; URL Copy has only the four report menus. Hide logo navigation, Logout, project selection, Copy and bookmark writes. Bookmark reads and aggregate/Quota Excel remain allowed; server scope enforcement is authoritative.
|
||||
|
||||
@@ -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") => {
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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) &&
|
||||
|
||||
Reference in New Issue
Block a user