"use client"; /** * Old deep links into cards that moved to another Settings page. * * A path that moved is a server redirect (`next.config.ts`), but a card that * moved while its page stayed cannot be: the `#anchor` never reaches the * server. Bookmarks, cross-links in older notifications and the docs point at * `/settings/privacy#sessions` and the like, so the shell forwards a known * anchor on a known page to the card's new home, once, on arrival. * * `SETTINGS_ANCHOR_FORWARDS` is also read by the legacy-routes guard, which * proves every target lands on a page that exists. */ import { useEffect } from "react"; import { usePathname, useRouter } from "next/navigation"; export const SETTINGS_ANCHOR_FORWARDS: Readonly< Record>> > = { // v1.44 — sessions, trusted devices and the security activity joined the // other sign-in controls under Security; the duplicate export card left. "/settings/privacy": { sessions: "/settings/security#sessions", "trusted-devices": "/settings/security#trusted-devices", "security-activity": "/settings/security#security-activity", "your-data-export": "/settings/export", }, // v1.44 — the proactive nudges are a reminder and live with the others. "/settings/coach": { "coach-nudge": "/settings/notifications#coach-nudge", }, // v1.44 — Arrangement holds order and view only; each module's own // settings moved to its page under Modules. "/settings/layout/labs": { "labs-local-ocr": "/settings/modules/labs#labs-local-ocr", "labs-biomarkers": "/settings/modules/labs#labs-biomarkers", }, "/settings/layout/medications": { "injection-sites": "/settings/modules/medications#injection-sites", }, "/settings/layout/vorsorge": { "screening-hints": "/settings/anamnesis#screening-hints", "vorsorge-reminders": "/settings/notifications#vorsorge-reminders", }, }; /** Where an anchor on a page now lives, or null when it did not move. */ export function forwardedAnchorTarget( pathname: string, hash: string, ): string | null { const anchor = hash.startsWith("#") ? hash.slice(1) : hash; if (!anchor) return null; return SETTINGS_ANCHOR_FORWARDS[pathname]?.[anchor] ?? null; } export function SettingsAnchorForward() { const pathname = usePathname(); const router = useRouter(); useEffect(() => { if (!pathname) return; const target = forwardedAnchorTarget(pathname, window.location.hash); if (target) router.replace(target); }, [pathname, router]); return null; }