From 734893ced8ac196dac69063a289b6e16fa9b697a Mon Sep 17 00:00:00 2001 From: Alezco Date: Mon, 25 Nov 2024 12:07:04 +0100 Subject: [PATCH] Ajout d'erreur sur les inputs --- src/components/commun/Input.jsx | 30 ++++++++++++++++--- src/components/commun/ZoneDeTexte.jsx | 10 +++++-- .../candidature-conseiller/AddressChooser.jsx | 12 ++++++-- .../CandidatureConseiller.jsx | 22 ++++++++++---- .../InformationsDeContact.jsx | 13 ++++++-- .../candidature-conseiller/Motivation.jsx | 9 ++++-- 6 files changed, 78 insertions(+), 18 deletions(-) diff --git a/src/components/commun/Input.jsx b/src/components/commun/Input.jsx index e972c23..8a11693 100644 --- a/src/components/commun/Input.jsx +++ b/src/components/commun/Input.jsx @@ -1,11 +1,27 @@ import React from 'react'; import PropTypes from 'prop-types'; -export default function Input({ children, id, isRequired = true, autoComplete = 'on', testId = '', type = 'text', - pattern, onChange, list, min, disabled, isLoading, ariaBusy, value, maxlength }) { +export default function Input({ + children, + id, + isRequired = true, + autoComplete = 'on', + testId = '', + type = 'text', + pattern, + onChange, + list, + min, + disabled, + isLoading, + ariaBusy, + value, + maxlength, + error, +}) { return (
-
+
)} + {error && ( +

+ {error} +

+ )}
); @@ -49,5 +70,6 @@ Input.propTypes = { ariaBusy: PropTypes.bool, value: PropTypes.string, testId: PropTypes.string, - maxlength: PropTypes.string + maxlength: PropTypes.string, + error: PropTypes.string }; diff --git a/src/components/commun/ZoneDeTexte.jsx b/src/components/commun/ZoneDeTexte.jsx index 5c6bfc9..9f5caf8 100644 --- a/src/components/commun/ZoneDeTexte.jsx +++ b/src/components/commun/ZoneDeTexte.jsx @@ -1,13 +1,18 @@ import React from 'react'; import PropTypes from 'prop-types'; -export default function ZoneDeTexte({ children, id, isRequired = true, maxlength = "2500" }) { +export default function ZoneDeTexte({ children, id, isRequired = true, maxlength = '2500', error }) { return ( -
+
+ {error && ( +

+ {error} +

+ )}
); } @@ -17,4 +22,5 @@ ZoneDeTexte.propTypes = { id: PropTypes.string, isRequired: PropTypes.bool, maxlength: PropTypes.string, + error: PropTypes.string, }; diff --git a/src/views/candidature-conseiller/AddressChooser.jsx b/src/views/candidature-conseiller/AddressChooser.jsx index 7f054f1..05702e0 100644 --- a/src/views/candidature-conseiller/AddressChooser.jsx +++ b/src/views/candidature-conseiller/AddressChooser.jsx @@ -2,17 +2,19 @@ import React, { useState } 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({ error }) { const { searchByName, villes } = useGeoApi(); const [codeCommune, setCodeCommune] = useState(''); return ( <> { searchByName(event.target.value); const codeCommune = await villes.find(({ codesPostaux, nom }) => @@ -23,7 +25,7 @@ export default function AddressChooser() { Votre lieu d’habitation *{' '} Saississez le nom ou le code postal de votre commune. - + {villes?.map(({ codesPostaux, nom }, key) => (