Skip to content
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

Merged
merged 11 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Comment on lines +19 to +20
Copy link
Member

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

{ _id: tool._id },
"simulateur-embauche"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peut être passer cela en const

);
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
Expand Up @@ -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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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");
Expand Down
2 changes: 0 additions & 2 deletions packages/code-du-travail-frontend/pages/outils/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
DureePreavisDemission,
DureePreavisLicenciement,
HeuresRechercheEmploi,
SimulateurEmbauche,
SimulateurIndemnitePrecarite,
CalculateurPreavisRetraite,
} from "../../src/outils";
Expand All @@ -38,7 +37,6 @@ const toolsBySlug = {
"preavis-demission": DureePreavisDemission,
"preavis-licenciement": DureePreavisLicenciement,
"preavis-retraite": CalculateurPreavisRetraite,
"simulateur-embauche": SimulateurEmbauche,
"procedure-licenciement": DismissalProcess,
"indemnite-rupture-conventionnelle": CalculateurRuptureConventionnelle,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Up @@ -3,7 +3,7 @@
exports[`<CallToActionTile /> should render 1`] = `
<div>
<div
class="sc-d47d8018-0 ezEIGw sc-98e66f5e-1 fCudut"
class="sc-d47d8018-0 ezEIGw sc-45a05aa-1 jNkAaK"
>
<div
class="sc-d47d8018-2 eBZhiP"
Expand Down Expand Up @@ -53,13 +53,13 @@ exports[`<CallToActionTile /> should render 1`] = `
class="sc-d47d8018-6 ipSAXR"
>
<div
class="sc-98e66f5e-0 bQDuAS"
class="sc-45a05aa-0 dqQtNN"
>
<p>
Cette tuile vous fera dire bonjour !
</p>
<div
class="sc-98e66f5e-2 cDPdrN"
class="sc-45a05aa-2 gcKsUr"
>
<p
class="sc-3633cc97-1 gDIqvu"
Expand Down
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>
);
};
26 changes: 26 additions & 0 deletions packages/code-du-travail-frontend/src/modules/outils/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
} from "../../api/utils";
import { Tool } from "@socialgouv/cdtn-types";
import { SOURCES } from "@socialgouv/cdtn-utils";
import { DocumentElasticResult, fetchDocument } from "../documents";
import { ElasticTool } from "./type";

export const fetchAllTools = async <K extends keyof Tool>(
fields: K[]
Expand Down Expand Up @@ -53,3 +55,27 @@ export const fetchAllTools = async <K extends keyof Tool>(
.map(({ _source }) => _source)
.filter((source) => source !== undefined);
};

export const fetchTool = async (
slug: string
): Promise<DocumentElasticResult<ElasticTool>> => {
const result = await fetchDocument<
ElasticTool,
keyof DocumentElasticResult<ElasticTool>
>(["description", "metaDescription", "metaTitle", "title", "displayTitle"], {
query: {
bool: {
filter: [
{ term: { source: SOURCES.TOOLS } },
{ term: { slug } },
{ term: { isPublished: true } },
],
},
},
size: 1,
});
if (!result) {
throw new Error("Outils non trouvé");
}
return result;
};
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&apos;estimation du salaire net après impôt est basée
sur la situation d&apos;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";
3 changes: 3 additions & 0 deletions packages/code-du-travail-frontend/src/modules/outils/type.ts
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 packages/code-du-travail-frontend/src/outils/SimulateurEmbauche.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/code-du-travail-frontend/src/outils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export * from "./DureePreavisLicenciement";
export * from "./IndemniteLicenciement";
export * from "./HeuresRechercheEmploi";
export * from "./IndemnitePrecarite";
export * from "./SimulateurEmbauche";
export * from "./DismissalProcess";
export * from "./RuptureCoventionnelle";
export * from "./api";
Expand Down
Loading
Loading