Skip to content

Commit 21790bb

Browse files
committed
reaname rgpt -> consentManagement
1 parent f015361 commit 21790bb

File tree

18 files changed

+352
-174
lines changed

18 files changed

+352
-174
lines changed

.storybook/preview.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const { getHardCodedWeight } = (() => {
104104
//"components",
105105
"components/Header",
106106
"components/Footer",
107+
"components/consentManagement",
107108
"components/Alert",
108109
"components/Tabs",
109110
"components/Stepper",

src/gdpr/ConsentBannerAndConsentManagement/ConsentBannerAndConsentManagement.tsx renamed to src/consentManagement/ConsentBannerAndConsentManagement/ConsentBannerAndConsentManagement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function createFooterPersonalDataPolicyItem(params: {
126126
if (personalDataPolicyLinkProps === undefined) {
127127
throw new Error(
128128
[
129-
"You should provide a personalDataPolicyLinkProps to createGdprApi if",
129+
"You should provide a personalDataPolicyLinkProps to createConsentManagement if",
130130
"you want to add a link to the personal data policy in the footer"
131131
].join(" ")
132132
);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./ConsentBannerAndConsentManagement";
2+
export { addConsentManagementTranslations } from "./translation";

src/gdpr/ConsentBannerAndConsentManagement/translation.tsx renamed to src/consentManagement/ConsentBannerAndConsentManagement/translation.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React from "react";
22
import { createComponentI18nApi } from "../../i18n";
33
import { getLink, type RegisteredLinkProps } from "../../link";
44

5-
export const { useTranslation, addGdprTranslations } = createComponentI18nApi({
6-
"componentName": "Gdpr",
5+
export const { useTranslation, addConsentManagementTranslations } = createComponentI18nApi({
6+
"componentName": "ConsentManagement",
77
"frMessages": {
88
/** cspell: disable */
99
"all services pref": "Préférences pour tous les services.",
@@ -70,7 +70,7 @@ export const { useTranslation, addGdprTranslations } = createComponentI18nApi({
7070
}
7171
});
7272

73-
addGdprTranslations({
73+
addConsentManagementTranslations({
7474
"lang": "en",
7575
"messages": {
7676
"all services pref": "Preferences for all services.",

src/gdpr/createGdprApi.ts renamed to src/consentManagement/createConsentManagement.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
import { useReducer, useEffect, type ReactNode } from "react";
22
import type { ExtractFinalityFromFinalityDescription } from "./types";
33
import type { RegisteredLinkProps } from "../link";
4-
import { createUseGdpr } from "./useGdpr";
5-
import { createProcessConsentChanges, type GdprConsentCallback } from "./processConsentChanges";
4+
import { createUseConsent } from "./useConsent";
5+
import { createProcessConsentChanges, type ConsentCallback } from "./processConsentChanges";
66
import { createStatefulObservable } from "../tools/StatefulObservable";
77
import type { FinalityConsent } from "./types";
88
import { useRerenderOnChange } from "../tools/StatefulObservable/hooks";
99
import { createConsentBannerAndConsentManagement } from "./ConsentBannerAndConsentManagement";
1010
import { isBrowser } from "../tools/isBrowser";
1111

12-
export const localStorageKey = "@codegouvfr/react-dsfr gdpr finalityConsent";
12+
export const localStorageKey = "@codegouvfr/react-dsfr consent management finalityConsent";
1313

14-
export function createGdprApi<
14+
export function createConsentManagement<
1515
FinalityDescription extends Record<
1616
string,
1717
{ title: ReactNode; description?: ReactNode; subFinalities?: Record<string, ReactNode> }
1818
>
1919
>(params: {
2020
finalityDescription: ((params: { lang: string }) => FinalityDescription) | FinalityDescription;
21-
consentCallback?: GdprConsentCallback<
22-
ExtractFinalityFromFinalityDescription<FinalityDescription>
23-
>;
21+
consentCallback?: ConsentCallback<ExtractFinalityFromFinalityDescription<FinalityDescription>>;
2422
/** Optional: If you have a dedicated page that provides comprehensive information about your website's GDPR policies. */
2523
personalDataPolicyLinkProps?: RegisteredLinkProps;
2624
}) {
@@ -76,7 +74,7 @@ export function createGdprApi<
7674
return $finalityConsent.current;
7775
}
7876

79-
const { useGdpr } = createUseGdpr({
77+
const { useConsent } = createUseConsent({
8078
useFinalityConsent,
8179
processConsentChanges,
8280
useConsentCallback
@@ -95,7 +93,7 @@ export function createGdprApi<
9593
});
9694

9795
return {
98-
useGdpr,
96+
useConsent,
9997
ConsentBannerAndConsentManagement,
10098
FooterConsentManagementItem,
10199
FooterPersonalDataPolicyItem

src/consentManagement/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { createConsentManagement } from "./createConsentManagement";
2+
export { addConsentManagementTranslations } from "./ConsentBannerAndConsentManagement";

src/gdpr/processConsentChanges.ts renamed to src/consentManagement/processConsentChanges.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { assert } from "tsafe/assert";
55
import { is } from "tsafe/is";
66
import { useConstCallback } from "../tools/powerhooks/useConstCallback";
77

8-
export type GdprConsentCallback<Finality extends string> = (params: {
8+
export type ConsentCallback<Finality extends string> = (params: {
99
finalityConsent: FinalityConsent<Finality>;
1010
finalityConsent_prev: FinalityConsent<Finality> | undefined;
1111
}) => Promise<void> | void;
@@ -61,22 +61,22 @@ export function createProcessConsentChanges<Finality extends string>(params: {
6161
finalityConsent: FinalityConsent<Finality>;
6262
prAllConsentCallbacksRun: Promise<void>;
6363
}) => void;
64-
consentCallback: GdprConsentCallback<Finality> | undefined;
64+
consentCallback: ConsentCallback<Finality> | undefined;
6565
}) {
6666
const { finalities, getFinalityConsent, setFinalityConsent, consentCallback } = params;
6767

68-
const consentCallbacks: GdprConsentCallback<Finality>[] = [];
68+
const consentCallbacks: ConsentCallback<Finality>[] = [];
6969

7070
if (consentCallback !== undefined) {
7171
consentCallbacks.push(consentCallback);
7272
}
7373

7474
function useConsentCallback(params: {
75-
consentCallback: GdprConsentCallback<Finality> | undefined;
75+
consentCallback: ConsentCallback<Finality> | undefined;
7676
}) {
7777
const { consentCallback } = params;
7878

79-
const onConsentChange_const = useConstCallback<GdprConsentCallback<Finality>>(params =>
79+
const onConsentChange_const = useConstCallback<ConsentCallback<Finality>>(params =>
8080
consentCallback?.(params)
8181
);
8282

src/gdpr/types.ts renamed to src/consentManagement/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
import type { ReactNode } from "react";
33

4-
//See: test/types/gdpr.ts to understand theses types
4+
//See: test/types/consentManagement.ts to understand theses types
55

66
export type FinalityConsent<Finality extends string> = {
77
readonly [K in Finality as K extends `${infer _P}.${infer _C}` ? never : K]: boolean;

0 commit comments

Comments
 (0)