🐛 Filtre les SIREN non diffusibles

pull/1564/head
Maxime Quandalle 2021-05-12 15:54:27 +02:00
parent 3c82147f49
commit 7c5de02d2d
5 changed files with 24 additions and 7 deletions

View File

@ -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))
}
}
}

View File

@ -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

View File

@ -30,6 +30,15 @@ export default function CompanyDetails({ siren, denomination }: Etablissement) {
fetchCompanyDetails(siren).then(setCompany)
}, [siren])
if (company === null) {
return (
<p className="ui__ notice">
{siren}
<Trans>est un SIREN non diffusable</Trans>
</p>
)
}
return (
<>
<h3>

View File

@ -261,7 +261,7 @@ export function RadioLabelContent({
/>
<span>
{icônes && <>{emoji(icônes)}&nbsp;</>}
<Trans>{label}</Trans>
{label}
</span>
</label>
)

View File

@ -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