-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Alert from "@codegouvfr/react-dsfr/Alert"; | ||
import { type NextServerPageProps } from "@common/utils/next"; | ||
import { CenteredContainer } from "@design-system"; | ||
import { notFound } from "next/navigation"; | ||
|
||
import { Footer } from "../Footer"; | ||
import { Header } from "../Header"; | ||
|
||
const controlledErrors: Record<string, string | { message: string; source: string }> = { | ||
AccessDenied: { | ||
source: "login", | ||
message: "Vous n'êtes pas staff.", | ||
}, | ||
}; | ||
|
||
const ControlledErrorPage = ({ searchParams }: NextServerPageProps<never, "error" | "source">) => { | ||
const error = controlledErrors[`${searchParams.error}`]; | ||
const source = `${searchParams.source}`; | ||
|
||
if (!error) { | ||
notFound(); | ||
} | ||
|
||
const errorMessage = typeof error === "object" ? (source == error.source ? error.message : notFound()) : error; | ||
|
||
return ( | ||
<> | ||
<Header /> | ||
<main role="main" id="content" className="grow"> | ||
<CenteredContainer py="6w"> | ||
<Alert title="Erreur" severity="error" description={errorMessage} /> | ||
</CenteredContainer> | ||
</main> | ||
<Footer type="public" /> | ||
</> | ||
); | ||
}; | ||
|
||
export default ControlledErrorPage; |