Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/routes/app.$tenant/settings/profile.tsx
T

58 lines
2.5 KiB
TypeScript

// AK-SET-01 Hub A — "Mein Konto" bundles the former profile, security,
// notifications and privacy rail entries. Layout route only.
//
// Every tab is ungated on purpose: these are the user's own settings, and the
// DSGVO self-service under "Meine Daten" has to stay reachable for everyone
// (DoD B6). The admin-facing privacy pages keep their own permission gates.
import { Outlet, useLoaderData, useLocation, type LoaderFunctionArgs, type MetaFunction } from "react-router";
import { FeatherUser } from "@subframe/core";
import { buildSettingsHubVM, type SettingsHubTabInput } from "@hivegrid/view-models";
import { SettingsHubShell } from "~/components/screens/settings/SettingsHubShell";
import { getTranslations } from "~/locale/i18next.server";
import UrlUtils from "~/utils/app/UrlUtils";
import { requireAuth } from "~/utils/loaders.middleware";
type LoaderData = {
title: string;
tabs: SettingsHubTabInput[];
};
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
await requireAuth({ request, params });
const { t } = await getTranslations(request);
const tabs: SettingsHubTabInput[] = [
// The hub index href is a prefix of every sibling — without this the
// profile tab would stay lit on the other tabs.
{ id: "profile", labelKey: "settings.profile.profileTitle", href: UrlUtils.currentTenantUrl(params, "settings/profile"), exact: true },
{ id: "appearance", labelKey: "settings.appearance.title", href: UrlUtils.currentTenantUrl(params, "settings/profile/appearance") },
{ id: "security", labelKey: "settings.security.title", href: UrlUtils.currentTenantUrl(params, "settings/profile/security") },
{ id: "notifications", labelKey: "settings.notifications.title", href: UrlUtils.currentTenantUrl(params, "settings/profile/notifications") },
{ id: "data", labelKey: "settings.privacy.title", href: UrlUtils.currentTenantUrl(params, "settings/profile/data") },
];
return { title: `${t("settings.hubs.account.title")} | ${process.env.APP_NAME}`, tabs } satisfies LoaderData;
};
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
export default function AccountHubRoute() {
const { tabs } = useLoaderData<LoaderData>();
const location = useLocation();
const vm = buildSettingsHubVM({
hubId: "account",
titleKey: "settings.hubs.account.title",
subtitleKey: "settings.hubs.account.subtitle",
tabs,
currentPath: location.pathname,
});
return (
<SettingsHubShell vm={vm} icon={<FeatherUser />}>
<Outlet />
</SettingsHubShell>
);
}