Skip to content

Commit

Permalink
DonutCard employee vs menu
Browse files Browse the repository at this point in the history
  • Loading branch information
bluo999 committed Mar 1, 2022
1 parent 406dcd5 commit 1e668ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
17 changes: 11 additions & 6 deletions frontend/src/components/DonutCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,14 +33,18 @@ export const DonutCard: React.FC<Donut> = (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<OrderInterface>({
"donut": donut,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/Employee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const Employee: React.FC = () => {
description={donut.description}
price={donut.price}
quantity={orders[selectedOrder].amounts[index]}
menuView={false}
/>;
}
})}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const Menu: React.FC = () => {
<div className="options-Div">
{menu.map((donut: DonutInterface, index: number) => (
<DonutCard key={index} id={donut.id} name={donut.name} image={donut.picture} description={donut.description}
price={donut.price} quantity={0}/>
price={donut.price} quantity={0} menuView={true}/>
))}
</div>
</div>
Expand All @@ -51,7 +51,7 @@ export const Menu: React.FC = () => {
<div className="options-Div">
{menu.map((donut: DonutInterface, index: number) => (
<DonutCard key={index} id={donut.id} name={donut.name} image={donut.picture} description={donut.description}
price={donut.price} quantity={0}/>
price={donut.price} quantity={0} menuView={true}/>
))}
</div>
</div>
Expand All @@ -61,7 +61,7 @@ export const Menu: React.FC = () => {
<div className="options-Div">
{menu.map((donut: DonutInterface, index: number) => (
<DonutCard key={index} id={donut.id} name={donut.name} image={donut.picture} description={donut.description}
price={donut.price} quantity={0}/>
price={donut.price} quantity={0} menuView={true}/>
))}
</div>
</div>
Expand Down

0 comments on commit 1e668ed

Please sign in to comment.