Skip to content

Commit

Permalink
Release (#278)
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
  • Loading branch information
olasunkanmi-SE committed Apr 20, 2023
1 parent 1c1bd28 commit db90f65
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 41 deletions.
7 changes: 5 additions & 2 deletions frontend/src/components/Cart/AddMenuToCart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export const AddMenuToCartButton = ({
basePrice,
handleInCreaseQty,
}: addItemToCart) => {
const { itemPrice } = useShoppingCart();
const { itemPrice, addMenuToCart } = useShoppingCart();
const HandleAddMenuToCart = () => {
return addMenuToCart();
};
return (
<Stack direction="horizontal" gap={3}>
<div>
Expand All @@ -38,7 +41,7 @@ export const AddMenuToCartButton = ({
</div>
<div className="ms-auto">
<div style={addToCartStyle}>
<Button onClick={onAddMenuToCart} className="w-100 btn btn-success" variant="primary" type="submit">
<Button 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: 2 additions & 2 deletions frontend/src/components/MenuItems/NoMenuItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export const NoMenuItems = ({ handleCheck, isChecked }: NoItems) => {
return (
<div style={{ marginBottom: "-14px" }} className="pt-1 elBg">
<Stack direction="horizontal" gap={3}>
<div style={{ marginLeft: "4px" }}>
<div style={{ marginLeft: "6px" }}>
<Form.Check onClick={handleCheck} className="mr-2" type="checkbox" checked={isChecked} readOnly />
</div>
<div style={{ marginLeft: "4px", marginTop: "5px" }}>None</div>
<div style={{ marginLeft: "10px", marginTop: "5px" }}>None</div>
</Stack>
<hr></hr>
</div>
Expand Down
21 changes: 2 additions & 19 deletions frontend/src/components/Utilities/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,17 @@ const checkoutStyle: CSSProperties = {
height: "40px",
backgroundColor: "#000000",
};
const cartItemsCount: CSSProperties = {
color: "#000",
width: "1.5rem",
height: "1.5rem",
bottom: "0px",
right: "0px",
backgroundColor: "#fff",
textAlign: "center",
marginRight: "11px",
fontWeight: 600,
borderRadius: "10px",
};

export const Checkout = () => {
const { quantity, totalPrice } = useShoppingCart();
return (
<div style={checkoutStyle}>
<Stack className="mt-2" direction="horizontal" gap={3}>
<div>Checkout</div>
<div className="ms-auto">RM {totalPrice}</div>
<div className="ms-auto" style={cartItemsCount}>
{quantity}
<div style={{ marginRight: "10px" }} className="ms-auto">
Total: RM {totalPrice}
</div>
</Stack>
</div>
// <div style={checkoutStyle} className="d-flex justify-content-between">
// <div style={{ marginLeft: "11px" }}>Checkout</div>
// <div style={cartItemsCount}>{quantity}</div>
// </div>
);
};
5 changes: 3 additions & 2 deletions frontend/src/components/Utilities/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import Container from "react-bootstrap/Container";
import Navbar from "react-bootstrap/Navbar";
import { NavLink, Outlet, useNavigate } from "react-router-dom";
import { useShoppingCart } from "../../hooks/UseShoppingCart";
import { calculateQuantity } from "../../utility/utils";

export const Navigation = () => {
const { quantity, openCart } = useShoppingCart();
const { quantity, openCart, GetOrderSummary } = useShoppingCart();
const navigate = useNavigate();

const previousPage = () => {
Expand Down Expand Up @@ -79,7 +80,7 @@ export const Navigation = () => {
}}
className="rounded-circle d-flex justify-content-center align-items-center"
>
{quantity}
{calculateQuantity(quantity)}
</div>
</Button>
</Container>
Expand Down
28 changes: 17 additions & 11 deletions frontend/src/contexts/shoppingCartContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export type shoppingCartProps = {
itemPrice(id: string): number | undefined;
AddMoreMenu(id: string): number | undefined;
addMenuToCart(): void;
GetOrderSummary(): OrderSummary[];
};

export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) => {
const [state, dispatch] = useReducer(cartReducer, initialCartState);
const [isOpen, setIsOpen] = useState<boolean>(false);
const [qty, setqty] = useState<number>(0);

const shoppingCartState = useMemo(() => {
const openCart = () => {
Expand All @@ -48,9 +50,7 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
};

const increaseMenuQuantity = (payload: CartItem) => {
console.log(state);
let menus: Partial<CartItem>[] = state.menus;

if (!state.menus.length) {
payload.selectedItems = [];
state.menus.push(payload);
Expand All @@ -59,9 +59,7 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
if (state.menus.length) {
const found = menus.find((menu) => menu?.id === payload.id);
if (!found) {
state.menus = [...state.menus, payload];
state.quantity += 1;
payload.quantity = 1;
} else {
if (!found.quantity) {
state.quantity = state.quantity === 0 ? state.quantity + 2 : (state.quantity += 1);
Expand Down Expand Up @@ -114,7 +112,6 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
state.totalPrice = 0;
}
}
console.log(state);
dispatch({
type: CartActionsType.REMOVE_MENU_FROM_CART,
});
Expand Down Expand Up @@ -181,7 +178,6 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
};

const addItemToCart = (menuItem: selectedItem) => {
console.log(state);
let { menus } = state;
const menu: Partial<CartItem> = selectedItemToMenuMapper(menuItem);
if (!menus.length) {
Expand Down Expand Up @@ -244,7 +240,6 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
}
}
}
console.log(state);
}
dispatch({
type: CartActionsType.ADD_ITEM_TO_CART,
Expand All @@ -263,18 +258,28 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
};

const addMenuToCart = () => {
console.log(state);
let { menus, quantity, orderSummary } = state;
let stateQty = 0;
const orderInfo: OrderSummary = {
menus,
quantity,
};
if (quantity === 0) {
orderInfo.quantity = 1;
}
orderSummary.push(orderInfo);
state.menus[0].quantity = 1;
state.menus = [];
console.log(state);
return state;
state.quantity = 0;

dispatch({
type: CartActionsType.ADD_MENU_TO_CART,
});
};

const GetOrderSummary = (): OrderSummary[] => {
return state.orderSummary;
};
const resetMenuState = () => {};

const value: shoppingCartProps = {
totalPrice: state.totalPrice,
Expand All @@ -291,6 +296,7 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
itemPrice,
AddMoreMenu,
addMenuToCart,
GetOrderSummary,
};
return value;
}, [state]);
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ hr {
}

.form-check-input {
width: 2em;
height: 2em;
width: 1.7em;
height: 1.7em;
border-radius: 100% !important;
background-color: #efefef;
border-color: #e5e0e0
}

.form-check-input:checked {
width: 2em;
height: 2em;
width: 1.7em;
height: 1.7em;
border-radius: 100% !important;
background-color: #21c579;
background-color: #168c55;
border-color: #f7a2;
}
5 changes: 5 additions & 0 deletions frontend/src/reducers/cartReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum CartActionsType {
REMOVE_ITEM_FROM_CART = "REMOVE_ITEM_FROM_CART",
GET_MENU_PRICE = "GET_MENU_PRICE",
INCREASE_MENU_QUANTITY = "INCREASE_MENU_QUANTITY",
GET_ORDER_SUMMARY = "GET_ORDER_SUMMARY",
}

export type OrderSummary = {
Expand Down Expand Up @@ -90,6 +91,10 @@ export const cartReducer = (state = initialCartState, action: CartAction): cartS
return {
...state,
};
case CartActionsType.GET_ORDER_SUMMARY:
return {
...state,
};
default:
throw new Error(`No case for type ${type} found in shopReducer.`);
}
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/utility/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useShoppingCart } from "../hooks/UseShoppingCart";

const currencyFormatter = new Intl.NumberFormat(undefined, {
currency: "NGR",
style: "currency",
Expand All @@ -10,3 +12,15 @@ export function formatCurrency(number: number) {
export const capitalizeFirstLetter = (word: string) => {
return word.charAt(0).toUpperCase() + word.slice(1);
};

export const calculateQuantity = (quantity: number) => {
const { GetOrderSummary } = useShoppingCart();
const orderSummary = GetOrderSummary();
let orderQty = orderSummary.reduce((acc, order) => acc + order.quantity, 0);
let orderQuantity = orderQty || 0;

if ((quantity === 0 && orderSummary.length) || (quantity !== 0 && orderSummary.length)) {
return orderQuantity;
}
return orderQuantity;
};

0 comments on commit db90f65

Please sign in to comment.