feat(housekeeping): dispatch canonical domain routes
This commit is contained in:
1 parent
2970dff563
commit
e5c230ba35
13 files changed
+680
-82
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { satisfiesCapability } from "@/features/housekeeping/foundation/capability-context";
|
||||
import { createHousekeepingRegistry } from "@/features/housekeeping/foundation/registry";
|
||||
import { matchHousekeepingRoute } from "@/features/housekeeping/foundation/routing/match-route";
|
||||
import { getHousekeepingCapabilityContext } from "@/features/housekeeping/foundation/server-capability-context";
|
||||
import { HOUSEKEEPING_MANIFESTS } from "@/features/housekeeping/manifests";
|
||||
import { HOUSEKEEPING_ROUTE_HANDLERS } from "@/features/housekeeping/route-handlers";
|
||||
|
||||
export default async function HousekeepingPreviewRoutePage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ domain: string; segments?: readonly string[] }>;
|
||||
}) {
|
||||
const { domain, segments = [] } = await params;
|
||||
const registry = createHousekeepingRegistry(HOUSEKEEPING_MANIFESTS);
|
||||
const activeDomain = registry.domains.find((entry) => entry.id === domain);
|
||||
if (!activeDomain) notFound();
|
||||
|
||||
const suffix = segments
|
||||
.map((segment) => encodeURIComponent(segment))
|
||||
.join("/");
|
||||
const canonicalPath = suffix
|
||||
? `${activeDomain.canonicalHref}/${suffix}`
|
||||
: activeDomain.canonicalHref;
|
||||
const match = matchHousekeepingRoute(registry, canonicalPath);
|
||||
if (!match || match.domain !== activeDomain.id) notFound();
|
||||
|
||||
const route = activeDomain.routes.find((entry) => entry.id === match.routeId);
|
||||
const handler = HOUSEKEEPING_ROUTE_HANDLERS.find(
|
||||
(entry) => entry.routeId === match.routeId,
|
||||
);
|
||||
if (!route || !handler) notFound();
|
||||
|
||||
const context = await getHousekeepingCapabilityContext();
|
||||
if (
|
||||
!satisfiesCapability(context, activeDomain.capability) ||
|
||||
!satisfiesCapability(context, route.capability)
|
||||
) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
return handler.render({ context, match });
|
||||
}
|
||||
@@ -18,7 +18,7 @@ function namespaceKey(key: string): string {
|
||||
return key.slice(MESSAGE_PREFIX.length);
|
||||
}
|
||||
|
||||
export default async function AdminNextDomainLayout({
|
||||
export default async function HousekeepingPreviewDomainLayout({
|
||||
children,
|
||||
params,
|
||||
}: {
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { HousekeepingPageShell } from "@/features/housekeeping/foundation/page/housekeeping-page-shell";
|
||||
import { HousekeepingPageState } from "@/features/housekeeping/foundation/page/housekeeping-page-state";
|
||||
import { createHousekeepingRegistry } from "@/features/housekeeping/foundation/registry";
|
||||
import { HOUSEKEEPING_MANIFESTS } from "@/features/housekeeping/manifests";
|
||||
|
||||
const MESSAGE_PREFIX = "pages.housekeeping.";
|
||||
|
||||
function namespaceKey(key: string): string {
|
||||
if (!key.startsWith(MESSAGE_PREFIX)) {
|
||||
throw new Error(`invalid housekeeping message key: ${key}`);
|
||||
}
|
||||
|
||||
return key.slice(MESSAGE_PREFIX.length);
|
||||
}
|
||||
|
||||
export default async function AdminNextDomainPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ domain: string }>;
|
||||
}) {
|
||||
const { domain } = await params;
|
||||
const registry = createHousekeepingRegistry(HOUSEKEEPING_MANIFESTS);
|
||||
const activeDomain = registry.domains.find((entry) => entry.id === domain);
|
||||
|
||||
if (!activeDomain) notFound();
|
||||
|
||||
const translate = await getTranslations("pages.housekeeping");
|
||||
|
||||
return (
|
||||
<HousekeepingPageShell
|
||||
title={translate(namespaceKey(activeDomain.labelKey) as never)}
|
||||
description={translate(
|
||||
namespaceKey(activeDomain.descriptionKey) as never,
|
||||
)}
|
||||
>
|
||||
<HousekeepingPageState
|
||||
state="empty"
|
||||
title={translate("states.empty.title")}
|
||||
description={translate("states.empty.description")}
|
||||
/>
|
||||
</HousekeepingPageShell>
|
||||
);
|
||||
}
|
||||
+14
-10
@@ -5,19 +5,23 @@ import { toHousekeepingHref } from "@/features/housekeeping/foundation/routing/h
|
||||
import { getHousekeepingCapabilityContext } from "@/features/housekeeping/foundation/server-capability-context";
|
||||
import { HOUSEKEEPING_MANIFESTS } from "@/features/housekeeping/manifests";
|
||||
|
||||
export default async function AdminNextPage() {
|
||||
export default async function HousekeepingPreviewRootPage() {
|
||||
const context = await getHousekeepingCapabilityContext();
|
||||
const registry = createHousekeepingRegistry(HOUSEKEEPING_MANIFESTS);
|
||||
const firstVisibleDomain = registry.domains.find((domain) =>
|
||||
satisfiesCapability(context, domain.capability),
|
||||
);
|
||||
|
||||
if (!firstVisibleDomain) notFound();
|
||||
for (const domain of registry.domains) {
|
||||
if (!satisfiesCapability(context, domain.capability)) continue;
|
||||
|
||||
const previewHref = toHousekeepingHref(
|
||||
firstVisibleDomain.canonicalHref,
|
||||
"preview",
|
||||
);
|
||||
const route = domain.routes.find((entry) =>
|
||||
satisfiesCapability(context, entry.capability),
|
||||
);
|
||||
if (!route) continue;
|
||||
|
||||
redirect(previewHref === "/ase-next" ? "/ase-next/operations" : previewHref);
|
||||
const previewHref = toHousekeepingHref(route.href, "preview");
|
||||
redirect(
|
||||
previewHref === "/ase-next" ? "/ase-next/operations" : previewHref,
|
||||
);
|
||||
}
|
||||
|
||||
notFound();
|
||||
}
|
||||
Reference in new issue
Block a user