From 1e668ed028ca06026827b02c195c0bdd2fd8cfc2 Mon Sep 17 00:00:00 2001 From: Brian Luo Date: Tue, 1 Mar 2022 18:27:13 -0500 Subject: [PATCH] DonutCard employee vs menu --- frontend/src/components/DonutCard.tsx | 17 +++++++++++------ frontend/src/pages/Employee.tsx | 1 + frontend/src/pages/Menu.tsx | 6 +++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/DonutCard.tsx b/frontend/src/components/DonutCard.tsx index b4bb00b..535a84c 100644 --- a/frontend/src/components/DonutCard.tsx +++ b/frontend/src/components/DonutCard.tsx @@ -11,6 +11,7 @@ class Donut { description: string price: number quantity: number + menuView: boolean constructor(id: string, name: string, image: string, description: string, price: number, quantity: number) { this.id = id; @@ -32,14 +33,18 @@ export const DonutCard: React.FC = (donutIn: Donut) => { headers.append("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT"); headers.append("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"); - - useEffect(() => { - if (quantity != 0) - sentOrder(donut.id, quantity).then() - }, [quantity]) + // Temporary fix for menu vs employee donut cards + if (donutIn.menuView) { + useEffect(() => { + if (quantity != 0) + sentOrder(donut.id, quantity).then() + }, [quantity]) + } else { + if (quantity != donutIn.quantity) + setQuantity(donutIn.quantity); + } async function sentOrder(donut: string, amount: number) { - console.log("sendOrder") try { const res = await postRequest({ "donut": donut, diff --git a/frontend/src/pages/Employee.tsx b/frontend/src/pages/Employee.tsx index c9c69cc..e1ecb87 100644 --- a/frontend/src/pages/Employee.tsx +++ b/frontend/src/pages/Employee.tsx @@ -120,6 +120,7 @@ export const Employee: React.FC = () => { description={donut.description} price={donut.price} quantity={orders[selectedOrder].amounts[index]} + menuView={false} />; } })} diff --git a/frontend/src/pages/Menu.tsx b/frontend/src/pages/Menu.tsx index b4528a1..bd55828 100644 --- a/frontend/src/pages/Menu.tsx +++ b/frontend/src/pages/Menu.tsx @@ -41,7 +41,7 @@ export const Menu: React.FC = () => {
{menu.map((donut: DonutInterface, index: number) => ( + price={donut.price} quantity={0} menuView={true}/> ))}
@@ -51,7 +51,7 @@ export const Menu: React.FC = () => {
{menu.map((donut: DonutInterface, index: number) => ( + price={donut.price} quantity={0} menuView={true}/> ))}
@@ -61,7 +61,7 @@ export const Menu: React.FC = () => {
{menu.map((donut: DonutInterface, index: number) => ( + price={donut.price} quantity={0} menuView={true}/> ))}