From c136963431f9d37eaec22eddcd6424d84ca468ad Mon Sep 17 00:00:00 2001 From: Liliana Date: Tue, 23 Apr 2024 14:56:45 +0200 Subject: [PATCH] added fields for requesting first and last name information from add users --- webapp/src/components/AddUser.js | 41 ++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/webapp/src/components/AddUser.js b/webapp/src/components/AddUser.js index d124e8b4..e6bc0410 100644 --- a/webapp/src/components/AddUser.js +++ b/webapp/src/components/AddUser.js @@ -7,17 +7,24 @@ import Button from './Button'; const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; const AddUser = () => { + + const [name, setName] = useState(''); + const [surname, setSurname] = useState(''); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [openSnackbar, setOpenSnackbar] = useState(false); const addUser = async () => { - try { - await axios.post(`${apiEndpoint}/adduser`, { username, password }); - setOpenSnackbar(true); - } catch (error) { - setError(error.response.data.error); + if (name.trim() === '' || lastName.trim() === '') { + setError('Por favor, introduce tanto el nombre como los apellidos.'); + } else { + try { + await axios.post(`${apiEndpoint}/adduser`, { username, password }); + setOpenSnackbar(true); + } catch (error) { + setError(error.response.data.error); + } } }; @@ -27,9 +34,29 @@ const AddUser = () => { return ( + Add User + + setName(e.target.value)} + /> + + setSurname(e.target.value)} + /> + { value={username} onChange={(e) => setUsername(e.target.value)} /> + { value={password} onChange={(e) => setPassword(e.target.value)} /> +