Skip to content

Commit f015361

Browse files
committed
Fix integration apps
1 parent 837345c commit f015361

File tree

5 files changed

+102
-130
lines changed

5 files changed

+102
-130
lines changed

test/integration/cra/src/Home.tsx

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { fr } from "@codegouvfr/react-dsfr";
33
import { useIsDark } from "@codegouvfr/react-dsfr/useIsDark";
44
import { SideMenu } from "@codegouvfr/react-dsfr/SideMenu";
55
import { Table } from "@codegouvfr/react-dsfr/Table";
6-
import { useGdprStore } from "@codegouvfr/react-dsfr/useGdprStore"
76
import { ButtonsGroup } from '@codegouvfr/react-dsfr/ButtonsGroup';
8-
import { consentModalNativeButtonProps } from '@codegouvfr/react-dsfr/ConsentBanner';
97

108
const sideMenuItems = [
119
{
@@ -109,7 +107,6 @@ export function Home() {
109107
/>
110108

111109
<TableExample />
112-
<GdprStoreViewer />
113110
</>
114111
);
115112
}
@@ -131,25 +128,3 @@ function TableExample() {
131128
);
132129
}
133130

134-
135-
export const GdprStoreViewer = () => {
136-
const {consents, firstChoiceMade } = useGdprStore();
137-
138-
return <>
139-
<ButtonsGroup inlineLayoutWhen='always' buttons={[
140-
{
141-
"nativeButtonProps": consentModalNativeButtonProps,
142-
children: "Open Consent"
143-
},
144-
{
145-
children: "Reset Consent",
146-
priority: "secondary",
147-
onClick() {
148-
localStorage.removeItem("dsfr-gdpr-consent");
149-
window.location.reload();
150-
}
151-
}
152-
]} />
153-
<pre>{JSON.stringify({consents, firstChoiceMade})}</pre>
154-
</>;
155-
}

test/integration/cra/src/index.tsx

Lines changed: 44 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,12 @@ import { Header } from "@codegouvfr/react-dsfr/Header";
99
import { fr } from "@codegouvfr/react-dsfr";
1010
import { routes } from "./router";
1111
import { headerFooterDisplayItem } from "@codegouvfr/react-dsfr/Display";
12-
import { GdprStoreProvider } from "@codegouvfr/react-dsfr/gdpr";
13-
import { ConsentBanner } from '@codegouvfr/react-dsfr/ConsentBanner';
1412

1513

1614
startReactDsfr({
1715
"defaultColorScheme": "system"
1816
});
1917

20-
declare module "@codegouvfr/react-dsfr/gdpr" {
21-
interface RegisterGdprServices {
22-
matomo: never;
23-
}
24-
}
2518

2619
createRoot(document.getElementById("root")!).render(
2720
<StrictMode>
@@ -46,62 +39,53 @@ function Root() {
4639
}
4740
}}
4841
/>
49-
<GdprStoreProvider>
50-
<ConsentBanner gdprLinkProps={{ href: "/mui" }} siteName='Next Test App' services={[
51-
{
52-
name: "matomo",
53-
title: "Matomo",
54-
description: "User tracking",
55-
}
56-
]} />
42+
<div style={{
43+
"minHeight": "100vh",
44+
"display": "flex",
45+
"flexDirection": "column",
46+
}}>
47+
<Header
48+
brandTop={<>INTITULE<br />OFFICIEL</>}
49+
serviceTitle="Nom du site / service"
50+
quickAccessItems={[
51+
headerFooterDisplayItem,
52+
{
53+
iconId: "ri-mail-line",
54+
linkProps: {
55+
href: `mailto:${"joseph.garrone@code.gouv.fr"}`,
56+
},
57+
text: "Nous contacter",
58+
}
59+
]}
60+
homeLinkProps={{ ...routes.home().link, "title": "Accueil - Nom de l’entité (ministère, secrétariat d‘état, gouvernement)" }}
61+
navigation={[
62+
{
63+
"text": "Home",
64+
"linkProps": routes.home().link,
65+
"isActive": route.name === "home"
66+
},
67+
{
68+
"text": "Mui playground",
69+
"linkProps": routes.mui().link,
70+
"isActive": route.name === "mui"
71+
}
72+
]}
73+
/>
5774
<div style={{
58-
"minHeight": "100vh",
59-
"display": "flex",
60-
"flexDirection": "column",
75+
"flex": 1,
76+
"margin": "auto",
77+
"maxWidth": 1000,
78+
...fr.spacing("padding", { "topBottom": "10v" })
6179
}}>
62-
<Header
63-
brandTop={<>INTITULE<br />OFFICIEL</>}
64-
serviceTitle="Nom du site / service"
65-
quickAccessItems={[
66-
headerFooterDisplayItem,
67-
{
68-
iconId: "ri-mail-line",
69-
linkProps: {
70-
href: `mailto:${"joseph.garrone@code.gouv.fr"}`,
71-
},
72-
text: "Nous contacter",
73-
}
74-
]}
75-
homeLinkProps={{ ...routes.home().link, "title": "Accueil - Nom de l’entité (ministère, secrétariat d‘état, gouvernement)" }}
76-
navigation={[
77-
{
78-
"text": "Home",
79-
"linkProps": routes.home().link,
80-
"isActive": route.name === "home"
81-
},
82-
{
83-
"text": "Mui playground",
84-
"linkProps": routes.mui().link,
85-
"isActive": route.name === "mui"
86-
}
87-
]}
88-
/>
89-
<div style={{
90-
"flex": 1,
91-
"margin": "auto",
92-
"maxWidth": 1000,
93-
...fr.spacing("padding", { "topBottom": "10v" })
94-
}}>
95-
{(() => {
96-
switch (route.name) {
97-
case "mui": return <Mui />;
98-
case "home": return <Home />;
99-
case false: return <h1>404</h1>
100-
}
101-
})()}
102-
</div>
80+
{(() => {
81+
switch (route.name) {
82+
case "mui": return <Mui />;
83+
case "home": return <Home />;
84+
case false: return <h1>404</h1>
85+
}
86+
})()}
10387
</div>
104-
</GdprStoreProvider>
88+
</div>
10589
</>
10690
);
10791

test/integration/vite/src/Home.tsx

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { fr } from "@codegouvfr/react-dsfr";
99
import { useIsDark } from "@codegouvfr/react-dsfr/useIsDark";
1010
import { useState } from "react";
1111
import { Table } from "@codegouvfr/react-dsfr/Table";
12-
import { useGdprStore } from "@codegouvfr/react-dsfr/useGdprStore"
13-
import { consentModalNativeButtonProps } from '@codegouvfr/react-dsfr/ConsentBanner';
1412

1513
export function Home() {
1614
const { isDark, setIsDark } = useIsDark();
@@ -68,8 +66,6 @@ export function Home() {
6866
</div>
6967
<Form />
7068
<TableExample />
71-
<GdprStoreViewer />
72-
7369
</>
7470
);
7571
}
@@ -207,24 +203,3 @@ function TableExample() {
207203
}
208204

209205

210-
export const GdprStoreViewer = () => {
211-
const {consents, firstChoiceMade } = useGdprStore();
212-
213-
return <>
214-
<ButtonsGroup inlineLayoutWhen='always' buttons={[
215-
{
216-
"nativeButtonProps": consentModalNativeButtonProps,
217-
children: "Open Consent"
218-
},
219-
{
220-
children: "Reset Consent",
221-
priority: "secondary",
222-
onClick() {
223-
localStorage.removeItem("dsfr-gdpr-consent");
224-
location.reload();
225-
}
226-
}
227-
]} />
228-
<pre>{JSON.stringify({consents, firstChoiceMade})}</pre>
229-
</>;
230-
}

test/integration/vite/src/gdpr.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"use client";
2+
3+
import { createGdprApi } from "@codegouvfr/react-dsfr/gdpr";
4+
5+
export const {
6+
ConsentBannerAndConsentManagement,
7+
useGdpr,
8+
FooterConsentManagementItem,
9+
FooterPersonalDataPolicyItem
10+
} = createGdprApi({
11+
"finalityDescription": ({ lang }) => ({
12+
"advertising": {
13+
"title": "Publicité",
14+
"description": "Nous utilisons des cookies pour vous proposer des publicités adaptées à vos centres d’intérêts et mesurer leur efficacité."
15+
},
16+
"analytics": {
17+
"title": "Analyse",
18+
"description": "Nous utilisons des cookies pour mesurer l’audience de notre site et améliorer son contenu."
19+
},
20+
"personalization": {
21+
"title": "Personnalisation",
22+
"description": "Nous utilisons des cookies pour vous proposer des contenus adaptés à vos centres d’intérêts."
23+
},
24+
"statistics": {
25+
"title": "Statistiques",
26+
"description": "Nous utilisons des cookies pour mesurer l’audience de notre site et améliorer son contenu.",
27+
"subFinalities": {
28+
"deviceInfo": "Informations sur votre appareil",
29+
"traffic": "Informations sur votre navigation",
30+
}
31+
}
32+
}),
33+
"personalDataPolicyLinkProps": {
34+
"to": "#",
35+
"onClick": ()=> {
36+
alert("Navigate or display your data policy");
37+
}
38+
},
39+
"consentCallback": async ({ finalityConsent, finalityConsent_prev })=> {
40+
console.log("callback from gdpr hook", { finalityConsent, finalityConsent_prev });
41+
}
42+
});
43+
44+
45+
46+

test/integration/vite/src/main.tsx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { Routes, Route, Link, useLocation } from "react-router-dom";
1010
import { headerFooterDisplayItem } from "@codegouvfr/react-dsfr/Display";
1111
import { GlobalStyles } from "tss-react";
1212
import { fr } from "@codegouvfr/react-dsfr";
13-
import { GdprStoreProvider } from "@codegouvfr/react-dsfr/gdpr";
14-
import { ConsentBanner } from '@codegouvfr/react-dsfr/ConsentBanner';
13+
import { ConsentBannerAndConsentManagement, FooterConsentManagementItem, FooterPersonalDataPolicyItem } from "./gdpr";
1514

1615
startReactDsfr({ "defaultColorScheme": "system", Link });
1716

@@ -21,11 +20,6 @@ declare module "@codegouvfr/react-dsfr/spa" {
2120
}
2221
}
2322

24-
declare module "@codegouvfr/react-dsfr/gdpr" {
25-
interface RegisterGdprServices {
26-
matomo: never;
27-
}
28-
}
2923

3024
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
3125
<React.StrictMode>
@@ -52,21 +46,15 @@ function Root() {
5246
const location = useLocation();
5347

5448
return (
55-
<GdprStoreProvider>
56-
<ConsentBanner gdprLinkProps={{ to: "/mui" }} siteName='Next Test App' services={[
57-
{
58-
name: "matomo",
59-
title: "Matomo",
60-
description: "User tracking",
61-
}
62-
]} />
49+
<>
50+
<ConsentBannerAndConsentManagement />
6351
<div style={{ "minHeight": "100vh", "display": "flex", "flexDirection": "column" }}>
6452
<Header
6553
brandTop={<>INTITULE<br />OFFICIEL</>}
6654
serviceTitle="Nom du site / service"
67-
homeLinkProps={{
68-
"to": "/",
69-
"title": "Accueil - Nom de l’entité (ministère, secrétariat d‘état, gouvernement)"
55+
homeLinkProps={{
56+
"to": "/",
57+
"title": "Accueil - Nom de l’entité (ministère, secrétariat d‘état, gouvernement)"
7058
}}
7159
quickAccessItems={[
7260
headerFooterDisplayItem,
@@ -123,10 +111,14 @@ function Root() {
123111
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
124112
eu fugiat nulla pariatur.
125113
`}
126-
bottomItems={[headerFooterDisplayItem]}
114+
bottomItems={[
115+
headerFooterDisplayItem,
116+
<FooterPersonalDataPolicyItem />,
117+
<FooterConsentManagementItem />
118+
]}
127119
/>
128120
</div>
129-
</GdprStoreProvider>
121+
</>
130122
);
131123

132124
}

0 commit comments

Comments
 (0)