From faa119b0ad4ad64ede364b4701ed6de66558b532 Mon Sep 17 00:00:00 2001 From: Victor Turgeon <76506447+Medenos@users.noreply.github.com> Date: Tue, 8 Nov 2022 05:37:12 -0500 Subject: [PATCH] Address post is broken --- .../Controllers/AddressController.cs | 2 +- .../Data/InventoryContext.cs | 2 + .../src/components/CartButton.js | 2 +- .../src/pages/Formulaire.js | 188 ++++++++++++++---- .../src/stylesheets/site.css | 7 + 5 files changed, 159 insertions(+), 42 deletions(-) diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/AddressController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/AddressController.cs index d7bd047..c138575 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/AddressController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/AddressController.cs @@ -62,7 +62,7 @@ public class AddressController : Controller { id = _signInMan.Context.User.Identity.GetUserId(); if (all is not null && all == true && roles.Contains("Administrateur")) return Ok(_context.Addresses.ToList()); - else return Ok(user.Adresses.ToList()); + else return Ok(_context.Users.Where(x=>x.Id == id).Include("Adresses").First().Adresses); } catch (Exception e) { _logger.LogError(10, e.Message); return BadRequest(); diff --git a/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs b/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs index 0d596bc..6316b5c 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Data/InventoryContext.cs @@ -386,6 +386,7 @@ Pikachu is also the starter Pokémon of Pokémon Rumble Blast and Pokémon Rumbl LastName = "Admin", NormalizedUserName = "ADMIN", UserName = "Admin", + PhoneNumber = "111-111-1111", Id = AdminID, NormalizedEmail = "ADMIN@ADMIN.COM", Email = "admin@admin.com" @@ -396,6 +397,7 @@ Pikachu is also the starter Pokémon of Pokémon Rumble Blast and Pokémon Rumbl LastName = "A.", NormalizedUserName = "PASLA", UserName = "PasLa", + PhoneNumber="222-222-2222", Id = PaulID, NormalizedEmail = "PAUL@EXEMPLE.COM", Email = "paul@exemple.com" diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/CartButton.js b/GrossesMitaines/grosses-mitaines-ui/src/components/CartButton.js index 4283833..1bbf525 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/CartButton.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/CartButton.js @@ -36,7 +36,7 @@ const CartButton = () => { navigate("/login"); handleClose(); } - else if(result.isDismissed && result.dismiss == Swal.DismissReason.cancel){ + else if (result.isDismissed && result.dismiss == Swal.DismissReason.cancel) { navigate("/formulaire"); handleClose(); } diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js index 3b36f34..7bc1efb 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/Formulaire.js @@ -1,55 +1,163 @@ +import { useEffect } from "react"; import { useState } from "react"; import { Button } from "react-bootstrap"; import { useForm } from "react-hook-form"; +import Cookies from "universal-cookie"; +import { Form } from "react-bootstrap"; export default function App() { - const { register, handleSubmit, watch, formState: { errors } } = useForm(); + const { register, handleSubmit, setValue, watch, formState: { errors } } = useForm(); const onSubmit = data => console.log(data); + const cookies = new Cookies(); + + const [userAddresses, setUserAddresses] = useState([]); + + useEffect(() => { + + const userInfo = cookies.get("GMGM"); + if (userInfo != null && userInfo.LoggedIn == true) { + if (userInfo.firstName != null) + setValue("firstName", userInfo.firstName); + if (userInfo.lastName != null) + setValue("lastName", userInfo.lastName); + if (userInfo.phone != null) + setValue("phoneNumber", userInfo.phone); + if (userInfo.email != null) + setValue("emailAddress", userInfo.email); + + fetch("https://localhost:7292/api/Address", { + method: 'GET', + credentials: 'include', + mode: 'cors' + },).then(async (response) => { + if (response.ok) { + const json = await response.json(); + setUserAddresses(json); + // if (json.length >= 1) + // setFormAddress(json[0]); + } + }); + } + + + }, []); + + const setFormAddress = (addressId) => { + + const address = userAddresses.filter(a => a.id == addressId); + + console.log(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); + } return (