From 6d33738191ed13fbc8d1b19342ee30a4daa56efc Mon Sep 17 00:00:00 2001 From: Marine Heckler Date: Thu, 8 Feb 2024 17:53:25 +0100 Subject: [PATCH] Utilisation d'un composant NotFound custom --- packages/site/app/actus/[id]/[slug]/page.tsx | 4 ++-- packages/site/app/actus/[id]/page.tsx | 5 +++-- packages/site/app/actus/page.tsx | 5 ++++- .../site/app/collectivites/[code]/[name]/page.tsx | 4 +++- packages/site/app/collectivites/[code]/page.tsx | 7 ++++++- packages/site/app/collectivites/page.tsx | 6 ++---- packages/site/app/layout.tsx | 4 +--- packages/site/app/programme/[uid]/page.tsx | 6 +++--- packages/site/components/info/NotFound.tsx | 15 +++++++++++++++ 9 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 packages/site/components/info/NotFound.tsx diff --git a/packages/site/app/actus/[id]/[slug]/page.tsx b/packages/site/app/actus/[id]/[slug]/page.tsx index 345aa45b88c..2606b32eb85 100644 --- a/packages/site/app/actus/[id]/[slug]/page.tsx +++ b/packages/site/app/actus/[id]/[slug]/page.tsx @@ -1,4 +1,3 @@ -import {notFound} from 'next/navigation'; import {StrapiImage} from '@components/strapiImage/StrapiImage'; import Section from '@components/sections/Section'; import {getLocalDateString} from 'src/utils/getLocalDateString'; @@ -11,6 +10,7 @@ import EmbededVideo from '@components/video/EmbededVideo'; import {ParagrapheCustomArticleData} from 'app/types'; import {Metadata, ResolvingMetadata} from 'next'; import {getUpdatedMetadata} from 'src/utils/getUpdatedMetadata'; +import NotFound from '@components/info/NotFound'; export async function generateMetadata( {params}: {params: {id: string}}, @@ -41,7 +41,7 @@ const Article = async ({params}: {params: {id: string}}) => { const id = parseInt(params.id); const data = await getData(id); - if (!data) return notFound(); + if (!data) return ; return ( <> diff --git a/packages/site/app/actus/[id]/page.tsx b/packages/site/app/actus/[id]/page.tsx index 5d89cf7784d..aa2331c9be1 100644 --- a/packages/site/app/actus/[id]/page.tsx +++ b/packages/site/app/actus/[id]/page.tsx @@ -1,8 +1,9 @@ 'use server'; -import {notFound, redirect} from 'next/navigation'; +import {redirect} from 'next/navigation'; import {convertNameToSlug} from 'src/utils/convertNameToSlug'; import {getData} from './[slug]/utils'; +import NotFound from '@components/info/NotFound'; /** * Permet la redirection vers la page article lorsque seul @@ -13,7 +14,7 @@ const ArticleParId = async ({params}: {params: {id: string}}) => { const id = parseInt(params.id); const data = await getData(id); - if (!data || !data.titre) return notFound(); + if (!data || !data.titre) return ; redirect(`/actus/${params.id}/${convertNameToSlug(data.titre)}`); }; diff --git a/packages/site/app/actus/page.tsx b/packages/site/app/actus/page.tsx index 03a71b02b2d..9fbfe69ba11 100644 --- a/packages/site/app/actus/page.tsx +++ b/packages/site/app/actus/page.tsx @@ -8,6 +8,7 @@ import BlogCard from '@components/cards/BlogCard'; import MasonryGallery from '@components/galleries/MasonryGallery'; import {Metadata} from 'next'; import {convertNameToSlug} from 'src/utils/convertNameToSlug'; +import NotFound from '@components/info/NotFound'; export async function generateMetadata(): Promise { return { @@ -85,7 +86,9 @@ const Actualites = async () => { ))} /> - ) : null; + ) : ( + + ); }; export default Actualites; diff --git a/packages/site/app/collectivites/[code]/[name]/page.tsx b/packages/site/app/collectivites/[code]/[name]/page.tsx index ef9667c98cc..0e6814f72d8 100644 --- a/packages/site/app/collectivites/[code]/[name]/page.tsx +++ b/packages/site/app/collectivites/[code]/[name]/page.tsx @@ -16,6 +16,7 @@ import {natureCollectiviteToLabel} from 'src/utils/labels'; import AccesCompte from './AccesCompte'; import {getUpdatedMetadata} from 'src/utils/getUpdatedMetadata'; import HistoriqueLabellisation from './HistoriqueLabellisation'; +import NotFound from '@components/info/NotFound'; export async function generateMetadata( {params}: {params: {code: string}}, @@ -59,7 +60,8 @@ const DetailCollectivite = async ({params}: {params: {code: string}}) => { const strapiData = await getStrapiData(params.code); const strapiDefaultData = await getStrapiDefaultData(); - if (!collectiviteData || !collectiviteData.collectivite.nom) return null; + if (!collectiviteData || !collectiviteData.collectivite.nom) + return ; return (
{ return { @@ -19,8 +20,12 @@ export async function generateMetadata(): Promise { const DetailCodeCollectivite = async ({params}: {params: {code: string}}) => { const data = await fetchCollectivite(params.code); + if (!data) return ; + redirect( - `/collectivites/${params.code}/${convertNameToSlug(data?.nom ?? '')}`, + `/collectivites/${params.code}/${convertNameToSlug( + data?.collectivite.nom ?? '', + )}`, ); }; diff --git a/packages/site/app/collectivites/page.tsx b/packages/site/app/collectivites/page.tsx index bd8a8cfc34d..22312c592f9 100644 --- a/packages/site/app/collectivites/page.tsx +++ b/packages/site/app/collectivites/page.tsx @@ -1,7 +1,7 @@ 'use server'; +import NotFound from '@components/info/NotFound'; import {Metadata} from 'next'; -import {notFound} from 'next/navigation'; export async function generateMetadata(): Promise { return { @@ -9,8 +9,6 @@ export async function generateMetadata(): Promise { }; } -const Collectivite = () => { - notFound(); -}; +const Collectivite = () => ; export default Collectivite; diff --git a/packages/site/app/layout.tsx b/packages/site/app/layout.tsx index 056b04a9271..e8d462363c6 100644 --- a/packages/site/app/layout.tsx +++ b/packages/site/app/layout.tsx @@ -74,9 +74,7 @@ export default function RootLayout({children}: {children: JSX.Element}) {
-
- {children} -
+
{children}