diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/InvoiceController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/InvoiceController.cs index 567efe0..39c3612 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/InvoiceController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/InvoiceController.cs @@ -116,7 +116,8 @@ public class InvoiceController : Controller { LastName = sinv.LastName, EmailAddress = sinv.EmailAddress, PhoneNumber = sinv.PhoneNumber, - PurchaseDate = DateTime.Now + PurchaseDate = DateTime.Now, + Products = new List() }; AddressModel ad; user.Wait(); diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js index 335bd5c..7ad297e 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js @@ -7,17 +7,14 @@ import { useNavigate } from "react-router-dom"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { CartContext } from "../components/Cart"; -import { useRef } from "react"; const ReviewInvoice = () => { - + const navigate = useNavigate(); const mySwal = withReactContent(Swal); - const cart = useRef(useContext(CartContext)); - - //const [products, setProducts] = useState([]); + const cart = useContext(CartContext); const [thisInvoice, setThisInvoice] = useState({ firstName: "", @@ -39,14 +36,19 @@ const ReviewInvoice = () => { const thisInvoice = cookies.get('invoice'); if (thisInvoice != null) { var dic = {}; - - if (cart.current.items.length > 0) { - cart.current.items.forEach((item) => - dic[item.id] = item.qty + if (cart.items.length > 0) { + cart.items.forEach((item) => + dic[item.id] = item.quantity ) } - //dic[5] = 1; + async function test() { + + const json = JSON.stringify(dic); + console.log(await json); + } + test(); + setThisInvoice((e) => { return { @@ -69,7 +71,7 @@ const ReviewInvoice = () => { else { console.log("No invoice to review!"); } - }, []); + }, [cart]); // const handleAddOne = (id) => { @@ -114,10 +116,19 @@ const ReviewInvoice = () => { const handleConfirmer = async () => { - // let formData = new FormData(); - // Object.keys(thisInvoice).map((k) => { - // formData.set(k, thisInvoice[k]); - // }); + // var dic = {}; + // if (cart.items.length > 0) { + // cart.items.forEach((item) => + // dic[item.id] = item.quantity + // ) + // } + // const json = JSON.stringify(dic); + // console.log(await json); + + // const json1 = JSON.stringify(cart.items); + // console.log(await json1); + + //setThisInvoice({ ...thisInvoice, prodQuant: dic }); const json = JSON.stringify(thisInvoice); console.log(json); @@ -163,58 +174,46 @@ const ReviewInvoice = () => {
- {/* setFirstName(e.target.value)} /> */}
- {/* setLastName(e.target.value)} /> */}
- {/* setPhoneNumber(e.target.value)} /> */}
- {/* setEmailAddress(e.target.value)} /> */}
- {/* setCivicNumber(e.target.value)} /> */}
{thisInvoice.appartment != null ?
- {/* setAppartment(e.target.value)} /> */}
: null }
- {/* setStreet(e.target.value)} /> */}
- {/* setCity(e.target.value)} /> */}
- {/* setProvince(e.target.value)} /> */}
- {/* setCountry(e.target.value)} /> */}
- {/* setPostalCode(e.target.value)} /> */}
@@ -228,10 +227,6 @@ const ReviewInvoice = () => {