-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(DSFR): salaire brut / net #6260
Changes from 9 commits
cbbc8de
692a54a
504e521
900dee3
534031a
1971bb2
367dd77
e5f75d9
4244206
5e43e9d
83bcddb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. peut être passer cela en |
||
); | ||
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,11 @@ import "cypress-iframe"; | |
describe("Outil - Salaire brut/net", () => { | ||
it("Valider que le simulateur s'affiche correctement dans l'iframe", () => { | ||
cy.visit("/outils/simulateur-embauche"); | ||
cy.get("h1").should("have.text", "Calculer le salaire brut/net"); | ||
cy.findByRole("heading", { level: 1 }).should( | ||
"have.text", | ||
"Calculer le salaire brut/net" | ||
); | ||
cy.findByRole("heading", { level: 1 }).click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. c'est ça qui fixe le test 🤷♀️ |
||
cy.iframe("#simulateurEmbauche") | ||
.contains("Coût total employeur") | ||
.should("be.visible"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ const StyledDiv = styled.div` | |
height: 1.4rem; | ||
margin: 0 ${spacings.tiny} 0 ${spacings.small}; | ||
transition: transform ${theme.animations.transitionTiming} linear; | ||
fill: ${theme.primary}; | ||
fill: ${theme.colors.primary}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. j'ai fixé un warning qui apparaissait dans la console |
||
} | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { fr } from "@codegouvfr/react-dsfr"; | ||
import { Breadcrumb, BreadcrumbProps } from "@codegouvfr/react-dsfr/Breadcrumb"; | ||
|
||
import { RelatedItems } from "../common/RelatedItems"; | ||
import { Share } from "../common/Share"; | ||
import { RelatedItem } from "../documents"; | ||
import { Feedback } from "../layout/feedback"; | ||
|
||
type Props = { | ||
relatedItems: { items: RelatedItem[]; title: string }[]; | ||
title: string; | ||
description: string; | ||
children: React.ReactNode; | ||
} & Pick<BreadcrumbProps, "segments">; | ||
|
||
export const ContainerSimulator = ({ | ||
children, | ||
relatedItems, | ||
title, | ||
description, | ||
segments = [], | ||
}: Props) => { | ||
return ( | ||
<div className={fr.cx("fr-grid-row")}> | ||
<Breadcrumb | ||
currentPageLabel={title} | ||
homeLinkProps={{ | ||
href: "/", | ||
}} | ||
segments={segments} | ||
className={fr.cx("fr-mb-2v")} | ||
/> | ||
<div> | ||
{children} | ||
<div className={fr.cx("fr-col-12", "fr-col-md-7", "fr-my-12v")}> | ||
<Feedback /> | ||
</div> | ||
</div> | ||
<div className={fr.cx("fr-col-12", "fr-col-md-8")}> | ||
<RelatedItems relatedItems={relatedItems} /> | ||
</div> | ||
<div className={fr.cx("fr-col-12", "fr-col-md-4", "fr-mb-12v")}> | ||
<Share title={title} metaDescription={description} /> | ||
</div> | ||
</div> | ||
); | ||
}; |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./HiringSimulator"; |
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>; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c'est dommage qu'on fasse les deux calls en asynchrone. il faudra voir comment optimiser cette page en utilisant la logique statique de nextjs avec du cache.
car en soit, je pense pas que les info de l'outil et les related items changent tous les jours
ça pourrait drastiquement augmenter nos performances sur cette page