-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DSFR): salaire brut / net (#6260)
* Revert "fix(simulateur embauche): revert DSFR sur simulateur embauche (#6245)" This reverts commit 6a359dd. * add click in test * try to memoised * update meta data * fix snapshots * more logging * sans aysnc * fix!!
- Loading branch information
1 parent
c296467
commit 43505f5
Showing
12 changed files
with
195 additions
and
97 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/code-du-travail-frontend/app/outils/simulateur-embauche/page.tsx
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,45 @@ | ||
import { DsfrLayout } from "../../../src/modules/layout"; | ||
import { fetchRelatedItems } from "../../../src/modules/documents"; | ||
import { fetchTool } from "../../../src/modules/outils"; | ||
import { notFound } from "next/navigation"; | ||
import { generateDefaultMetadata } from "../../../src/modules/common/metas"; | ||
import HiringSimulator from "../../../src/modules/outils/simulateur-embauche/HiringSimulator"; | ||
|
||
export async function generateMetadata() { | ||
const { metaTitle, metaDescription } = await getTool(); | ||
|
||
return generateDefaultMetadata({ | ||
title: metaTitle, | ||
description: metaDescription, | ||
path: `/outils/simulateur-embauche`, | ||
}); | ||
} | ||
|
||
async function HiringSimulatorPage() { | ||
const tool = await getTool(); | ||
const relatedItems = await fetchRelatedItems( | ||
{ _id: tool._id }, | ||
"simulateur-embauche" | ||
); | ||
return ( | ||
<DsfrLayout> | ||
<HiringSimulator | ||
title={tool.displayTitle} | ||
breadcrumbTitle={tool.title} | ||
relatedItems={relatedItems} | ||
description={tool.description} | ||
/> | ||
</DsfrLayout> | ||
); | ||
} | ||
|
||
const getTool = async () => { | ||
const tool = await fetchTool("simulateur-embauche"); | ||
|
||
if (!tool) { | ||
return notFound(); | ||
} | ||
return tool; | ||
}; | ||
|
||
export default HiringSimulatorPage; |
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
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
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
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
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
102 changes: 102 additions & 0 deletions
102
packages/code-du-travail-frontend/src/modules/outils/simulateur-embauche/HiringSimulator.tsx
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,102 @@ | ||
"use client"; | ||
import { Highlight } from "@codegouvfr/react-dsfr/Highlight"; | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import { createRef, memo, useEffect, useState } from "react"; | ||
import { ContainerSimulator } from "../../layout/ContainerSimulator"; | ||
import { RelatedItem } from "../../documents"; | ||
import * as Sentry from "@sentry/nextjs"; | ||
|
||
type Props = { | ||
relatedItems: { | ||
items: RelatedItem[]; | ||
title: string; | ||
}[]; | ||
title: string; | ||
breadcrumbTitle: string; | ||
description: string; | ||
}; | ||
|
||
const HiringSimulator = memo(function HiringSimulator({ | ||
relatedItems, | ||
description, | ||
title, | ||
breadcrumbTitle, | ||
}: Props) { | ||
const simRef = createRef<HTMLDivElement>(); | ||
const [state, setState] = useState({ | ||
error: "", | ||
simulator: "loading", | ||
}); | ||
const onError = (error) => { | ||
console.log(`Erreur durant le chargement de l'iframe brut/net ${error}`); | ||
setState({ error, simulator: "error" }); | ||
Sentry.captureMessage(`Erreur durant le chargement de l'iframe brut/net`); | ||
}; | ||
|
||
const onLoad = () => { | ||
setState({ simulator: "success", error: "" }); | ||
if (!simRef.current?.querySelector("#simulateurEmbauche")) { | ||
console.log( | ||
`Erreur durant le chargement de l'iframe brut/net, "empty child"` | ||
); | ||
setState({ error: "empty child", simulator: "error" }); | ||
Sentry.captureMessage( | ||
`Erreur durant le chargement de l'iframe brut/net "empty child"` | ||
); | ||
} | ||
}; | ||
useEffect(() => { | ||
const script = document.createElement("script"); | ||
|
||
script.src = | ||
"https://mon-entreprise.urssaf.fr/simulateur-iframe-integration.js"; | ||
script.id = "script-simulateur-embauche"; | ||
script.onload = onLoad; | ||
script.onerror = onError; | ||
|
||
if (simRef.current) { | ||
simRef.current.appendChild(script); | ||
} | ||
|
||
return () => { | ||
if (simRef.current) { | ||
simRef.current.removeChild(script); | ||
} | ||
}; | ||
}, []); | ||
const { simulator } = state; | ||
return ( | ||
<ContainerSimulator | ||
relatedItems={relatedItems} | ||
title={breadcrumbTitle} | ||
description={description} | ||
segments={[{ label: "Simulateurs", linkProps: { href: "/outils" } }]} | ||
> | ||
<h1 id="simulateur-embauche">{title}</h1> | ||
<Highlight size="lg" className={fr.cx("fr-mb-12v")}> | ||
Pour information, l'estimation du salaire net après impôt est basée | ||
sur la situation d'une personne célibataire sans enfants ni | ||
patrimoine. | ||
</Highlight> | ||
{simulator === "loading" && <p>Chargement de l’outil</p>} | ||
{simulator === "error" ? ( | ||
<p> | ||
Le simulateur d’embauche n’est pas disponible actuellement. | ||
<br /> | ||
Retrouvez les autres simulateurs autour du thème de l’entreprise, sur | ||
le site:{" "} | ||
<a | ||
title="Voir les simulateurs" | ||
href="https://mon-entreprise.urssaf.fr/" | ||
> | ||
https://mon-entreprise.urssaf.fr/ | ||
</a> | ||
</p> | ||
) : ( | ||
<div ref={simRef} className={fr.cx("fr-col-12")} /> | ||
)} | ||
</ContainerSimulator> | ||
); | ||
}); | ||
|
||
export default HiringSimulator; |
1 change: 1 addition & 0 deletions
1
packages/code-du-travail-frontend/src/modules/outils/simulateur-embauche/index.ts
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 @@ | ||
export * from "./HiringSimulator"; |
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,3 @@ | ||
import { DocumentElasticWithSource, Tool } from "@socialgouv/cdtn-types"; | ||
|
||
export type ElasticTool = DocumentElasticWithSource<Tool>; |
80 changes: 0 additions & 80 deletions
80
packages/code-du-travail-frontend/src/outils/SimulateurEmbauche.js
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.