From 9a7d8625a82bdcf4b612733bb5f9e5717edbe19a Mon Sep 17 00:00:00 2001 From: ThomasDos Date: Fri, 6 Dec 2024 10:50:49 +0100 Subject: [PATCH] feat(candidate): update actualisation logic to display warning based on last activity date --- packages/reva-candidate/src/app/page.tsx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/reva-candidate/src/app/page.tsx b/packages/reva-candidate/src/app/page.tsx index e8e7d6ccf..91f976729 100644 --- a/packages/reva-candidate/src/app/page.tsx +++ b/packages/reva-candidate/src/app/page.tsx @@ -8,7 +8,7 @@ import { ProjectTimeline } from "@/components/legacy/organisms/ProjectTimeline/P import { useCandidacy } from "@/components/candidacy/candidacy.context"; import { useFeatureFlipping } from "@/components/feature-flipping/featureFlipping"; import Button from "@codegouvfr/react-dsfr/Button"; -import { addMonths, format, subWeeks } from "date-fns"; +import { addMonths, format, isAfter, subWeeks } from "date-fns"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/navigation"; @@ -25,11 +25,8 @@ const ActualisationSection = ({ }: { lastActivityDate: number; }) => { - // La candidature sera considérée comme caduque après cette date, 5 mois et 2 semaines après la dernière actualisation - const thresholdDate = format( - subWeeks(addMonths(lastActivityDate, 6), 2), - "dd/MM/yyyy", - ); + // La candidature sera considérée comme caduque après cette date, 6 mois après la dernière actualisation + const thresholdDate = format(addMonths(lastActivityDate, 6), "dd/MM/yyyy"); return (
@@ -71,10 +68,21 @@ export default function Home() { router.push("/candidacy-dropout"); } + let shouldDisplayActualisationWarning: boolean = false; + if (candidacy?.lastActivityDate) { + // On affiche le message d'actualisation à partir de 5 mois et 2 semaines après la dernière activité + const thresholdDate = subWeeks(addMonths(candidacy.lastActivityDate, 6), 2); + shouldDisplayActualisationWarning = isAfter(new Date(), thresholdDate); + } + + const lastActiveStatus = candidacy?.status; + const displayActualisationSection = candidacy?.lastActivityDate && candidacy?.feasibility?.decision === "ADMISSIBLE" && - candidacyActualisationFeatureIsActive; + candidacyActualisationFeatureIsActive && + shouldDisplayActualisationWarning && + lastActiveStatus !== "DOSSIER_DE_VALIDATION_ENVOYE"; return (