From 7efb6c23517354e49230f7baa1faceb8e1f63f83 Mon Sep 17 00:00:00 2001 From: Victor Turgeon Date: Tue, 25 Oct 2022 10:02:17 -0400 Subject: [PATCH] Ajout de promoPrice dans le gestionnaire de produit --- .../src/components/Ajouter.js | 40 +++++++++++-------- .../src/components/Modify.js | 31 +++++++++----- .../src/components/SimpleItem.js | 4 +- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/Ajouter.js b/GrossesMitaines/grosses-mitaines-ui/src/components/Ajouter.js index fcab8d8..c905e52 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/Ajouter.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/Ajouter.js @@ -10,26 +10,27 @@ const Ajouter = ({ onCreation }) => { const [description, setDescription] = useState(""); const [category, setCategory] = useState(""); const [price, setPrice] = useState(""); + const [promoPrice, setPromoPrice] = useState(""); const [quantity, setQuantity] = useState(""); const [imageName, setImageName] = useState("sqdc.jpg"); - const [status, setStatusValue] = useState(0) + const [status, setStatusValue] = useState(0); const handleSubmit = (e) => { e.preventDefault(); // Empêcher de reloader la page au submit. // Appeler le comportement onCreation - onCreation({ title, description, category, price, quantity, imageName, status }) + onCreation({ title, description, category, price, promoPrice, quantity, imageName, status }); // Reset les états du formulaire. - setTitle("") - setDescription("") - setCategory("") - setPrice("") - setQuantity("") - setImageName("sqdc.jpg") + setTitle(""); + setDescription(""); + setCategory(""); + setPrice(""); + setPromoPrice(""); + setQuantity(""); + setImageName("sqdc.jpg"); } - return (
@@ -37,42 +38,49 @@ const Ajouter = ({ onCreation }) => {
setTitle(e.target.value)} />
setDescription(e.target.value)} />
- + setCategory(e.target.value)} />
setPrice(e.target.value)} />
+
+ + setPromoPrice(e.target.value)} /> +
setQuantity(e.target.value)} />
setImageName(e.target.value)} />
diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/Modify.js b/GrossesMitaines/grosses-mitaines-ui/src/components/Modify.js index fd15027..ab83d44 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/Modify.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/Modify.js @@ -28,11 +28,11 @@ function renderStatus(statusCode) { const Modify = ({ morceau, onModify }) => { const [currentStatus, setStatus] = useState(renderStatus(morceau.status)); - const [title, setTitle] = useState(morceau.title); const [description, setDescription] = useState(morceau.description); const [category, setCategory] = useState(morceau.category); const [price, setPrice] = useState(morceau.price); + const [promoPrice, setPromoPrice] = useState(""); const [quantity, setQuantity] = useState(morceau.quantity); const [imageName, setImageName] = useState(morceau.imageName); const [status, setStatusValue] = useState(morceau.status) @@ -43,53 +43,60 @@ const Modify = ({ morceau, onModify }) => { e.preventDefault(); // Empêcher de reloader la page au submit. // Appeler le comportement onCreation - onModify({ id, title, description, category, price, quantity, imageName, status }) + onModify({ id, title, description, category, price, promoPrice, quantity, imageName, status }) } return (
-

Modifier un morceau

+

Ajouter un morceau

setTitle(e.target.value)} />
setDescription(e.target.value)} />
- + setCategory(e.target.value)} />
setPrice(e.target.value)} />
+
+ + setPromoPrice(e.target.value)} /> +
setQuantity(e.target.value)} />
setImageName(e.target.value)} />
@@ -141,7 +148,9 @@ const Modify = ({ morceau, onModify }) => {
- + + +
) diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/SimpleItem.js b/GrossesMitaines/grosses-mitaines-ui/src/components/SimpleItem.js index 5e849dc..8d67413 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/SimpleItem.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/SimpleItem.js @@ -39,7 +39,7 @@ const SimpleItem = ({ item, onDelete, onModify }) => {

- setFormVisibility(!isFormvisible)} /> onDelete(item.id)} /> @@ -47,7 +47,7 @@ const SimpleItem = ({ item, onDelete, onModify }) => { {isFormvisible && } {!isFormvisible &&
-

Catégorie: {item.category}, Prix: {item.price}, Promo: {item.promoPrice}, Quantité: {item.quantity}, Disponibilité: {renderStatus(item.status)}

+

Catégorie: {item.category}, Prix: {item.price.toFixed(2).toString().replace(".", ",")} $ CA, Promo: {item.promoPrice.toFixed(2).toString().replace(".", ",")} $ CA, Quantité: {item.quantity}, Disponibilité: {renderStatus(item.status)}

Description: {item.description}

}