Skip to content

Commit

Permalink
feat(dsfr): migration de la page modèle de document
Browse files Browse the repository at this point in the history
  • Loading branch information
carolineBda committed Oct 15, 2024
1 parent 1f64d85 commit bb57eeb
Show file tree
Hide file tree
Showing 20 changed files with 459 additions and 293 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from "react";
import { DsfrLayout } from "../../../src/modules/layout";
import { generateDefaultMetadata } from "../../../src/modules/common/metas";
import {
fetchModel,
getTitle,
LetterModel,
} from "../../../src/modules/modeles-de-courriers";
import { notFound } from "next/navigation";
import { fetchRelatedItems } from "../../../src/modules/documents";

export async function generateMetadata({ params }) {
const { title, type, metaDescription, meta_title } = await getModel(
params.slug
);
const category = `Modèle ${type !== "fichier" ? `de ${type}` : "à télécharger"}`;

return generateDefaultMetadata({
title: `${category} : ${meta_title ?? title}`,
description: metaDescription,
path: `/modeles-de-courriers/${params.slug}`,
});
}

async function ModeleCourrier({ params }) {
const { title, ...model } = await getModel(params.slug);

const relatedItems = await fetchRelatedItems({ _id: model._id }, params.slug);

return (
<DsfrLayout>
<LetterModel
title={getTitle(params.slug, title)}
{...model}
relatedItems={relatedItems}
/>
</DsfrLayout>
);
}

const getModel = async (slug: string) => {
const model = await fetchModel(slug);

if (!model) {
return notFound();
}
return model;
};
export default ModeleCourrier;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
fetchModelById,
getTitle,
} from "../../../../src/modules/modeles-de-courriers";
import { notFound } from "next/navigation";
import { LetterModelContent } from "../../../../src/modules/modeles-de-courriers/components/LetterModelContent";
import { WidgetWithIframeResizer } from "../../../../src/modules/widgets/WidgetWithIframeResizer"; // import { useIframeResizer } from "../../../../src/common/hooks";

async function WidgetModel({ params }) {
const { title, ...model } = await getModel(params.id);

return (
<WidgetWithIframeResizer>
<LetterModelContent title={getTitle(params.slug, title)} {...model} />
</WidgetWithIframeResizer>
);
}

export const getModel = async (id: string) => {
const modele = await fetchModelById(id);

if (!modele) {
return notFound();
}
return modele;
};

export default WidgetModel;
2 changes: 1 addition & 1 deletion packages/code-du-travail-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"format:check": "prettier --check \"**/*.{js,ts,tsx,jsx,json,md}\""
},
"dependencies": {
"@codegouvfr/react-dsfr": "^1.13.4",
"@codegouvfr/react-dsfr": "^1.13.9",
"@elastic/elasticsearch": "^8.13.1",
"@matejmazur/react-katex": "^3.1.3",
"@opentelemetry/instrumentation-generic-pool": "^0.37.0",
Expand Down

This file was deleted.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions packages/code-du-travail-frontend/src/modeles/index.ts

This file was deleted.

129 changes: 0 additions & 129 deletions packages/code-du-travail-frontend/src/modeles/modeles.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ describe("<LetterModel />", () => {
intro={""}
relatedItems={[]}
metaDescription={""}
filesize={undefined}
filesize={10}
filename={""}
html={undefined}
meta_title={""}
type={undefined}
/>
);

Expand All @@ -50,11 +48,9 @@ describe("<LetterModel />", () => {
intro={""}
relatedItems={[]}
metaDescription={""}
filesize={undefined}
filesize={10}
filename={""}
html={undefined}
meta_title={""}
type={undefined}
/>
);
fireEvent.keyDown(container, { key: "c" });
Expand Down
Loading

0 comments on commit bb57eeb

Please sign in to comment.