Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix + refactor formulaire #225

Merged
merged 14 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import '@gouvfr/dsfr/dist/component/modal/modal.module.min.js';
import '@gouvfr/dsfr/dist/component/header/header.module.min.js';
import './assets/sass/main.scss';
import '@gouvfr/dsfr/dist/core/core.min.css';
import '@gouvfr/dsfr/dist/component/alert/alert.min.css';
Ornella452 marked this conversation as resolved.
Show resolved Hide resolved

const RedirectCarto = () => {
const { permanence } = useParams();
Expand All @@ -39,7 +40,8 @@ function App() {
const PageCandidatureConseiller = lazy(() => import('./views/candidature-conseiller/PageCandidatureConseiller'));
const PageCandidatureStructure = lazy(() => import('./views/candidature-structure/PageCandidatureStructure'));
const PageCandidatureCoordinateur = lazy(() => import('./views/candidature-coordinateur/PageCandidatureCoordinateur'));
const PageCandidatureValidee = lazy(() => import('./views/candidature-validee/PageCandidatureValidee'));
const PageCandidatureValideeConseiller = lazy(() => import('./views/candidature-validee-conseiller/PageCandidatureValideeConseiller'));
const PageCandidatureValideeStructure = lazy(() => import('./views/candidature-validee-structure/PageCandidatureValideeStructure'));
const PageConfirmationEmailCandidatureConseiller =
lazy(() => import('./views/confirmation-email-candidature-conseiller/PageConfirmationEmailCandidatureConseiller'));
const PageConfirmationEmailCandidatureStructure =
Expand All @@ -54,7 +56,8 @@ function App() {
<Route path="/nouveau-formulaire-conseiller" element={<PageCandidatureConseiller />}/>
<Route path="/nouveau-formulaire-structure" element={<PageCandidatureStructure />}/>
<Route path="/nouveau-formulaire-coordinateur" element={<PageCandidatureCoordinateur />}/>
<Route path="/candidature-validee" element={<PageCandidatureValidee />}/>
<Route path="/candidature-validee-conseiller" element={<PageCandidatureValideeConseiller />}/>
<Route path="/candidature-validee-structure" element={<PageCandidatureValideeStructure />}/>
<Route path="/candidature-confirmer-conseiller/:token" element={<PageConfirmationEmailCandidatureConseiller />}/>
<Route path="/candidature-confirmer-structure/:token" element={<PageConfirmationEmailCandidatureStructure />}/>
<Route path="/kit-communication" element={<KitCommunication />}/>
Expand Down
20 changes: 15 additions & 5 deletions src/views/candidature-conseiller/AddressChooser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from 'react';
import Input from '../../components/commun/Input';
import { useGeoApi } from './useGeoApi';
import { debounce } from './debounce';
import PropTypes from 'prop-types';

export default function AddressChooser() {
export default function AddressChooser({ setCodeCommune }) {
const { searchByName, villes } = useGeoApi();

return (
Expand All @@ -12,17 +13,26 @@ export default function AddressChooser() {
id="lieuHabitation"
list="resultatsRecherche"
isRequired={false}
onChange={debounce(event => searchByName(event.target.value))}
onChange={debounce(async event => {
searchByName(event.target.value);
const codeCommune = await villes.find(({ codesPostaux, nom }) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essayer de déplacer ce bout de code dans buildConseillerData et simplifier ce composant

`${codesPostaux[0]} ${nom}` === event.target.value)?.code;
setCodeCommune(codeCommune);
})}
>
Votre lieu d’habitation <span className="fr-hint-text">Saississez le nom ou le code postal de votre commune.</span>
</Input>
<datalist id="resultatsRecherche">
{villes.map(({ code, nom }) => (
<option value={`${code} ${nom}`} key={code}>
{code} {nom}
{villes.map(({ codesPostaux, code, nom }) => (
<option value={`${codesPostaux[0]} ${nom}`} key={code}>
{codesPostaux[0]} {nom}
</option>
))}
</datalist>
</>
);
}

AddressChooser.propTypes = {
setCodeCommune: PropTypes.func
};
7 changes: 4 additions & 3 deletions src/views/candidature-conseiller/CandidatureConseiller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import './CandidatureConseiller.css';

export default function CandidatureConseiller() {
const [dateDisponibilite, setDateDisponibilite] = useState('');
const [codeCommune, setCodeCommune] = useState('');
const [isSituationValid, setIsSituationValid] = useState(true);
const [validationError, setValidationError] = useState('');
const { buildConseillerData, creerCandidatureConseiller } = useApiAdmin();
Expand Down Expand Up @@ -52,14 +53,14 @@ export default function CandidatureConseiller() {
setIsSituationValid(false);
document.getElementById('situation-et-experience').scrollIntoView();
} else {
const conseillerData = await buildConseillerData(formData);
const conseillerData = await buildConseillerData(formData, codeCommune);
const resultatCreation = await creerCandidatureConseiller(conseillerData);
if (resultatCreation.status >= 400) {
const error = await resultatCreation.json();
setValidationError(error.message);
window.scrollTo({ top: 0, behavior: 'smooth' });
} else {
navigate('/candidature-validee');
navigate('/candidature-validee-conseiller');
}
}
};
Expand All @@ -84,7 +85,7 @@ export default function CandidatureConseiller() {
aria-label="Candidature conseiller"
onSubmit={validerLaCandidature}
>
<InformationsDeContact />
<InformationsDeContact setCodeCommune={setCodeCommune}/>
<SituationEtExperience isSituationValid={isSituationValid} />
<Disponibilite setDateDisponibilite={setDateDisponibilite} />
<Motivation />
Expand Down
Loading