From a98a41061cae23c5cf61d8e2bfa7fa5efd050f82 Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 23 Jan 2025 18:29:26 +0100 Subject: [PATCH] refactor: localstorage should not send events --- .../ContributionGenericAgreementSearch.tsx | 17 ++++++-- .../contributions/ContributionLayout.tsx | 5 ++- .../DisplayContentContribution.test.tsx.snap | 30 +++++++------- .../__tests__/contributions.test.tsx | 19 ++++++--- .../AgreementSearch/AgreementSearchForm.tsx | 9 ++--- .../AgreementSearch/AgreementSearchInput.tsx | 4 +- .../__tests__/AgreementSearchForm.test.tsx | 39 ++++++++++++------- .../convention-collective/__tests__/ui.ts | 8 ++++ .../EnterpriseAgreementSearch/__tests__/ui.ts | 8 ---- 9 files changed, 84 insertions(+), 55 deletions(-) diff --git a/packages/code-du-travail-frontend/src/modules/contributions/ContributionGenericAgreementSearch.tsx b/packages/code-du-travail-frontend/src/modules/contributions/ContributionGenericAgreementSearch.tsx index 9315230091..98cfa66e3d 100644 --- a/packages/code-du-travail-frontend/src/modules/contributions/ContributionGenericAgreementSearch.tsx +++ b/packages/code-du-travail-frontend/src/modules/contributions/ContributionGenericAgreementSearch.tsx @@ -19,17 +19,27 @@ type Props = { onAgreementSelect: (agreement?: EnterpriseAgreement, mode?: string) => void; onDisplayClick: (ev: React.MouseEvent) => void; contribution: Contribution; + defaultAgreement?: EnterpriseAgreement; }; export function ContributionGenericAgreementSearch({ contribution, onAgreementSelect, onDisplayClick, + defaultAgreement, }: Props) { const { slug, isNoCDT } = contribution; const [selectedAgreement, setSelectedAgreement] = useState(); + const [isValid, setIsValid] = useState( + defaultAgreement ? isAgreementValid(contribution, defaultAgreement) : false + ); + useEffect(() => { + setIsValid( + isAgreementValid(contribution, selectedAgreement ?? defaultAgreement) + ); + }, [selectedAgreement, defaultAgreement]); const selectedAgreementAlert = (agreement: EnterpriseAgreement) => { const isSupported = isCCSupported(contribution, agreement); const isUnextended = isCCUnextended(contribution, agreement); @@ -98,13 +108,14 @@ export function ContributionGenericAgreementSearch({ ? "La convention collective est nécessaire pour obtenir une réponse car le code du travail ne prévoit rien sur ce sujet." : "La réponse dépend de la convention collective à laquelle votre entreprise est rattachée. Veuillez renseigner votre situation afin d’obtenir une réponse adaptée." } + defaultAgreement={defaultAgreement} /> - {(!contribution.isNoCDT || selectedAgreement) && ( + {((contribution.isNoCDT && isValid) || !contribution.isNoCDT) && (