2019-09-26 17:12:35 +00:00
|
|
|
import { fetchCompanyDetails } from '../api/sirene'
|
2018-10-09 15:34:52 +00:00
|
|
|
|
2019-11-10 15:57:44 +00:00
|
|
|
const fetchCommuneDetails = function(codeCommune) {
|
2018-10-09 15:34:52 +00:00
|
|
|
return fetch(
|
2019-09-26 17:12:35 +00:00
|
|
|
`https://geo.api.gouv.fr/communes/${codeCommune}?fields=departement,region`
|
2018-10-09 15:34:52 +00:00
|
|
|
).then(response => {
|
|
|
|
return response.json()
|
|
|
|
})
|
|
|
|
}
|
2019-01-24 18:06:30 +00:00
|
|
|
|
2019-09-26 17:12:35 +00:00
|
|
|
export const setEntreprise = siren => async dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: 'EXISTING_COMPANY::SET_SIREN',
|
|
|
|
siren
|
|
|
|
})
|
|
|
|
const companyDetails = await fetchCompanyDetails(siren)
|
|
|
|
dispatch({
|
2019-12-03 13:52:34 +00:00
|
|
|
type: 'EXISTING_COMPANY::SET_DETAILS',
|
|
|
|
catégorieJuridique: companyDetails.categorie_juridique,
|
2020-01-07 13:41:37 +00:00
|
|
|
dateDeCréation: companyDetails.date_creation
|
2019-09-26 17:12:35 +00:00
|
|
|
})
|
|
|
|
const communeDetails = await fetchCommuneDetails(
|
|
|
|
companyDetails.etablissement_siege.code_commune
|
2018-10-09 15:34:52 +00:00
|
|
|
)
|
2019-04-03 14:02:36 +00:00
|
|
|
dispatch({
|
2019-09-26 17:12:35 +00:00
|
|
|
type: 'EXISTING_COMPANY::ADD_COMMUNE_DETAILS',
|
|
|
|
details: communeDetails
|
2019-04-03 14:02:36 +00:00
|
|
|
})
|
2018-10-09 15:34:52 +00:00
|
|
|
}
|
2019-10-01 16:42:08 +00:00
|
|
|
|
|
|
|
export const specifyIfAutoEntrepreneur = isAutoEntrepreneur => ({
|
|
|
|
type: 'EXISTING_COMPANY::SPECIFY_AUTO_ENTREPRENEUR',
|
|
|
|
isAutoEntrepreneur
|
|
|
|
})
|
|
|
|
|
2019-10-11 14:46:59 +00:00
|
|
|
export const specifyIfDirigeantMajoritaire = isDirigeantMajoritaire => ({
|
|
|
|
type: 'EXISTING_COMPANY::SPECIFY_DIRIGEANT_MAJORITAIRE',
|
|
|
|
isDirigeantMajoritaire
|
|
|
|
})
|
|
|
|
|
2019-10-01 16:42:08 +00:00
|
|
|
export const resetEntreprise = () => ({
|
|
|
|
type: 'EXISTING_COMPANY::RESET'
|
|
|
|
})
|