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(rupture-co): passage du simulateur en dsfr #6392

Draft
wants to merge 11 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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 IndemniteRuptureCoSimulator from "../../../src/modules/outils/indemnite-rupture-conventionnelle/IndemniteRuptureCoSimulator";

export async function generateMetadata() {
const { metaTitle, metaDescription } = await getTool();

return generateDefaultMetadata({
title: metaTitle,
description: metaDescription,
path: `/outils/indemnite-rupture-conventionnelle`,
});
}

async function IndemniteRuptureCo() {
const tool = await getTool();
const relatedItems = await fetchRelatedItems(
{ _id: tool._id },
"indemnite-rupture-conventionnelle"
);
return (
<DsfrLayout>
<IndemniteRuptureCoSimulator
title={tool.displayTitle}
breadcrumbTitle={tool.title}
relatedItems={relatedItems}
description={tool.description}
/>
</DsfrLayout>
);
}

const getTool = async () => {
const tool = await fetchTool("indemnite-rupture-conventionnelle");

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

export default IndemniteRuptureCo;
6 changes: 2 additions & 4 deletions packages/code-du-travail-frontend/pages/outils/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import { RelatedItems } from "../../src/common/RelatedItems";
import { Share } from "../../src/common/Share";
import { Layout } from "../../src/layout/Layout";
import {
CalculateurIndemniteLicenciement,
CalculateurRuptureConventionnelle,
DismissalProcess,
DureePreavisDemission,
DureePreavisLicenciement,
HeuresRechercheEmploi,
SimulateurIndemnitePrecarite,
CalculateurPreavisRetraite,
CalculateurIndemniteLicenciement,
} from "../../src/outils";
import {
getBySlugTools,
Expand All @@ -30,13 +29,12 @@ import { Tool } from "@socialgouv/cdtn-types";

const toolsBySlug = {
"heures-recherche-emploi": HeuresRechercheEmploi,
"indemnite-licenciement": CalculateurIndemniteLicenciement,
"indemnite-precarite": SimulateurIndemnitePrecarite,
"preavis-demission": DureePreavisDemission,
"preavis-licenciement": DureePreavisLicenciement,
"preavis-retraite": CalculateurPreavisRetraite,
"procedure-licenciement": DismissalProcess,
"indemnite-rupture-conventionnelle": CalculateurRuptureConventionnelle,
"indemnite-licenciement": CalculateurIndemniteLicenciement,
};

export interface Props {
Expand Down
25 changes: 11 additions & 14 deletions packages/code-du-travail-frontend/src/lib/matomo/question.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { push as matopush } from "@socialgouv/matomo-next";

import { MatomoActionEvent, MatomoBaseEvent, MatomoMapping } from ".";
import { sendEvent } from "src/modules/utils";

export const trackQuestion = (
trackTitle: string | null,
Expand All @@ -16,19 +15,17 @@ export const trackQuestion = (
mappingElement.questionLabels.includes(trackTitle.toLowerCase())
) {
if (mappingElement.helpEvent && isTrackingHelp) {
matopush([
MatomoBaseEvent.TRACK_EVENT,
MatomoBaseEvent.OUTIL,
simulatorEvent,
mappingElement.helpEvent,
]);
sendEvent({
category: MatomoBaseEvent.OUTIL,
action: simulatorEvent,
name: mappingElement.helpEvent,
});
} else if (mappingElement.selectEvent && !isTrackingHelp) {
matopush([
MatomoBaseEvent.TRACK_EVENT,
MatomoBaseEvent.OUTIL,
simulatorEvent,
mappingElement.selectEvent,
]);
sendEvent({
category: MatomoBaseEvent.OUTIL,
action: simulatorEvent,
name: mappingElement.selectEvent,
});
}
}
});
Expand Down
32 changes: 30 additions & 2 deletions packages/code-du-travail-frontend/src/modules/common/Html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,44 @@ import { xssWrapper } from "../../lib";
type Props = {
children: string;
as?: string;
inline?: boolean;
className?: string;
};

const Html = ({ children, ...props }: Props): JSX.Element => {
if (props.as === "p") {
return (
<p
dangerouslySetInnerHTML={{
__html: xssWrapper(children),
}}
className={props.className}
/>
);
} else if (props.as === "span") {
return (
<span
dangerouslySetInnerHTML={{
__html: xssWrapper(children),
}}
className={props.className}
/>
);
} else if (props.as === "div") {
return (
<div
dangerouslySetInnerHTML={{
__html: xssWrapper(children),
}}
className={props.className}
/>
);
}
return (
<div
{...props}
dangerouslySetInnerHTML={{
__html: xssWrapper(children),
}}
className={props.className}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { fr } from "@codegouvfr/react-dsfr";
import Alert from "@codegouvfr/react-dsfr/Alert";
import React from "react";

type Props = {
title: string;
message: string;
dataTestId?: string;
};

export const Disclaimer = ({
title,
message,
dataTestId,
}: Props): JSX.Element => (
<Alert
severity="warning"
data-testid={dataTestId}
title={title}
description={message}
className={fr.cx("fr-my-2w")}
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from "react";

export type NoticeNoteProps = {
isList?: boolean;
numberOfElements: number;
currentElement?: number;
};

export const NoticeNote = (props: NoticeNoteProps) => {
const isUniq = React.useMemo(
() => props.numberOfElements === 1,
[props.numberOfElements]
);
return (
<>
{props.isList ? (
<sup>
{isUniq ? (
<>*</>
) : (
<>
{Array.from(Array(props.numberOfElements).keys()).map((i) => (
<span key={i}>({i + 1}) </span>
))}
</>
)}
</sup>
) : (
<sup>{isUniq ? <>*</> : <>({props.currentElement}) </>}</sup>
)}
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { References } from "@socialgouv/modeles-social";
import React from "react";

type Props = {
references: References[];
};

export const PubliReferences: React.FC<Props> = ({ references }) => (
<>
{references && references.length > 0 && (
<>
<h2>Sources</h2>
<ul data-testid="sources">
{references
.filter(({ article }) => article !== null)
.map(({ article, url }, id) => (
<li key={`${url}-${id}`} data-testid={`source-${id}`}>
<a href={url} target="_blank" rel="noopener noreferrer">
{article}
</a>
</li>
))}
</ul>
{references.length === 0 && <li>Source non disponible...</li>}
</>
)}
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from "react";
import Html from "src/modules/common/Html";
import { RadioButtons } from "@codegouvfr/react-dsfr/RadioButtons";

type Question = {
label: string;
value: string;
id: string;
};

type Props = {
onChangeSelectedOption: (value: unknown) => void;
selectedOption: string | undefined;
error?: string;
label: string;
questions: Question[];
name: string;
subLabel?: string;
note?: string;
autoFocus?: boolean;
};

export function RadioQuestion({
selectedOption,
onChangeSelectedOption,
error,
label,
questions,
name,
subLabel,
note,
autoFocus = false,
}: Props) {
const onChange = (value: string) => {
onChangeSelectedOption(value);
};

return (
<div>
<RadioButtons
legend={<Html as="p">{label}</Html>}
options={questions.map((question, index) => ({
name,
label: question.label,
value: question.value,
id: question.id,
"data-testid": `${name} - ${question.label}`,
nativeInputProps: {
checked: selectedOption === question.value,
onChange: () => onChange(question.value),
autoFocus: autoFocus && index === 0,
required: true,
},
}))}
state={error ? "error" : subLabel ? "info" : "default"}
stateRelatedMessage={error || subLabel || undefined}
/>
{note && <i>{note}</i>}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from "react";
import Html from "src/modules/common/Html";
import { Select } from "@codegouvfr/react-dsfr/Select";

type Props = {
name: string;
label: string;
subLabel?: string;
options: Record<string, string> | [string, string][];
error?: string;
onChangeSelectedOption: (value: string) => void;
selectedOption: string | undefined;
autoFocus?: boolean;
};

export const SelectQuestion = ({
name,
label,
subLabel,
options,
error,
onChangeSelectedOption,
selectedOption,
autoFocus = false,
}: Props): JSX.Element => {
const [optionsArray, setOptionsArray] = React.useState<[string, string][]>(
[]
);

React.useEffect(() => {
if (!Array.isArray(options)) {
setOptionsArray(Object.entries(options));
} else {
setOptionsArray(options);
}
}, [options]);

const handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
onChangeSelectedOption(event.target.value);
};

return (
<Select
label={<Html as="span">{label}</Html>}
data-testid={name}
nativeSelectProps={{
onChange: handleChange,
value: selectedOption ?? "",
id: `input-${name}`,
autoFocus,
required: true,
}}
state={error ? "error" : subLabel ? "info" : "default"}
stateRelatedMessage={error || subLabel || undefined}
>
<option value="" disabled>
Sélectionnez une option
</option>
{optionsArray.map(([key, label]) => (
<option key={key} value={key}>
{label}
</option>
))}
</Select>
);
};
Loading
Loading