Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #261

Merged
merged 49 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2ee3f51
update github workflow yaml file
olasunkanmi-SE Mar 21, 2023
3819c92
rename the frontend folder
olasunkanmi-SE Mar 22, 2023
930d471
create the checkout button
olasunkanmi-SE Mar 22, 2023
d271316
Merge branch 'release' into development
olasunkanmi-SE Mar 22, 2023
095f6f7
create dynamic route
olasunkanmi-SE Mar 23, 2023
4915dc1
update the routing definition and getmenubyId API call
olasunkanmi-SE Mar 24, 2023
fab228f
update the routing definition and getmenubyId API call
olasunkanmi-SE Mar 24, 2023
a465cd9
Merge branch 'release' into development
olasunkanmi-SE Mar 24, 2023
a1e1b04
Merge branch 'development' of github.com:olasunkanmi-SE/restaurant in…
olasunkanmi-SE Mar 24, 2023
0856185
Merge branch 'development' of github.com:olasunkanmi-SE/restaurant in…
olasunkanmi-SE Mar 24, 2023
98a0bcc
remove the styling for menu name
olasunkanmi-SE Mar 24, 2023
83b8773
optimize the components
olasunkanmi-SE Mar 24, 2023
7d810d5
conditionally render the checkout component
olasunkanmi-SE Mar 24, 2023
e788815
Merge branch 'release' into development
olasunkanmi-SE Mar 24, 2023
2d3d11b
remove code smell
olasunkanmi-SE Mar 24, 2023
2466e8d
Merge branch 'development' of github.com:olasunkanmi-SE/restaurant in…
olasunkanmi-SE Mar 24, 2023
0e614cc
Merge branch 'release' into development
olasunkanmi-SE Mar 24, 2023
b074a16
Merge branch 'release' into development
olasunkanmi-SE Mar 24, 2023
3f62b73
Merge branch 'development' of github.com:olasunkanmi-SE/restaurant in…
olasunkanmi-SE Mar 24, 2023
1efc8b3
update the menu item page and clean up the navigation
olasunkanmi-SE Mar 25, 2023
ce8a839
create the delete menu repo method, service and controller
olasunkanmi-SE Mar 26, 2023
48a45c4
create the delete menu API
olasunkanmi-SE Mar 26, 2023
45f4dc2
update food menu component to include item id
olasunkanmi-SE Mar 27, 2023
a72843a
update food menu component to include item id
olasunkanmi-SE Mar 27, 2023
630bacd
Merge branch 'release' into development
olasunkanmi-SE Mar 27, 2023
936d146
add the add menu item to cart functionality
olasunkanmi-SE Mar 28, 2023
40c5356
Merge branch 'development' of github.com:olasunkanmi-SE/restaurant in…
olasunkanmi-SE Mar 28, 2023
82da626
implement add menu items to cart
olasunkanmi-SE Mar 28, 2023
9eb6866
fix build errors
olasunkanmi-SE Mar 28, 2023
20d151b
fix code smell
olasunkanmi-SE Mar 28, 2023
70940d2
create the item quantity button component
olasunkanmi-SE Mar 29, 2023
988de5b
Merge branch 'release' into development
olasunkanmi-SE Mar 29, 2023
140f9e8
update the menu list ui
olasunkanmi-SE Mar 30, 2023
246bab7
Merge branch 'development' of github.com:olasunkanmi-SE/restaurant in…
olasunkanmi-SE Mar 30, 2023
30840d1
implement the add items to cart functionality
olasunkanmi-SE Apr 3, 2023
bf73e39
Merge branch 'release' into development
olasunkanmi-SE Apr 3, 2023
c4d2dad
fix code smell
olasunkanmi-SE Apr 3, 2023
18017e5
Merge branch 'development' of github.com:olasunkanmi-SE/restaurant in…
olasunkanmi-SE Apr 3, 2023
df960d1
create the selected items summary
olasunkanmi-SE Apr 3, 2023
31a8ce0
update cart reducer
olasunkanmi-SE Apr 4, 2023
8f6f5f9
Merge branch 'release' into development
olasunkanmi-SE Apr 4, 2023
3970e77
update the add item to cart implementation
olasunkanmi-SE Apr 5, 2023
756fa20
Merge branch 'development' of github.com:olasunkanmi-SE/restaurant in…
olasunkanmi-SE Apr 5, 2023
e6c5a3b
Merge branch 'release' into development
olasunkanmi-SE Apr 5, 2023
e0a7b57
create folder structure for componsnts
olasunkanmi-SE Apr 5, 2023
ae36614
Merge branch 'development' of github.com:olasunkanmi-SE/restaurant in…
olasunkanmi-SE Apr 5, 2023
dc59f6b
resolve conflicts
olasunkanmi-SE Apr 5, 2023
bee779c
implement the remove from cart functionality
olasunkanmi-SE Apr 5, 2023
eaae18e
Merge branch 'release' into development
olasunkanmi-SE Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions frontend/src/components/Cart/CartItemsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ export const CartItemsList = () => {
return (
<div className="">
<Stack direction="horizontal" gap={3} className="gap-3">
{itemSummaries.map((item) => (
<small style={{ marginLeft: "4px", fontSize: "11px" }} key={item.id}>
+{item.name.toLowerCase()} x {item.qty}
</small>
))}
{itemSummaries.map((item) =>
item.qty > 0 ? (
<small style={{ marginLeft: "4px", fontSize: "11px" }} key={item.id}>
+{item.name.toLowerCase()} x {item.qty}
</small>
) : (
""
)
)}
</Stack>
</div>
);
Expand Down
42 changes: 0 additions & 42 deletions frontend/src/components/CartItemsList.tsx

This file was deleted.

17 changes: 13 additions & 4 deletions frontend/src/components/MenuItems/FoodItemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { storeItemProps } from "./StoreItem";
type foodItem = storeItemProps & { itemId: string; itemPrice: number };

export const FoodItemList = ({ name, itemId, itemPrice, id, basePrice }: Omit<foodItem, "items">) => {
const { addItemToCart, menus } = useShoppingCart();
const { addItemToCart, menus, removeItemFromCart } = useShoppingCart();
let itemQty: number = 0;
const handleClick = () => {
const handleAddItemToCart = () => {
return addItemToCart({
id: itemId,
name,
Expand All @@ -17,6 +17,15 @@ export const FoodItemList = ({ name, itemId, itemPrice, id, basePrice }: Omit<fo
menuPrice: basePrice,
});
};
const handleRemoveItemFromCart = () => {
return removeItemFromCart({
id: itemId,
name,
price: itemPrice,
menuId: id,
menuPrice: basePrice,
});
};
if (menus && menus.length) {
const selectedItems = menus.map((menu) => menu.selectedItems || []);
const flattenedSelectedItems = selectedItems.flat();
Expand All @@ -29,11 +38,11 @@ export const FoodItemList = ({ name, itemId, itemPrice, id, basePrice }: Omit<fo
return (
<>
<Stack direction="horizontal" gap={3}>
<QtyButton sign={"increment"} onClick={handleClick} />
<QtyButton sign={"increment"} onClick={handleAddItemToCart} />
<div>{name}</div>
<div className=" ms-auto"> +RM {itemPrice}</div>
<div>x {itemQty}</div>
<QtyButton sign={"decrement"} onClick={handleClick} />
<QtyButton sign={"decrement"} onClick={handleRemoveItemFromCart} />
</Stack>
<hr></hr>
</>
Expand Down
36 changes: 32 additions & 4 deletions frontend/src/contexts/shoppingCartContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type shoppingCartProps = {
addToCart(cartItem: CartItem): void;
removeFromCart(cartItem: CartItem): void;
addItemToCart(menuItem: selectedItem): void;
removeItemFromCart(menuItem: selectedItem): void;
};

export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) => {
Expand Down Expand Up @@ -68,12 +69,41 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
});
};

const removeItemFromCart = (menuItem: selectedItem) => {
let { menus } = state;
const menuItems: selectedItem[] = [];

for (const menu of menus) {
if (menu.id === menuItem.menuId) {
if (menu.selectedItems && menu.selectedItems.length) {
menuItems.push(...menu.selectedItems);
}
}
}

if (menuItems.length) {
for (let i = 0; i < menuItems.length; i++) {
const item = menuItems[i];
if (menuItem.id === item.id) {
if (item.quantity && item.quantity > 1) {
item.quantity -= 1;
} else {
item.quantity = 0;
}
}
}
}
console.log(state);
dispatch({
type: CartActionsType.REMOVE_ITEM_FROM_CART,
});
};

const addItemToCart = (menuItem: selectedItem) => {
let { menus } = state;
let { price } = menuItem;
const menu: Partial<CartItem> = selectedItemToMenuMapper(menuItem);
if (!menus.length) {
menuItem.total = price;
menuItem.quantity = 0;
state.menus.push(menu);
}
Expand All @@ -88,7 +118,6 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
if (selectedItems?.length) {
const index = selectedItems.findIndex((item) => item.id === menuItem.id);
if (index === -1) {
menuItem.total = price;
menuItem.quantity = 0;
selectedItems.push(menuItem);
}
Expand All @@ -98,7 +127,6 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
for (const item of selectedItemMap.values()) {
if (item.id === menuItem.id) {
item.quantity! += 1;
item.total = item.total! + item.price;
}
}
}
Expand All @@ -108,7 +136,6 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
selectedItems.forEach((item) => {
totalItemPrice += item.quantity! * item.price;
});
console.log(state);
state.totalPrice = totalItemPrice + menuItem.menuPrice;
}

Expand All @@ -133,6 +160,7 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
addToCart,
removeFromCart,
addItemToCart,
removeItemFromCart,
};
return value;
}, [state]);
Expand Down
13 changes: 5 additions & 8 deletions frontend/src/reducers/cartReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export enum CartActionsType {
UPDATE_PRICE = "UPDATE_PRICE",
GET_MENU_QUANTITY = "GET_MENU_QUANTITY",
ADD_ITEM_TO_CART = "ADD_ITEM_TO_CART",
REMOVE_ITEM_TO_CART = "REMOVE_ITEM_TO_CART",
REMOVE_ITEM_FROM_CART = "REMOVE_ITEM_FROM_CART",
}

export type Item = {
Expand All @@ -19,7 +19,6 @@ export type selectedItem = {
menuId: string;
name: string;
quantity?: number | 0;
total?: number;
price: number;
menuPrice: number;
};
Expand Down Expand Up @@ -62,16 +61,14 @@ export const cartReducer = (state = initialCartState, action: CartAction): cartS
return {
...state,
};
// case CartActionsType.GET_MENU_QUANTITY:
// let quantity = state.menus.length ?? state.menus.filter((item) => item.id === menuPayload!.id)?.length;
// return {
// ...state,
// quantity: quantity,
// };
case CartActionsType.ADD_ITEM_TO_CART:
return {
...state,
};
case CartActionsType.REMOVE_ITEM_FROM_CART:
return {
...state,
};
default:
throw new Error(`No case for type ${type} found in shopReducer.`);
}
Expand Down