From 7c5de02d2d79b6c27c2d0d1c4f6b6bbc056adf48 Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Wed, 12 May 2021 15:54:27 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Filtre=20les=20SIREN=20non=20dif?= =?UTF-8?q?fusibles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/actions/companyStatusActions.ts | 15 ++++++++++----- mon-entreprise/source/api/sirene.ts | 4 +++- .../source/components/CompanyDetails.tsx | 9 +++++++++ .../source/components/conversation/Question.tsx | 2 +- mon-entreprise/source/locales/ui-en.yaml | 1 + 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/mon-entreprise/source/actions/companyStatusActions.ts b/mon-entreprise/source/actions/companyStatusActions.ts index 717cc0401..eaad3363e 100644 --- a/mon-entreprise/source/actions/companyStatusActions.ts +++ b/mon-entreprise/source/actions/companyStatusActions.ts @@ -85,17 +85,22 @@ const fetchCommuneDetails = async function (codeCommune: string) { export const useSetEntreprise = () => { const dispatch = useDispatch() return async (siren: string) => { - dispatch(setSiren(siren)) const companyDetails = await fetchCompanyDetails(siren) + if (companyDetails === null) { + return + } + dispatch(setSiren(siren)) dispatch( setCompanyDetails( companyDetails.categorie_juridique, companyDetails.date_creation ) ) - const communeDetails: ApiCommuneJson = await fetchCommuneDetails( - companyDetails.etablissement_siege.code_commune - ) - dispatch(addCommuneDetails(communeDetails)) + if (companyDetails.etablissement_siege) { + const communeDetails: ApiCommuneJson = await fetchCommuneDetails( + companyDetails.etablissement_siege.code_commune + ) + dispatch(addCommuneDetails(communeDetails)) + } } } diff --git a/mon-entreprise/source/api/sirene.ts b/mon-entreprise/source/api/sirene.ts index f87127acf..f1fff6c40 100644 --- a/mon-entreprise/source/api/sirene.ts +++ b/mon-entreprise/source/api/sirene.ts @@ -2,11 +2,13 @@ const isSIREN = (input: string) => /^[\s]*([\d][\s]*){9}$/.exec(input) const isSIRET = (input: string) => /^[\s]*([\d][\s]*){14}$/.exec(input) export async function fetchCompanyDetails(siren: string) { + // Le paramètre `statut_diffusion` filtre les SIREN non diffusibles, cf. + // https://github.com/betagouv/mon-entreprise/issues/1399#issuecomment-770736525 const response = await fetch( `https://entreprise.data.gouv.fr/api/sirene/v3/unites_legales/${siren.replace( /[\s]/g, '' - )}` + )}?statut_diffusion=O` ) if (!response.ok) { return null diff --git a/mon-entreprise/source/components/CompanyDetails.tsx b/mon-entreprise/source/components/CompanyDetails.tsx index df0a310f1..7d23b3a3d 100644 --- a/mon-entreprise/source/components/CompanyDetails.tsx +++ b/mon-entreprise/source/components/CompanyDetails.tsx @@ -30,6 +30,15 @@ export default function CompanyDetails({ siren, denomination }: Etablissement) { fetchCompanyDetails(siren).then(setCompany) }, [siren]) + if (company === null) { + return ( +

+ {siren} + est un SIREN non diffusable +

+ ) + } + return ( <>

diff --git a/mon-entreprise/source/components/conversation/Question.tsx b/mon-entreprise/source/components/conversation/Question.tsx index af72e267b..70bedbfb3 100644 --- a/mon-entreprise/source/components/conversation/Question.tsx +++ b/mon-entreprise/source/components/conversation/Question.tsx @@ -261,7 +261,7 @@ export function RadioLabelContent({ /> {icônes && <>{emoji(icônes)} } - {label} + {label} ) diff --git a/mon-entreprise/source/locales/ui-en.yaml b/mon-entreprise/source/locales/ui-en.yaml index f0fdaca90..3cb42db84 100644 --- a/mon-entreprise/source/locales/ui-en.yaml +++ b/mon-entreprise/source/locales/ui-en.yaml @@ -655,6 +655,7 @@ entreprise: titre: Write the company's articles titre: The to-do list for creating your business titre2: Recommended before starting your activity +est un SIREN non diffusable: is a non-distributable SIREN examples: Examples expected: the expected result was facteur: multiplier