Skip to content

Commit d26db43

Browse files
authored
fix(contributions): modification des events sur les contribs generiques pour être ISO avec ce qu'on avait avant le passage au DSFR (#6443)
1 parent 397232c commit d26db43

27 files changed

+674
-313
lines changed

packages/code-du-travail-frontend/app/outils/convention-collective/convention/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { DsfrLayout } from "../../../../src/modules/layout";
2-
import { DocumentElasticResult } from "../../../../src/modules/documents";
32
import { fetchTool, FindAgreementLayout } from "../../../../src/modules/outils";
43
import { notFound } from "next/navigation";
54
import { generateDefaultMetadata } from "../../../../src/modules/common/metas";
6-
import { ElasticTool } from "../../../../src/modules/outils/type";
75
import { AgreementSearch } from "../../../../src/modules/convention-collective";
86
import { agreementRelatedItems } from "../../../../src/modules/convention-collective/agreementRelatedItems";
97
import { SITE_URL } from "../../../../src/config";
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
import { css } from "@styled-system/css";
3+
import { fr } from "@codegouvfr/react-dsfr";
4+
5+
type Props = {
6+
children: React.ReactNode;
7+
};
8+
9+
const BlueCard = ({ children, ...props }: Props): JSX.Element => {
10+
return (
11+
<div
12+
{...props}
13+
className={`${fr.cx("fr-px-1w", "fr-px-md-3w", "fr-py-3w", "fr-mb-6w")} ${block}`}
14+
>
15+
{children}
16+
</div>
17+
);
18+
};
19+
20+
export default BlueCard;
21+
22+
const block = css({
23+
background: "var(--background-alt-blue-cumulus)",
24+
});

packages/code-du-travail-frontend/src/modules/common/useLocalStorage.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,3 @@ export const getAgreementFromLocalStorage = ():
7373
console.error(e);
7474
}
7575
};
76-
77-
export const removeAgreementFromLocalStorage = () => {
78-
try {
79-
if (window?.localStorage) {
80-
window.localStorage.removeItem(STORAGE_KEY_AGREEMENT);
81-
}
82-
} catch (e) {
83-
console.error(e);
84-
}
85-
};

packages/code-du-travail-frontend/src/modules/contributions/ContributionAgreemeentSelect.tsx

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"use client";
2+
import React from "react";
3+
import { css } from "@styled-system/css";
4+
import { fr } from "@codegouvfr/react-dsfr";
5+
import { ContributionAgreementContent } from "./ContributionAgreementContent";
6+
import { Contribution } from "./type";
7+
import { removeCCNumberFromSlug } from "../common/utils";
8+
import BlueCard from "../common/BlueCard";
9+
import Card from "@codegouvfr/react-dsfr/Card";
10+
import Button from "@codegouvfr/react-dsfr/Button";
11+
12+
type Props = {
13+
contribution: Contribution;
14+
};
15+
16+
export function ContributionAgreement({ contribution }: Props) {
17+
const { slug, relatedItems } = contribution;
18+
19+
return (
20+
<>
21+
<BlueCard>
22+
<p className={fr.cx("fr-h3", "fr-mt-1w")}>
23+
Votre convention collective
24+
</p>
25+
<Card
26+
title={`${contribution.ccnShortTitle} (IDCC ${contribution.idcc})`}
27+
size="small"
28+
titleAs="h2"
29+
className={fr.cx("fr-mt-2w")}
30+
classes={{
31+
content: fr.cx("fr-p-2w"),
32+
title: cardTitle,
33+
start: fr.cx("fr-m-0"),
34+
end: fr.cx("fr-p-0", "fr-m-0"),
35+
}}
36+
/>
37+
<Button
38+
className={fr.cx("fr-mt-2w")}
39+
linkProps={{
40+
href: `/contribution/${removeCCNumberFromSlug(slug)}`,
41+
}}
42+
priority="secondary"
43+
iconId="fr-icon-arrow-go-back-line"
44+
iconPosition="right"
45+
>
46+
Modifier
47+
</Button>
48+
</BlueCard>
49+
50+
<ContributionAgreementContent
51+
contribution={contribution}
52+
relatedItems={relatedItems}
53+
/>
54+
</>
55+
);
56+
}
57+
58+
const cardTitle = css({
59+
fontWeight: "normal!",
60+
});
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"use client";
2+
import React, { useState } from "react";
3+
import { useContributionTracking } from "./tracking";
4+
import { isAgreementSupported, isAgreementValid } from "./contributionUtils";
5+
import { ContributionGenericContent } from "./ContributionGenericContent";
6+
import { Contribution } from "./type";
7+
import { useLocalStorageForAgreement } from "../common/useLocalStorage";
8+
import { ContributionGenericAgreementSearch } from "./ContributionGenericAgreementSearch";
9+
import { Button } from "@codegouvfr/react-dsfr/Button";
10+
import { fr } from "@codegouvfr/react-dsfr";
11+
12+
type Props = {
13+
contribution: Contribution;
14+
};
15+
16+
export function ContributionGeneric({ contribution }: Props) {
17+
const getTitle = () => `/contribution/${slug}`;
18+
const { slug, isNoCDT, relatedItems } = contribution;
19+
20+
const [displayGeneric, setDisplayGeneric] = useState(false);
21+
22+
const [selectedAgreement, setSelectedAgreement] =
23+
useLocalStorageForAgreement();
24+
const {
25+
emitAgreementTreatedEvent,
26+
emitAgreementUntreatedEvent,
27+
emitDisplayAgreementContent,
28+
emitDisplayGeneralContent,
29+
emitDisplayGenericContent,
30+
emitClickP3,
31+
} = useContributionTracking();
32+
33+
return (
34+
<>
35+
<ContributionGenericAgreementSearch
36+
contribution={contribution}
37+
onAgreementSelect={(agreement) => {
38+
setSelectedAgreement(agreement);
39+
setDisplayGeneric(false);
40+
if (!agreement) return;
41+
42+
if (isAgreementSupported(contribution, agreement)) {
43+
emitAgreementTreatedEvent(agreement.num);
44+
} else {
45+
emitAgreementUntreatedEvent(agreement.num);
46+
}
47+
}}
48+
onDisplayClick={(ev) => {
49+
setDisplayGeneric(!displayGeneric);
50+
if (
51+
!isAgreementValid(contribution, selectedAgreement) ||
52+
!selectedAgreement
53+
) {
54+
ev.preventDefault();
55+
setDisplayGeneric(true);
56+
if (selectedAgreement) {
57+
emitDisplayGeneralContent(getTitle());
58+
} else {
59+
emitDisplayGenericContent(getTitle());
60+
}
61+
} else {
62+
emitDisplayAgreementContent(getTitle());
63+
}
64+
}}
65+
defaultAgreement={selectedAgreement}
66+
trackingActionName={getTitle()}
67+
/>
68+
69+
{!isNoCDT && !isAgreementValid(contribution, selectedAgreement) && (
70+
<>
71+
{!displayGeneric && (
72+
<Button
73+
className={fr.cx("fr-mb-6w")}
74+
priority="tertiary no outline"
75+
onClick={() => {
76+
setDisplayGeneric(true);
77+
emitClickP3(getTitle());
78+
}}
79+
>
80+
Afficher les informations sans sélectionner une convention
81+
collective
82+
</Button>
83+
)}
84+
<ContributionGenericContent
85+
contribution={contribution}
86+
relatedItems={relatedItems}
87+
displayGeneric={displayGeneric}
88+
alertText={
89+
selectedAgreement &&
90+
!isAgreementSupported(contribution, selectedAgreement) && (
91+
<p>
92+
<strong>
93+
Cette réponse correspond à ce que prévoit le code du
94+
travail, elle ne tient pas compte des spécificités de la{" "}
95+
{selectedAgreement.shortTitle}
96+
</strong>
97+
</p>
98+
)
99+
}
100+
/>
101+
</>
102+
)}
103+
</>
104+
);
105+
}

packages/code-du-travail-frontend/src/modules/contributions/ContributionGenericAgreementSearch.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
"use client";
22
import React, { useEffect, useState } from "react";
33
import { Button } from "@codegouvfr/react-dsfr/Button";
4-
import { css } from "@styled-system/css";
54
import { fr } from "@codegouvfr/react-dsfr";
65
import Image from "next/image";
76
import AgreementSearch from "../convention-collective/AgreementSearch.svg";
87

9-
import { AgreementSearchForm } from "../convention-collective/AgreementSearch/AgreementSearchForm";
108
import { EnterpriseAgreement } from "../enterprise";
119
import {
1210
isAgreementSupported,
@@ -15,21 +13,25 @@ import {
1513
} from "./contributionUtils";
1614
import { Contribution } from "./type";
1715
import Link from "../common/Link";
16+
import BlueCard from "../common/BlueCard";
17+
import { AgreementSearchForm } from "../convention-collective/AgreementSearch/AgreementSearchForm";
1818

1919
type Props = {
20-
onAgreementSelect: (agreement?: EnterpriseAgreement, mode?: string) => void;
20+
onAgreementSelect: (agreement?: EnterpriseAgreement) => void;
2121
onDisplayClick: (ev: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => void;
2222
contribution: Contribution;
2323
defaultAgreement?: EnterpriseAgreement;
24+
trackingActionName: string;
2425
};
2526

2627
export function ContributionGenericAgreementSearch({
2728
contribution,
2829
onAgreementSelect,
2930
onDisplayClick,
3031
defaultAgreement,
32+
trackingActionName,
3133
}: Props) {
32-
const { slug, isNoCDT } = contribution;
34+
const { slug } = contribution;
3335

3436
const [selectedAgreement, setSelectedAgreement] =
3537
useState<EnterpriseAgreement>();
@@ -80,12 +82,12 @@ export function ContributionGenericAgreementSearch({
8082
return <>Vous pouvez consulter les informations générales ci-dessous.</>;
8183
};
8284
return (
83-
<div className={`${fr.cx("fr-p-3w", "fr-mt-6w")} ${block}`}>
85+
<BlueCard>
8486
<div className={fr.cx("fr-grid-row")}>
8587
<Image
8688
priority
8789
src={AgreementSearch}
88-
alt="Personnalisez la réponse avec votre convention collective"
90+
alt=""
8991
className={fr.cx("fr-unhidden-md", "fr-hidden")}
9092
/>
9193
<p className={fr.cx("fr-h3", "fr-mt-1w")}>
@@ -94,14 +96,15 @@ export function ContributionGenericAgreementSearch({
9496
</div>
9597
<div>
9698
<AgreementSearchForm
97-
onAgreementSelect={(agreement, mode) => {
98-
onAgreementSelect(agreement, mode);
99+
onAgreementSelect={(agreement) => {
100+
onAgreementSelect(agreement);
99101
setSelectedAgreement(
100102
isAgreementValid(contribution, agreement) ? agreement : undefined
101103
);
102104
}}
103105
selectedAgreementAlert={selectedAgreementAlert}
104106
defaultAgreement={defaultAgreement}
107+
trackingActionName={trackingActionName}
105108
/>
106109
{((contribution.isNoCDT && isValid) || !contribution.isNoCDT) && (
107110
<Button
@@ -117,10 +120,6 @@ export function ContributionGenericAgreementSearch({
117120
</Button>
118121
)}
119122
</div>
120-
</div>
123+
</BlueCard>
121124
);
122125
}
123-
124-
const block = css({
125-
background: "var(--background-alt-blue-cumulus)!",
126-
});

0 commit comments

Comments
 (0)