From e537d86b9adf35ba743b19271ef24d2b456bd39d Mon Sep 17 00:00:00 2001 From: "anhara.akter" Date: Wed, 11 Dec 2024 16:31:39 +0100 Subject: [PATCH] feat(us-3078): retour pr --- components/jeune/TableauBeneficiaires.tsx | 47 ++++++++++++++--------- tests/pages/PortefeuillePage.test.tsx | 11 +++--- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/components/jeune/TableauBeneficiaires.tsx b/components/jeune/TableauBeneficiaires.tsx index 417fa16c7..59b466205 100644 --- a/components/jeune/TableauBeneficiaires.tsx +++ b/components/jeune/TableauBeneficiaires.tsx @@ -39,36 +39,39 @@ function TableauBeneficiaires( const DEBUT_PERIODE = DateTime.now().startOf('week') const FIN_PERIODE = DateTime.now().endOf('week') const [triDerniereActiviter, setTriDerniereActiviter] = useState(true) - const [filtreBeneficiaires, setFiltreBeneficiaires] = + const [beneficiairesTrier, setBeneficiairesTrier] = useState(beneficiairesFiltres) - const trierParDerniereActivite = () => { - const nouvelleTri = !triDerniereActiviter - const triBeneficiaires = [...beneficiairesFiltres].sort((a, b) => { + const trierParDerniereActivite = ( + beneficiaire: BeneficiaireAvecInfosComplementaires[], + ordre: boolean + ): BeneficiaireAvecInfosComplementaires[] => { + return [...beneficiairesTrier].sort((a, b) => { if (!a.isActivated && !b.isActivated) return 0 if (!a.isActivated) return 1 if (!b.isActivated) return -1 const dateA = DateTime.fromISO(a.lastActivity!) const dateB = DateTime.fromISO(b.lastActivity!) - return nouvelleTri + return ordre ? dateB.diff(dateA).milliseconds : dateA.diff(dateB).milliseconds }) - - setFiltreBeneficiaires(triBeneficiaires) - setPage(1) - setTriDerniereActiviter(nouvelleTri) } useEffect(() => { - setFiltreBeneficiaires(beneficiairesFiltres) setPage(1) }, [beneficiairesFiltres]) + useEffect(() => { + setBeneficiairesTrier( + trierParDerniereActivite(beneficiairesFiltres, triDerniereActiviter) + ) + }, [beneficiairesFiltres, triDerniereActiviter]) + return ( <> - {filtreBeneficiaires.length === 0 && ( + {beneficiairesTrier.length === 0 && ( )} - {filtreBeneficiaires.length > 0 && ( + {beneficiairesTrier.length > 0 && ( <>

Semaine du {toShortDate(DEBUT_PERIODE)} au{' '} @@ -85,14 +88,20 @@ function TableauBeneficiaires(