-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'creation-formulaire-candidature-structure' of https://g…
…ithub.com/anct-cnum/site-vitrine into creation-formulaire-candidature-structure
- Loading branch information
Showing
5 changed files
with
172 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import Input from '../../components/commun/Input'; | ||
import { useSiretApi } from './useSiretApi'; | ||
import { debounce } from '../candidature-conseiller/debounce'; | ||
|
||
export default function CompanyFinder() { | ||
const { search, entreprise } = useSiretApi(); | ||
|
||
return ( | ||
<> | ||
<Input | ||
id="siretEntreprise" | ||
isRequired={false} | ||
onChange={debounce(event => search(event.target.value))} | ||
placeholder="N° SIRET / RIDET" | ||
/> | ||
{entreprise} | ||
</> | ||
); | ||
} |
53 changes: 53 additions & 0 deletions
53
src/views/candidature-structure/InformationsDeStructure.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import Input from '../../components/commun/Input'; | ||
import CompanyFinder from './CompanyFinder'; | ||
import BoutonRadio from '../../components/commun/BoutonRadio'; | ||
|
||
export default function InformationsDeContact() { | ||
return ( | ||
<fieldset | ||
className="fr-border cc-section fr-p-3w fr-mb-3w" | ||
id="informations-de-structure" | ||
> | ||
<legend className="fr-h5">Vos informations de structure</legend> | ||
<hr /> | ||
<CompanyFinder /> | ||
<Input | ||
id="denomination" | ||
> | ||
Dénomination <span className="cc-obligatoire">*</span> | ||
</Input> | ||
<Input | ||
id="adresse" | ||
> | ||
Adresse <span className="cc-obligatoire">*</span> | ||
</Input> | ||
<p className="fr-mb-3w cc-bold"> | ||
Votre structure est <span className="cc-obligatoire">*</span> | ||
</p> | ||
<div className="fr-grid-row"> | ||
<BoutonRadio id="commune" nomGroupe="typeStructure"> | ||
Une commune | ||
</BoutonRadio> | ||
<BoutonRadio id="intercommunalite" nomGroupe="typeStructure"> | ||
Un département | ||
</BoutonRadio> | ||
<BoutonRadio id="region" nomGroupe="typeStructure"> | ||
Une région | ||
</BoutonRadio> | ||
<BoutonRadio id="etablissement" nomGroupe="typeStructure"> | ||
Un établissement public de coopération intercommunale | ||
</BoutonRadio> | ||
<BoutonRadio id="collectivite" nomGroupe="typeStructure"> | ||
Une collectivité à statut particulier | ||
</BoutonRadio> | ||
<BoutonRadio id="gip" nomGroupe="typeStructure"> | ||
Un GIP | ||
</BoutonRadio> | ||
<BoutonRadio id="structurePrivee" nomGroupe="typeStructure"> | ||
Une structure privée (association, entreprise de l’ESS, fondations) | ||
</BoutonRadio> | ||
</div> | ||
</fieldset> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useState } from 'react'; | ||
|
||
const getUrlEntrepriseApiV3 = (sirenOuSiret, type) => { | ||
let params = '?context=cnum&object=checkSiret&recipient=13002603200016'; | ||
let url = 'https://entreprise.api.gouv.fr/v3/'; | ||
let service = ''; | ||
switch (type) { | ||
case 'siret': | ||
service = 'insee/sirene/etablissements/' + sirenOuSiret; | ||
break; | ||
case 'siren': | ||
service = 'insee/sirene/unites_legales/' + sirenOuSiret + '/siege_social/'; | ||
break; | ||
default: | ||
break; | ||
} | ||
return url + service + params; | ||
}; | ||
|
||
export const useSiretApi = () => { | ||
const [entreprise, setEntreprise] = useState(null); | ||
const [error, setError] = useState(null); | ||
|
||
const search = async (sirenOuSiret, type) => { | ||
try { | ||
const url = getUrlEntrepriseApiV3(sirenOuSiret, type); | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error(`Error fetching data: ${response.statusText}`); | ||
} | ||
const result = await response.json(); | ||
setEntreprise(result); | ||
setError(null); | ||
} catch (err) { | ||
setError(err.message); | ||
setEntreprise(null); | ||
} | ||
}; | ||
|
||
return { search, entreprise, error }; | ||
}; | ||