Skip to content

Commit 07b49df

Browse files
committed
test other than appdir
1 parent 029fbf3 commit 07b49df

File tree

8 files changed

+107
-1
lines changed

8 files changed

+107
-1
lines changed

src/gdpr/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { RegisterGdprServices, GdprService } from "./types";
22
export * from "./constants";
3+
export { GdprStoreProvider } from "./GdprStore";

src/next-pagesdir.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Script from "next/script";
2424
import { assert } from "tsafe/assert";
2525
import "./dsfr/dsfr.css";
2626
import "./dsfr/utility/icons/icons.css";
27+
import { GdprStoreProvider } from "./gdpr/GdprStore";
2728

2829
export type { RegisterLink, RegisteredLinkProps };
2930

@@ -183,7 +184,9 @@ export function createNextDsfrIntegrationApi(
183184
/>
184185
</Head>
185186
{isBrowser ? (
186-
<App {...(props as any)} />
187+
<GdprStoreProvider>
188+
<App {...(props as any)} />
189+
</GdprStoreProvider>
187190
) : (
188191
<SsrIsDarkProvider value={isDark}>
189192
<App {...(props as any)} />

test/integration/cra/src/Home.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ 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"
7+
import { ButtonsGroup } from '@codegouvfr/react-dsfr/ButtonsGroup';
8+
import { consentModalButtonProps } from '@codegouvfr/react-dsfr/ConsentBanner';
69

710
const sideMenuItems = [
811
{
@@ -106,6 +109,7 @@ export function Home() {
106109
/>
107110

108111
<TableExample />
112+
<GdprStoreViewer />
109113
</>
110114
);
111115
}
@@ -126,3 +130,26 @@ function TableExample() {
126130
/>
127131
);
128132
}
133+
134+
135+
export const GdprStoreViewer = () => {
136+
const {consents, firstChoiceMade } = useGdprStore();
137+
138+
return <>
139+
<ButtonsGroup inlineLayoutWhen='always' buttons={[
140+
{
141+
...consentModalButtonProps,
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Header } from "@codegouvfr/react-dsfr/Header";
88
import { fr } from "@codegouvfr/react-dsfr";
99
import { routes } from "./router";
1010
import { Display, headerFooterDisplayItem } from "@codegouvfr/react-dsfr/Display";
11+
import { GdprStoreProvider } from "@codegouvfr/react-dsfr/gdpr";
1112

1213
startReactDsfr({
1314
"defaultColorScheme": "system"
@@ -55,13 +56,15 @@ function Root() {
5556
"maxWidth": 1000,
5657
...fr.spacing("padding", { "topBottom": "10v" })
5758
}}>
59+
<GdprStoreProvider>
5860
{(() => {
5961
switch (route.name) {
6062
case "mui": return <Mui />;
6163
case "home": return <Home />;
6264
case false: return <h1>404</h1>
6365
}
6466
})()}
67+
</GdprStoreProvider>
6568
</div>
6669
<Display />
6770
</div>

test/integration/next-pagesdir/pages/_app.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createEmotionSsrAdvancedApproach } from "tss-react/next";
88
import { useStyles } from "@codegouvfr/react-dsfr/tss";
99
import { fr } from "@codegouvfr/react-dsfr";
1010
import Link from "next/link";
11+
import { ConsentBanner } from "@codegouvfr/react-dsfr/ConsentBanner";
1112

1213

1314
declare module "@codegouvfr/react-dsfr/next-pagesdir" {
@@ -16,6 +17,12 @@ declare module "@codegouvfr/react-dsfr/next-pagesdir" {
1617
}
1718
}
1819

20+
declare module "@codegouvfr/react-dsfr/gdpr" {
21+
interface RegisterGdprServices {
22+
matomo: never;
23+
}
24+
}
25+
1926
const {
2027
withDsfr,
2128
dsfrDocumentApi
@@ -60,6 +67,13 @@ function App({ Component, pageProps }: AppProps) {
6067
"flexDirection": "column"
6168
}}
6269
>
70+
<ConsentBanner gdprPageLink="/mui" siteName='Next Test App' services={[
71+
{
72+
name: "matomo",
73+
title: "Matomo",
74+
description: "User tracking",
75+
}
76+
]} />
6377
<Header
6478
brandTop={brandTop}
6579
serviceTitle="Nom du site / service"

test/integration/next-pagesdir/pages/index.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { Table } from "@codegouvfr/react-dsfr/Table";
66
import { fr } from "@codegouvfr/react-dsfr";
77
import { useIsDark } from "@codegouvfr/react-dsfr/useIsDark";
88
import { useStyles } from "@codegouvfr/react-dsfr/tss";
9+
import { useGdprStore } from "@codegouvfr/react-dsfr/useGdprStore"
10+
import { ButtonsGroup } from '@codegouvfr/react-dsfr/ButtonsGroup';
11+
import { consentModalButtonProps } from '@codegouvfr/react-dsfr/ConsentBanner';
12+
913

1014
export default function App() {
1115
const { isDark, setIsDark } = useIsDark();
@@ -37,6 +41,7 @@ export default function App() {
3741

3842
<SideMenuExample />
3943
<TableExample />
44+
<GdprStoreViewer />
4045
</>
4146
);
4247
}
@@ -170,3 +175,26 @@ function TableExample() {
170175
/>
171176
);
172177
}
178+
179+
180+
export const GdprStoreViewer = () => {
181+
const {consents, firstChoiceMade } = useGdprStore();
182+
183+
return <>
184+
<ButtonsGroup inlineLayoutWhen='always' buttons={[
185+
{
186+
...consentModalButtonProps,
187+
children: "Open Consent"
188+
},
189+
{
190+
children: "Reset Consent",
191+
priority: "secondary",
192+
onClick() {
193+
localStorage.removeItem("dsfr-gdpr-consent");
194+
location.reload();
195+
}
196+
}
197+
]} />
198+
<pre>{JSON.stringify({consents, firstChoiceMade})}</pre>
199+
</>;
200+
}

test/integration/vite/src/Home.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Alert } from "@codegouvfr/react-dsfr/Alert";
22
import { fr } from "@codegouvfr/react-dsfr";
33
import { useIsDark } from "@codegouvfr/react-dsfr/useIsDark";
44
import { Table } from "@codegouvfr/react-dsfr/Table";
5+
import { useGdprStore } from "@codegouvfr/react-dsfr/useGdprStore"
6+
import { ButtonsGroup } from '@codegouvfr/react-dsfr/ButtonsGroup';
7+
import { consentModalButtonProps } from '@codegouvfr/react-dsfr/ConsentBanner';
58

69
export function Home() {
710
const { isDark, setIsDark } = useIsDark();
@@ -31,6 +34,7 @@ export function Home() {
3134
<button onClick={() => setIsDark("system")}>Set color scheme to system</button>
3235

3336
<TableExample />
37+
<GdprStoreViewer />
3438
</>
3539
);
3640
}
@@ -51,3 +55,26 @@ function TableExample() {
5155
/>
5256
);
5357
}
58+
59+
60+
export const GdprStoreViewer = () => {
61+
const {consents, firstChoiceMade } = useGdprStore();
62+
63+
return <>
64+
<ButtonsGroup inlineLayoutWhen='always' buttons={[
65+
{
66+
...consentModalButtonProps,
67+
children: "Open Consent"
68+
},
69+
{
70+
children: "Reset Consent",
71+
priority: "secondary",
72+
onClick() {
73+
localStorage.removeItem("dsfr-gdpr-consent");
74+
location.reload();
75+
}
76+
}
77+
]} />
78+
<pre>{JSON.stringify({consents, firstChoiceMade})}</pre>
79+
</>;
80+
}

test/integration/vite/src/main.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { BrowserRouter } from "react-router-dom";
99
import { Routes, Route, Link, useLocation } from "react-router-dom";
1010
import { Display, headerFooterDisplayItem } from "@codegouvfr/react-dsfr/Display";
1111
import { fr } from "@codegouvfr/react-dsfr";
12+
import { GdprStoreProvider } from "@codegouvfr/react-dsfr/gdpr";
1213

1314
startReactDsfr({ "defaultColorScheme": "system", Link });
1415

@@ -71,11 +72,13 @@ function Root() {
7172
"maxWidth": 1000,
7273
...fr.spacing("padding", { "topBottom": "10v" })
7374
}}>
75+
<GdprStoreProvider>
7476
<Routes>
7577
<Route path="/" element={<Home />} />
7678
<Route path="/mui" element={<Mui />} />
7779
<Route path="*" element={<h1>404</h1>} />
7880
</Routes>
81+
</GdprStoreProvider>
7982
</div>
8083
<Footer
8184
brandTop={brandTop}

0 commit comments

Comments
 (0)