Skip to content

Commit

Permalink
Release (#289)
Browse files Browse the repository at this point in the history
* Development (#235)

* update github workflow yaml file

* rename the frontend folder

* Development (#237)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* Development (#239)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* Development (#241)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Development (#242)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* Development (#244)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* Development (#246)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* Development (#248)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* Development (#250)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* Development (#252)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* Development (#254)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* Development (#256)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* Development (#257)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* Development (#259)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* Development (#261)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* Development (#262)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* Development (#264)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* rename add and remove from cart to add and remove menu from cart

* remove the menuid from foodmenu component

* create the shopping component

* Development (#266)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* rename add and remove from cart to add and remove menu from cart

* remove the menuid from foodmenu component

* create the shopping component

* implement display menu quantity, also display only menu items ata a time

* prevent increase in total price if the menu quantity is 1

* fix issues with totalprice calculations

* fix issues with menu items reduction

* merge conflicts

* Development (#267)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* rename add and remove from cart to add and remove menu from cart

* remove the menuid from foodmenu component

* create the shopping component

* implement display menu quantity, also display only menu items ata a time

* prevent increase in total price if the menu quantity is 1

* fix issues with totalprice calculations

* fix issues with menu items reduction

* fix the bug in shopping cart provider

* Development (#269)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* rename add and remove from cart to add and remove menu from cart

* remove the menuid from foodmenu component

* create the shopping component

* implement display menu quantity, also display only menu items ata a time

* prevent increase in total price if the menu quantity is 1

* fix issues with totalprice calculations

* fix issues with menu items reduction

* fix the bug in shopping cart provider

* remove menu price from global state

* fix bug in remove menu from cart

* Development (#271)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* rename add and remove from cart to add and remove menu from cart

* remove the menuid from foodmenu component

* create the shopping component

* implement display menu quantity, also display only menu items ata a time

* prevent increase in total price if the menu quantity is 1

* fix issues with totalprice calculations

* fix issues with menu items reduction

* fix the bug in shopping cart provider

* remove menu price from global state

* fix bug in remove menu from cart

* fix error in menuItems calculations

* Development (#273)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* rename add and remove from cart to add and remove menu from cart

* remove the menuid from foodmenu component

* create the shopping component

* implement display menu quantity, also display only menu items ata a time

* prevent increase in total price if the menu quantity is 1

* fix issues with totalprice calculations

* fix issues with menu items reduction

* fix the bug in shopping cart provider

* remove menu price from global state

* fix bug in remove menu from cart

* fix error in menuItems calculations

* update some names in the shoppingcart context

* Development (#274)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* rename add and remove from cart to add and remove menu from cart

* remove the menuid from foodmenu component

* create the shopping component

* implement display menu quantity, also display only menu items ata a time

* prevent increase in total price if the menu quantity is 1

* fix issues with totalprice calculations

* fix issues with menu items reduction

* fix the bug in shopping cart provider

* remove menu price from global state

* fix bug in remove menu from cart

* fix error in menuItems calculations

* update some names in the shoppingcart context

* add the none button for food items

* update remove item from cart method to calculate total price correctly

* remove unused file

* Development (#276)

* Development (#277)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* rename add and remove from cart to add and remove menu from cart

* remove the menuid from foodmenu component

* create the shopping component

* implement display menu quantity, also display only menu items ata a time

* prevent increase in total price if the menu quantity is 1

* fix issues with totalprice calculations

* fix issues with menu items reduction

* fix the bug in shopping cart provider

* remove menu price from global state

* fix bug in remove menu from cart

* fix error in menuItems calculations

* update some names in the shoppingcart context

* add the none button for food items

* update remove item from cart method to calculate total price correctly

* remove unused file

* create the radio button

* calculate order quantity

* Development (#279)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* rename add and remove from cart to add and remove menu from cart

* remove the menuid from foodmenu component

* create the shopping component

* implement display menu quantity, also display only menu items ata a time

* prevent increase in total price if the menu quantity is 1

* fix issues with totalprice calculations

* fix issues with menu items reduction

* fix the bug in shopping cart provider

* remove menu price from global state

* fix bug in remove menu from cart

* fix error in menuItems calculations

* update some names in the shoppingcart context

* add the none button for food items

* update remove item from cart method to calculate total price correctly

* remove unused file

* create the radio button

* calculate order quantity

* remove quantity count from checkout

* Development (#287)

* update github workflow yaml file

* rename the frontend folder

* create the checkout button

* create dynamic route

* update the routing definition and getmenubyId API call

* Merge branch 'development' of github.com:olasunkanmi-SE/restaurant into development

* remove the styling for menu name

* optimize the components

* conditionally render the checkout component

* remove code smell

* Merge branch 'release' into development

* update the menu item page and clean up the navigation

* create the delete menu repo method, service and controller

* create the delete menu API

* update food menu component to include item id

* update food menu component to include item id

* add the add menu item to cart functionality

* implement add menu items to cart

* fix build errors

* fix code smell

* create the item quantity button component

* update the menu list ui

* implement the add items to cart functionality

* fix code smell

* create the selected items summary

* update cart reducer

* update the add item to cart implementation

* create folder structure for componsnts

* implement the remove from cart functionality

* implement the add to cart functionality

* rename add and remove from cart to add and remove menu from cart

* remove the menuid from foodmenu component

* create the shopping component

* implement display menu quantity, also display only menu items ata a time

* prevent increase in total price if the menu quantity is 1

* fix issues with totalprice calculations

* fix issues with menu items reduction

* fix the bug in shopping cart provider

* remove menu price from global state

* fix bug in remove menu from cart

* fix error in menuItems calculations

* update some names in the shoppingcart context

* add the none button for food items

* update remove item from cart method to calculate total price correctly

* remove unused file

* create the radio button

* calculate order quantity

* remove quantity count from checkout

* Calculate cart total

* disable add to cart buttons on page load

* add development branch to github workflow, in order to track and build branches created from issues

* fix code smells
  • Loading branch information
olasunkanmi-SE authored Jun 4, 2023
1 parent db90f65 commit f3e6092
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI for restaurant

on:
pull_request:
branches: [release, main]
branches: [release, main, development]
push:
branches: [release, main]
branches: [release, main, development]

jobs:
build:
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/components/Cart/AddMenuToCart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ type addItemToCart = {
onAddMenuToCart: (event: React.MouseEvent<HTMLElement>) => void;
onRemoveMenuFromCart: (event: React.MouseEvent<HTMLElement>) => void;
handleInCreaseQty: (event: React.MouseEvent<HTMLElement>) => void;
disableQuatityButton: boolean;
disableAddToCartButton: boolean;
};

export const AddMenuToCartButton = ({
id,
quantity,
onAddMenuToCart,
onRemoveMenuFromCart,
basePrice,
handleInCreaseQty,
disableQuatityButton,
disableAddToCartButton,
}: addItemToCart) => {
const { itemPrice, addMenuToCart } = useShoppingCart();
const HandleAddMenuToCart = () => {
Expand All @@ -33,15 +36,21 @@ export const AddMenuToCartButton = ({
return (
<Stack direction="horizontal" gap={3}>
<div>
<QtyButton sign={"increment"} onClick={handleInCreaseQty} />
<QtyButton disabled={disableQuatityButton} sign={"increment"} onClick={handleInCreaseQty} />
</div>
<div>{quantity === 0 ? 1 : quantity}</div>
<div>
<QtyButton sign={"decrement"} onClick={onRemoveMenuFromCart} />
<QtyButton disabled={disableQuatityButton} sign={"decrement"} onClick={onRemoveMenuFromCart} />
</div>
<div className="ms-auto">
<div style={addToCartStyle}>
<Button onClick={HandleAddMenuToCart} className="w-100 btn btn-success" variant="primary" type="button">
<Button
disabled={disableAddToCartButton}
onClick={HandleAddMenuToCart}
className="w-100 btn btn-success"
variant="primary"
type="button"
>
ADD TO CART RM {itemPrice(id) === undefined ? basePrice : itemPrice(id)}
</Button>
</div>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/MenuItems/addItemButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ const QtyButtonStyle: CSSProperties = {
type QtyButtonType = {
onClick: (event: React.MouseEvent<HTMLElement>) => void;
sign: string;
disabled?: boolean;
};

export const QtyButton = ({ onClick, sign }: QtyButtonType) => {
export const QtyButton = ({ onClick, sign, disabled }: QtyButtonType) => {
return (
<input
disabled={disabled}
onClick={onClick}
style={QtyButtonStyle}
type="button"
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Utilities/Checkout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CSSProperties } from "react";
import { Stack } from "react-bootstrap";
import { useShoppingCart } from "../../hooks/UseShoppingCart";
import { calculateTotalOrderAmount } from "../../utility/utils";

const checkoutStyle: CSSProperties = {
zIndex: 9999,
Expand All @@ -12,16 +12,16 @@ const checkoutStyle: CSSProperties = {
color: "#FFF",
height: "40px",
backgroundColor: "#000000",
fontWeight: 700,
};

export const Checkout = () => {
const { quantity, totalPrice } = useShoppingCart();
return (
<div style={checkoutStyle}>
<Stack className="mt-2" direction="horizontal" gap={3}>
<div>Checkout</div>
<div style={{ marginRight: "10px" }} className="ms-auto">
Total: RM {totalPrice}
Total: RM {calculateTotalOrderAmount()}
</div>
</Stack>
</div>
Expand Down
20 changes: 11 additions & 9 deletions frontend/src/contexts/shoppingCartContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createContext, useMemo, useReducer, useState } from "react";
import { selectedItemToMenuMapper } from "../application/mappers/MenuItem.mapper";
import { CartActionsType, CartItem, OrderSummary, cartReducer, initialCartState, selectedItem } from "../reducers";
import { ShoppingCart } from "../components/ShoppingCart";
import { useNavigate } from "react-router-dom";

type shoppingCartProviderProps = {
children: React.ReactNode;
Expand All @@ -28,6 +29,7 @@ export type shoppingCartProps = {
};

export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) => {
const navigate = useNavigate();
const [state, dispatch] = useReducer(cartReducer, initialCartState);
const [isOpen, setIsOpen] = useState<boolean>(false);
const [qty, setqty] = useState<number>(0);
Expand All @@ -42,7 +44,7 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>

const AddMoreMenu = (id: string): number | undefined => {
const menu = state.menus.find((menu) => menu.id === id);
if (menu && menu.selectedItems) {
if (menu?.selectedItems) {
const menuPrice = calculateMenuTotalPriceFromMenuItems(id)! * menu.quantity!;
menu.menuTotalPrice = menuPrice;
}
Expand All @@ -56,7 +58,7 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
state.menus.push(payload);
}

if (state.menus.length) {
if (menus.length) {
const found = menus.find((menu) => menu?.id === payload.id);
if (!found) {
state.quantity += 1;
Expand Down Expand Up @@ -118,14 +120,13 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
};

const removeItemFromCart = (menuItem: selectedItem) => {
const menu = state.menus.find((menu) => menu.id === menuItem.menuId);
if (menu && menu.menuTotalPrice) {
let { menus } = state;
let { menus } = state;
const menu = menus.find((menu) => menu.id === menuItem.menuId);
if (menu?.menuTotalPrice) {
let menuItems: selectedItem[] = [];

for (const menu of menus) {
if (menu.id === menuItem.menuId) {
if (menu.selectedItems && menu.selectedItems.length) {
if (menu?.selectedItems && menu.selectedItems.length) {
menuItems = menu.selectedItems;
}
}
Expand Down Expand Up @@ -158,7 +159,7 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
const menu: Partial<CartItem> | undefined = state.menus.find((menu) => menu.id === id);
let totalPrice: number = 0;
if (menu) {
const selectedItems: selectedItem[] = menu.selectedItems || [];
const selectedItems: selectedItem[] = menu.selectedItems ?? [];
let orderPrice: number = 0;
if (selectedItems?.length) {
selectedItems.forEach((item) => {
Expand Down Expand Up @@ -197,7 +198,7 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
if (state.menus.length) {
state.menus.forEach((menu) => {
if (menuItem.menuId === menu.id) {
selectedItems = menu.selectedItems || [];
selectedItems = menu.selectedItems ?? [];
if (!selectedItems?.length) {
menuItem.quantity = 0;
selectedItems.push(menuItem);
Expand Down Expand Up @@ -271,6 +272,7 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
orderSummary.push(orderInfo);
state.menus = [];
state.quantity = 0;
navigate("/");

dispatch({
type: CartActionsType.ADD_MENU_TO_CART,
Expand Down
35 changes: 22 additions & 13 deletions frontend/src/pages/FoodMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,36 @@ import { Item } from "../reducers";
import { CartItemsList } from "../components/Cart/CartItemsList";
import { StoreItem } from "../components/MenuItems/StoreItem";
import { AddMenuToCartButton } from "../components/Cart/AddMenuToCart";
import { useEffect, useState } from "react";

const mapItems = (items: IItem[]): Item[] => {
const stateItem =
items &&
items.map((item) => {
const { id, name, price, maximumPermitted } = item;
return {
id,
name,
price,
maximumPermitted,
};
});
const stateItem = items?.map((item) => {
const { id, name, price, maximumPermitted } = item;
return {
id,
name,
price,
maximumPermitted,
};
});
return stateItem;
};

export const FoodMenu = () => {
const { increaseMenuQuantity, quantity, totalPrice, removeMenuFromCart, getMenuQuantity } = useShoppingCart();
const [disableAddToCartBtns, setDisableAddToCartBtns] = useState<boolean>(false);

useEffect(() => {
setDisableAddToCartBtns(true);
return () => {
setDisableAddToCartBtns(false);
};
}, []);

const { id } = useParams();
let response;
if (id) {
const { isLoading, data: menu } = getMenuById(id);
const { increaseMenuQuantity, quantity, totalPrice, removeMenuFromCart, getMenuQuantity, addMenuToCart } =
useShoppingCart();
const items = mapItems(menu?.data?.items!);
if (isLoading) {
response = <p>...Loading</p>;
Expand Down Expand Up @@ -58,6 +65,8 @@ export const FoodMenu = () => {
onAddMenuToCart={() => increaseMenuQuantity({ id, name, basePrice, quantity, items })}
amount={totalPrice > 0 ? totalPrice : basePrice}
onRemoveMenuFromCart={() => removeMenuFromCart({ id, name, basePrice, quantity, items })}
disableQuatityButton={disableAddToCartBtns}
disableAddToCartButton={disableAddToCartBtns}
/>
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/utility/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ export const calculateQuantity = (quantity: number) => {
}
return orderQuantity;
};

export const calculateTotalOrderAmount = (): number => {
const { GetOrderSummary } = useShoppingCart();
const orderSummary = GetOrderSummary();
const total = orderSummary.reduce((acc, order) => acc + order.menus[0].menuTotalPrice!, 0);
return total > 0 ? total : 0;
};

0 comments on commit f3e6092

Please sign in to comment.