Skip to content

Commit

Permalink
Appel du back-end depuis le formulaire
Browse files Browse the repository at this point in the history
  • Loading branch information
Alezco committed Aug 30, 2024
1 parent ffa80b2 commit 4a3f3e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/views/candidature-conseiller/CandidatureConseiller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import '@gouvfr/dsfr/dist/component/badge/badge.min.css';
import '@gouvfr/dsfr/dist/component/notice/notice.min.css';
import '@gouvfr/dsfr/dist/component/sidemenu/sidemenu.min.css';
import './CandidatureConseiller.css';
import { useApiAdmin } from './useApiAdmin';

export default function CandidatureConseiller() {
const [dateDisponibilite, setDateDisponibilite] = useState('');
const [isSituationValid, setIsSituationValid] = useState(true);

const { creerCandidatureConseiller } = useApiAdmin();
useScrollToSection();

const validerLaCandidature = event => {
Expand All @@ -33,6 +34,7 @@ export default function CandidatureConseiller() {
document.getElementById('situation-et-experience').scrollIntoView();
} else {
event.currentTarget.submit();
creerCandidatureConseiller();
}
};

Expand All @@ -45,7 +47,10 @@ export default function CandidatureConseiller() {
<div className="fr-col-12 fr-col-md-8 fr-py-12v">
<h1 className="cc-titre fr-mb-5w">Je veux devenir conseiller numérique</h1>
<p className="fr-text--sm fr-hint-text">Les champs avec <span className="cc-obligatoire">*</span> sont obligatoires.</p>
<form aria-label="Candidature conseiller" onSubmit={validerLaCandidature}>
<form
aria-label="Candidature conseiller"
onSubmit={validerLaCandidature}
>
<InformationsDeContact />
<SituationEtExperience isSituationValid={isSituationValid} />
<Disponibilite setDateDisponibilite={setDateDisponibilite} />
Expand Down
18 changes: 18 additions & 0 deletions src/views/candidature-conseiller/useApiAdmin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const useApiAdmin = () => {
const creerCandidatureConseiller = async () => {
const baseUrl = import.meta.env.VITE_APP_API_URL;
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
};

try {
const result = fetch(`${baseUrl}/candidature-conseiller`, requestOptions);
console.log('===================', result);

Check warning on line 11 in src/views/candidature-conseiller/useApiAdmin.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
} catch (error) {
console.error(error);

Check warning on line 13 in src/views/candidature-conseiller/useApiAdmin.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}
};

return { creerCandidatureConseiller };
};

0 comments on commit 4a3f3e5

Please sign in to comment.