From 765bb5edc0ccdf545ba5d539da128bf6d775095e Mon Sep 17 00:00:00 2001 From: DavidBelisle <79233327+DavidBelisle@users.noreply.github.com> Date: Fri, 11 Nov 2022 14:15:01 -0500 Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"Tout=20=C3=A7a=20pour=20une?= =?UTF-8?q?=20calis=20d'adresse""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 4b5ddab66a79172a4c7514ccb31417f5f2b0e9d7. --- .../src/pages/Formulaire.js | 100 ++++++++++++------ 1 file changed, 70 insertions(+), 30 deletions(-) diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js index f410c27..bb87e7d 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js @@ -7,23 +7,37 @@ import { Form } from "react-bootstrap"; import { useNavigate } from "react-router-dom"; export default function App() { - const { register, handleSubmit, setValue, watch, formState: { errors } } = useForm(); + const { register, handleSubmit, 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) - setValue("firstName", userInfo.firstName); + setCurrentAdress((e) => { return { ...e, firstName: userInfo.firstName } }); if (userInfo.lastName != null) - setValue("lastName", userInfo.lastName); + setCurrentAdress((e) => { return { ...e, lastName: userInfo.lastName } }); if (userInfo.phone != null) - setValue("phoneNumber", userInfo.phone); + setCurrentAdress((e) => { return { ...e, phoneNumber: userInfo.phone } }); if (userInfo.email != null) - setValue("emailAddress", userInfo.email); + setCurrentAdress((e) => { return { ...e, emailAddress: userInfo.email } }); fetch("https://localhost:7292/api/Address", { method: 'GET', @@ -33,22 +47,27 @@ 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) => { - - 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); + 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 + } + }); } const onSubmit = async (data) => { @@ -68,7 +87,6 @@ export default function App() { } } - return (
@@ -76,7 +94,9 @@ export default function App() {
- + setCurrentAdress((prev) => { return { ...prev, emailAddress: e.target.value } })} />
{errors.emailAddress && errors.emailAddress.type === 'required' && Vous devez entrer une adresse courriel!} @@ -84,7 +104,9 @@ export default function App() {
- + setCurrentAdress((prev) => { return { ...prev, firstName: e.target.value } })} />
{errors.firstName && errors.firstName.type === 'required' && Vous devez entrer votre prénom!} @@ -92,7 +114,9 @@ export default function App() {
- + setCurrentAdress((prev) => { return { ...prev, lastName: e.target.value } })} />
{errors.lastName && errors.lastName.type === 'required' && Vous devez entrer votre nom!} @@ -100,7 +124,9 @@ export default function App() {
- + setCurrentAdress((prev) => { return { ...prev, phoneNumber: e.target.value } })} />
{errors.phoneNumber && errors.phoneNumber.type === 'required' && Vous devez entrer un numéro de téléphone!} @@ -109,22 +135,26 @@ export default function App() {
Adresse - {/* { setFormAddress(e.target.value); }}> - {userAddresses.map((a) => ( - + setFormAddress(userAddresses[e.target.value])}> + {userAddresses.map((a, i) => ( + //{a.civicNumber} {a.street} ))} - */} +
- + setCurrentAdress((prev) => { return { ...prev, civicNumber: e.target.value } })} />
{errors.civicNumber && errors.civicNumber.type === 'required' && Vous devez entrer une numéro civique!}
- + setCurrentAdress((prev) => { return { ...prev, street: e.target.value } })} />
{errors.street && errors.street.type === 'required' && Vous devez entrer votre rue!} @@ -134,11 +164,15 @@ export default function App() {
- + setCurrentAdress((prev) => { return { ...prev, appartment: e.target.value } })} />
- + setCurrentAdress((prev) => { return { ...prev, city: e.target.value } })} />
{errors.city && errors.city.type === 'required' && Vous devez entrer votre ville!} @@ -147,7 +181,9 @@ export default function App() {
- + setCurrentAdress((prev) => { return { ...prev, province: e.target.value } })} />
{errors.province && errors.province.type === 'required' && Vous devez entrer votre province!} @@ -155,7 +191,9 @@ export default function App() {
- + setCurrentAdress((prev) => { return { ...prev, country: e.target.value } })} />
{errors.country && errors.country.type === 'required' && Vous devez entrer votre pays!} @@ -164,7 +202,9 @@ export default function App() {
- + setCurrentAdress((prev) => { return { ...prev, postalCode: e.target.value } })} />
{errors.postalCode && errors.postalCode.type === 'required' && Vous devez entrer votre code postal!}