Skip to content

Commit

Permalink
Release (#258)
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
  • Loading branch information
olasunkanmi-SE authored Apr 5, 2023
1 parent 88440d1 commit 233f9e0
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 28 deletions.
9 changes: 9 additions & 0 deletions frontend/src/application/mappers/MenuItem.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ItemsSummary } from "../../components/CartItemsList";
import { CartItem, selectedItem } from "../../reducers";

export const selectedItemToMenuMapper = (selectedItem: selectedItem): Partial<CartItem> => {
Expand All @@ -7,3 +8,11 @@ export const selectedItemToMenuMapper = (selectedItem: selectedItem): Partial<Ca
selectedItems: [selectedItem],
};
};

export const ItemToSummaryMapper = (item: selectedItem): ItemsSummary => {
return {
id: item.id,
name: item.name,
qty: item.quantity || 0,
};
};
1 change: 1 addition & 0 deletions frontend/src/components/AddToCart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { QtyButton } from "./addItemButton";

const addToCartStyle: CSSProperties = {
textAlign: "center",
marginRight: "10px",
};

type addItemToCart = {
Expand Down
42 changes: 42 additions & 0 deletions frontend/src/components/CartItemsList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Stack } from "react-bootstrap";
import { ItemToSummaryMapper } from "../application/mappers/MenuItem.mapper";
import { useShoppingCart } from "../hooks/UseShoppingCart";

export type ItemsSummary = {
id: string;
name: string;
qty: number;
};

export const CartItemsList = () => {
const { menus } = useShoppingCart();
let itemSummaries: ItemsSummary[] = [];
if (menus && menus.length) {
const itemsMap = new Map<string, ItemsSummary>();
const selectedItems = menus.map((menu) => menu.selectedItems || []);
const flattenedSelectedItems = selectedItems.flat();
flattenedSelectedItems.forEach((item) => {
const selectedItem = ItemToSummaryMapper(item);
if (itemsMap.has(item.id)) {
itemsMap.get(item.id)!.qty += 1;
} else {
itemsMap.set(item.id, selectedItem);
}
});
for (const item of itemsMap.values()) {
itemSummaries.push(item);
}
}

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>
))}
</Stack>
</div>
);
};
3 changes: 2 additions & 1 deletion frontend/src/components/FoodItemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { storeItemProps } from "./StoreItem";
import { QtyButton } from "./addItemButton";

type foodItem = storeItemProps & { itemId: string; itemPrice: number };
export const FoodItemList = ({ name, itemId, itemPrice, id, basePrice }: foodItem) => {

export const FoodItemList = ({ name, itemId, itemPrice, id, basePrice }: Omit<foodItem, "items">) => {
const { addItemToCart } = useShoppingCart();
const handleClick = () => {
return addItemToCart({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type menuItemProps = {

export const MenuItem = ({ name, url, description, basePrice }: menuItemProps) => {
return (
<Card style={{ border: "none", borderRadius: "10% " }}>
<Card className="menuCard">
<div>
<Card.Img style={{ objectFit: "cover", borderRadius: "50px" }} height="200px" variant="top" src={url} />
<MenuInfo name={name} price={basePrice} description={description} />
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/StoreItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Card, Col, Row } from "react-bootstrap";
import { FoodItemList } from "./FoodItemList";
import { Item } from "../reducers";
import { CartItemsList } from "./CartItemsList";

export type storeItemProps = {
id: string;
Expand Down Expand Up @@ -38,12 +39,11 @@ export const StoreItem = ({ id, name, description, imageUrl, basePrice, items, q
<i style={{ backgroundColor: "#f7a278", color: "#fff", padding: "4px" }}>More Portion</i>
</p>
</div>
<>
<div className="pt-2 elBg">
{items.map((item) => (
<div className="mb-5" key={item.id}>
<div key={item.id}>
<FoodItemList
quantity={quantity}
items={items}
id={id}
itemId={item.id}
name={item.name}
Expand All @@ -52,7 +52,7 @@ export const StoreItem = ({ id, name, description, imageUrl, basePrice, items, q
/>
</div>
))}
</>
</div>
</Col>
</Row>
</>
Expand Down
33 changes: 19 additions & 14 deletions frontend/src/contexts/shoppingCartContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,34 @@ export const ShoppingCartProvider = ({ children }: shoppingCartProviderProps) =>
state.menus.forEach((menu) => {
if (menuItem.menuId === menu.id) selectedItems = menu.selectedItems;
});
selectedItems?.forEach((item) => selectedItemMap.set(item.menuId, item));
state.menus.forEach((menu) => {
if (selectedItemMap.has(menu.id!)) {
const selectedItem = selectedItemMap.get(menu.id!);
if (selectedItem!.id === menuItem.id) {
selectedItem!.quantity! += 1;
selectedItem!.total = selectedItem!.total! + selectedItem!.price;
} else {
menuItem.total = price;
menuItem.quantity = 1;
selectedItems?.push(menuItem);
}

if (selectedItems?.length) {
const index = selectedItems.findIndex((item) => item.id === menuItem.id);
if (index === -1) {
menuItem.total = price;
menuItem.quantity = 0;
selectedItems.push(menuItem);
}
});
}

selectedItems?.forEach((item) => selectedItemMap.set(item.id, item));
for (const item of selectedItemMap.values()) {
if (item.id === menuItem.id) {
item.quantity! += 1;
item.total = item.total! + item.price;
}
}
}

if (selectedItems && selectedItems.length) {
let totalItemPrice: number = 0;
selectedItems.forEach((item) => {
totalItemPrice += item.quantity! * item.price;
});

console.log(state);
state.totalPrice = totalItemPrice + menuItem.menuPrice;
}

dispatch({
type: CartActionsType.ADD_ITEM_TO_CART,
});
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,22 @@ hr {

.card {
border: 1px solid #f3f3f3;
}

.menuCard {
margin: 0;
box-shadow: 0 1px 6px rgba(0, 0, 0, .16);
border-radius: 20px;
height: 100%;
display: flex;
flex-direction: column;
}

.elBg {
background-color: #fff;
}

.addToCart {
padding-bottom: 15px;
border-top: 0.1rem solid #f1f1f1;
}
19 changes: 12 additions & 7 deletions frontend/src/pages/FoodMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AddToCartButton, StoreItem } from "../components";
import { useShoppingCart } from "../hooks/UseShoppingCart";
import { IItem } from "../models/item.model";
import { Item } from "../reducers";
import { CartItemsList } from "../components/CartItemsList";

const mapItems = (items: IItem[]): Item[] => {
const stateItem =
Expand All @@ -26,7 +27,6 @@ export const FoodMenu = () => {
if (id) {
const { isLoading, data: menu } = getMenuById(id);
const { addToCart, quantity, totalPrice } = useShoppingCart();

const items = mapItems(menu?.data?.items!);

if (isLoading) {
Expand All @@ -45,12 +45,17 @@ export const FoodMenu = () => {
basePrice={basePrice}
id={id}
/>
<AddToCartButton
onAddMenuToCartClick={() => addToCart({ id, name, basePrice, quantity, items })}
amount={totalPrice > 0 ? totalPrice : basePrice}
onAddItemToCartClick={() => addToCart({ id, name, basePrice, quantity, items })}
onRemoveItemFromCartClick={() => addToCart({ id, name, basePrice, quantity, items })}
/>
<div className="elBg addToCart">
<div className=" pt-2 pb-2">
<CartItemsList />
</div>
<AddToCartButton
onAddMenuToCartClick={() => addToCart({ id, name, basePrice, quantity, items })}
amount={totalPrice > 0 ? totalPrice : basePrice}
onAddItemToCartClick={() => addToCart({ id, name, basePrice, quantity, items })}
onRemoveItemFromCartClick={() => addToCart({ id, name, basePrice, quantity, items })}
/>
</div>
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/reducers/cartReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type selectedItem = {
id: string;
menuId: string;
name: string;
quantity?: number;
quantity?: number | 0;
total?: number;
price: number;
menuPrice: number;
Expand Down

0 comments on commit 233f9e0

Please sign in to comment.