From 09fd2a71a2ac5e7eadd04276433a2b83cbd423f9 Mon Sep 17 00:00:00 2001 From: Johan Girod Date: Tue, 1 Oct 2019 18:42:08 +0200 Subject: [PATCH] Ajoute une question pour les auto-entrepreneurs --- source/actions/existingCompanyActions.js | 9 +++ source/components/CompanyDetails.js | 2 +- source/components/FindCompany.js | 3 +- source/components/Overlay.js | 16 +++--- source/reducers/inFranceAppReducer.js | 7 ++- source/reducers/rootReducer.js | 10 ++++ .../pages/SocialSecurity/Home.js | 57 ++++++++++++++++--- 7 files changed, 87 insertions(+), 17 deletions(-) diff --git a/source/actions/existingCompanyActions.js b/source/actions/existingCompanyActions.js index e567dbae5..57cd6e6e2 100644 --- a/source/actions/existingCompanyActions.js +++ b/source/actions/existingCompanyActions.js @@ -26,3 +26,12 @@ export const setEntreprise = siren => async dispatch => { details: communeDetails }) } + +export const specifyIfAutoEntrepreneur = isAutoEntrepreneur => ({ + type: 'EXISTING_COMPANY::SPECIFY_AUTO_ENTREPRENEUR', + isAutoEntrepreneur +}) + +export const resetEntreprise = () => ({ + type: 'EXISTING_COMPANY::RESET' +}) diff --git a/source/components/CompanyDetails.js b/source/components/CompanyDetails.js index 808e714da..2c1e75d69 100644 --- a/source/components/CompanyDetails.js +++ b/source/components/CompanyDetails.js @@ -20,7 +20,7 @@ export default function CompanyDetails({ siren, denomination }) { const [company, setCompany] = useState() useEffect(() => { fetchCompanyDetails(siren).then(setCompany) - }, [siren, company]) + }, [siren]) return ( <> diff --git a/source/components/FindCompany.js b/source/components/FindCompany.js index 79deab261..d4bf3dd1f 100644 --- a/source/components/FindCompany.js +++ b/source/components/FindCompany.js @@ -77,7 +77,8 @@ export default function Search() { width: 100%; padding: 0.4rem; border-radius: 0.3rem; - :hover { + :hover, + :focus { background-color: var(--lighterColour); } `}> diff --git a/source/components/Overlay.js b/source/components/Overlay.js index 3a98a2d9c..632c405d5 100644 --- a/source/components/Overlay.js +++ b/source/components/Overlay.js @@ -10,16 +10,18 @@ export default function Overlay({ onClose, children, ...otherProps }) {
{children} - - × - + {onClose && ( + + × + + )}
diff --git a/source/reducers/inFranceAppReducer.js b/source/reducers/inFranceAppReducer.js index 75a8aee5d..c3b989e1a 100644 --- a/source/reducers/inFranceAppReducer.js +++ b/source/reducers/inFranceAppReducer.js @@ -98,7 +98,8 @@ const infereLegalStatusFromCategorieJuridique = catégorieJuridique => { En revanche, impossible de différencier EI et auto-entreprise https://www.sirene.fr/sirene/public/question.action?idQuestion=2933 */ - if (!catégorieJuridique) { + + if (catégorieJuridique === '1000') { return 'EI' } if (catégorieJuridique === '5498') { @@ -129,6 +130,9 @@ function existingCompany( if (!action.type.startsWith('EXISTING_COMPANY::')) { return state } + if (action.type.endsWith('RESET')) { + return null + } if (action.type.endsWith('SET_SIREN')) { return { siren: action.siren } } @@ -144,6 +148,7 @@ function existingCompany( if (state && action.type.endsWith('SPECIFY_AUTO_ENTREPRENEUR')) { return { ...state, isAutoEntrepreneur: action.isAutoEntrepreneur } } + return state } diff --git a/source/reducers/rootReducer.js b/source/reducers/rootReducer.js index 46cecd767..3d0bf8b94 100644 --- a/source/reducers/rootReducer.js +++ b/source/reducers/rootReducer.js @@ -4,6 +4,7 @@ import { findRuleByDottedName } from 'Engine/rules' import { compose, defaultTo, + dissoc, identity, lensPath, omit, @@ -186,6 +187,12 @@ const addAnswerToSituation = (dottedName, value, state) => { ) )(state) } +const removeAnswerFromSituation = (dottedName, state) => { + return compose( + over(lensPath(['simulation', 'situation']), dissoc(dottedName)), + over(lensPath(['conversationSteps', 'foldedSteps']), without([dottedName])) + )(state) +} const existingCompanyReducer = (state, action) => { if (!action.type.startsWith('EXISTING_COMPANY::')) { @@ -198,6 +205,9 @@ const existingCompanyReducer = (state, action) => { state ) } + if (action.type.endsWith('RESET')) { + removeAnswerFromSituation('établissement . localisation', state) + } return state } diff --git a/source/sites/mon-entreprise.fr/pages/SocialSecurity/Home.js b/source/sites/mon-entreprise.fr/pages/SocialSecurity/Home.js index 9f0330473..d2c769691 100644 --- a/source/sites/mon-entreprise.fr/pages/SocialSecurity/Home.js +++ b/source/sites/mon-entreprise.fr/pages/SocialSecurity/Home.js @@ -1,17 +1,20 @@ /* @flow */ +import { + resetEntreprise, + specifyIfAutoEntrepreneur +} from 'Actions/existingCompanyActions' import { React, T } from 'Components' import CompanyDetails from 'Components/CompanyDetails' import FindCompany from 'Components/FindCompany' import Overlay from 'Components/Overlay' import { ScrollToTop } from 'Components/utils/Scroll' import withSitePaths from 'Components/utils/withSitePaths' -import { compose } from 'ramda' import { useEffect, useRef, useState } from 'react' import emoji from 'react-easy-emoji' import { Helmet } from 'react-helmet' import { useTranslation } from 'react-i18next' -import { useSelector } from 'react-redux' +import { useDispatch, useSelector } from 'react-redux' import { Link } from 'react-router-dom' import * as Animate from 'Ui/animate' import Video from './Video' @@ -46,6 +49,7 @@ type Props = { régime: 'indépendant' | 'assimilé-salarié' | 'auto-entrepreneur' | null, sitePaths: Object } + function SocialSecurity({ sitePaths }: Props) { const { t } = useTranslation() const company = useSelector(state => state.inFranceApp.existingCompany) @@ -138,17 +142,52 @@ function SocialSecurity({ sitePaths }: Props) { const CompanySection = ({ company }) => { const [searchModal, showSearchModal] = useState(false) - const companyRef = useRef(company) + const [autoEntrepreneurModal, showAutoEntrepreneurModal] = useState(false) + + const companyRef = useRef(null) useEffect(() => { if (companyRef.current !== company) { companyRef.current = company - if (searchModal) { + if (searchModal && company) { showSearchModal(false) } + if ( + company?.statutJuridique === 'EI' && + company?.isAutoEntrepreneur == null + ) { + showAutoEntrepreneurModal(true) + } } }, [company, searchModal]) + + const dispatch = useDispatch(company) + const handleAnswerAutoEntrepreneur = isAutoEntrepreneur => { + dispatch(specifyIfAutoEntrepreneur(isAutoEntrepreneur)) + showAutoEntrepreneurModal(false) + } + return ( <> + {autoEntrepreneurModal && ( + <> + + +

Êtes-vous auto-entrepreneur ?

+
+ + +
+
+ + )} {searchModal && ( <> @@ -164,8 +203,11 @@ const CompanySection = ({ company }) => {
) : ( @@ -192,4 +234,5 @@ const CompanySection = ({ company }) => { ) } -export default compose(withSitePaths)(SocialSecurity) + +export default withSitePaths(SocialSecurity)