websites/app/annuaire/[regionSlug]/[departementSlug]/page.tsx

49 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2024-05-06 22:35:25 +02:00
import { Metadata } from "next";
import { notFound } from "next/navigation";
import {
Header,
CommunesList,
DepartementsList,
RegionList,
} from "@/components/index";
import departements, {
getSlugFromDepartement,
getDepartementFromSlug,
} from "@/lib/departements";
import { getRegionFromCode } from "@/lib/regions";
export const metadata: Metadata = {
title: "Annuaire",
description: "L'annuaire collaboratif des professionnels de la santé",
};
export async function generateStaticParams() {
return departements.map((departement) => ({
departement: getSlugFromDepartement(departement),
}));
}
export default function DepartementPage({
params,
}: {
params: { regionSlug: string; departementSlug: string };
}) {
const departement = getDepartementFromSlug(params.departementSlug);
if (!departement) return notFound();
const region = getRegionFromCode(departement.region);
if (!region) return notFound();
return (
<>
<Header searchField={true} />
<RegionList selected={region} />
<hr></hr>
<DepartementsList selected={departement} region={region} />
<hr></hr>
<CommunesList departement={departement} />
</>
);
}