From 4b5ddab66a79172a4c7514ccb31417f5f2b0e9d7 Mon Sep 17 00:00:00 2001 From: DavidBelisle <79233327+DavidBelisle@users.noreply.github.com> Date: Fri, 11 Nov 2022 14:11:40 -0500 Subject: [PATCH] =?UTF-8?q?Revert=20"Tout=20=C3=A7a=20pour=20une=20calis?= =?UTF-8?q?=20d'adresse"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c5cd52e34c079a444fa0506e834f25b095c74196. --- .../src/pages/Formulaire.js | 100 ++++++------------ 1 file changed, 30 insertions(+), 70 deletions(-) diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js index bb87e7d..f410c27 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js @@ -7,37 +7,23 @@ import { Form } from "react-bootstrap"; import { useNavigate } from "react-router-dom"; export default function App() { - const { register, handleSubmit, formState: { errors } } = useForm(); + const { register, handleSubmit, setValue, watch, formState: { errors } } = useForm(); const cookies = new Cookies(); const [userAddresses, setUserAddresses] = useState([]); const navigate = useNavigate(); - const [currentAdress, setCurrentAdress] = useState({ - firstName: "", - lastName: "", - phoneNumber: "", - emailAddress: "", - civicNumber: "", - appartment: "", - street: "", - city: "", - province: "", - country: "", - postalCode: "" - }) - useEffect(() => { const userInfo = cookies.get("GMGM"); if (userInfo != null && userInfo.LoggedIn == true) { if (userInfo.firstName != null) - setCurrentAdress((e) => { return { ...e, firstName: userInfo.firstName } }); + setValue("firstName", userInfo.firstName); if (userInfo.lastName != null) - setCurrentAdress((e) => { return { ...e, lastName: userInfo.lastName } }); + setValue("lastName", userInfo.lastName); if (userInfo.phone != null) - setCurrentAdress((e) => { return { ...e, phoneNumber: userInfo.phone } }); + setValue("phoneNumber", userInfo.phone); if (userInfo.email != null) - setCurrentAdress((e) => { return { ...e, emailAddress: userInfo.email } }); + setValue("emailAddress", userInfo.email); fetch("https://localhost:7292/api/Address", { method: 'GET', @@ -47,27 +33,22 @@ export default function App() { if (response.ok) { const json = await response.json(); setUserAddresses(json); - if (json.length >= 1) { + if (json.length >= 1) setFormAddress(json[0]); - } } }); } }, []); const setFormAddress = (address) => { - setCurrentAdress((e) => { - return { - ...e, - civicNumber: address.civicNumber, - appartment: address.appartment, - street: address.street, - city: address.city, - province: address.province, - country: address.country, - postalCode: address.postalCode - } - }); + + setValue("civicNumber", address.civicNumber); + setValue("appartment", address.appartment); + setValue("street", address.street); + setValue("city", address.city); + setValue("province", address.province); + setValue("country", address.country); + setValue("postalCode", address.postalCode); } const onSubmit = async (data) => { @@ -87,6 +68,7 @@ export default function App() { } } + return (