@@ -2,7 +2,11 @@ import React, { useEffect, useMemo, useState, useId, type ReactNode } from "reac
22import { fr } from "../../fr" ;
33import type { RegisteredLinkProps } from "../../link" ;
44import { createModal } from "../../Modal" ;
5- import type { ExtractFinalityFromFinalityDescription , FinalityConsent } from "../types" ;
5+ import type {
6+ ExtractFinalityFromFinalityDescription ,
7+ FinalityConsent ,
8+ SubFinalityContent
9+ } from "../types" ;
610import type { ProcessConsentChanges } from "../processConsentChanges" ;
711import { useLang } from "../../i18n" ;
812import { useIsModalOpen } from "../../Modal/useIsModalOpen" ;
@@ -20,7 +24,11 @@ import { useConst } from "../../tools/powerhooks/useConst";
2024export function createConsentManagement <
2125 FinalityDescription extends Record <
2226 string ,
23- { title : ReactNode ; description ?: ReactNode ; subFinalities ?: Record < string , ReactNode > }
27+ {
28+ title : ReactNode ;
29+ description ?: ReactNode ;
30+ subFinalities ?: Record < string , SubFinalityContent > ;
31+ }
2432 >
2533> ( params : {
2634 personalDataPolicyLinkProps : RegisteredLinkProps | undefined ;
@@ -238,7 +246,7 @@ export function createConsentManagement<
238246 function ConsentService ( props : {
239247 title : ReactNode ;
240248 description : ReactNode | undefined ;
241- subFinalities : Record < string , ReactNode > | undefined ;
249+ subFinalities : Record < string , { title : ReactNode ; description ?: ReactNode } > | undefined ;
242250 finalityConsent :
243251 | boolean
244252 | ( {
@@ -378,19 +386,22 @@ export function createConsentManagement<
378386 className = { fr . cx ( "fr-consent-services" , "fr-collapse" ) }
379387 id = { subFinalityDivId }
380388 >
381- { Object . entries ( subFinalities ) . map ( ( [ subFinality , title ] ) => (
382- < SubConsentService
383- key = { subFinality }
384- title = { title }
385- isConsentGiven = { finalityConsent [ subFinality ] }
386- onChange = { ( { isConsentGiven } ) =>
387- onChange ( {
388- subFinality,
389- isConsentGiven
390- } )
391- }
392- />
393- ) ) }
389+ { Object . entries ( subFinalities ) . map (
390+ ( [ subFinality , { title, description } ] ) => (
391+ < SubConsentService
392+ key = { subFinality }
393+ title = { title }
394+ description = { description }
395+ isConsentGiven = { finalityConsent [ subFinality ] }
396+ onChange = { ( { isConsentGiven } ) =>
397+ onChange ( {
398+ subFinality,
399+ isConsentGiven
400+ } )
401+ }
402+ />
403+ )
404+ ) }
394405 </ div >
395406 </ >
396407 ) ) }
@@ -401,10 +412,11 @@ export function createConsentManagement<
401412
402413 function SubConsentService ( props : {
403414 title : ReactNode ;
415+ description ?: ReactNode ;
404416 onChange : ( params : { isConsentGiven : boolean } ) => void ;
405417 isConsentGiven : boolean ;
406418 } ) {
407- const { title, onChange, isConsentGiven } = props ;
419+ const { title, description , onChange, isConsentGiven } = props ;
408420
409421 const { t } = useTranslation ( ) ;
410422
@@ -421,6 +433,9 @@ export function createConsentManagement<
421433 < div className = { fr . cx ( "fr-consent-service" ) } >
422434 < fieldset className = { fr . cx ( "fr-fieldset" , "fr-fieldset--inline" ) } >
423435 < legend className = { fr . cx ( "fr-consent-service__title" ) } > { title } </ legend >
436+ { description !== undefined && (
437+ < p className = { fr . cx ( "fr-consent-service__desc" ) } > { description } </ p >
438+ ) }
424439 < div className = { fr . cx ( "fr-consent-service__radios" , "fr-fieldset--inline" ) } >
425440 < div className = { fr . cx ( "fr-radio-group" ) } >
426441 < input
0 commit comments