Skip to content

Commit

Permalink
feat(frontend-workflow): Addition of table billing page
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsukoyachi committed Sep 21, 2024
1 parent 1b59815 commit 0273004
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 133 deletions.
3 changes: 2 additions & 1 deletion apps/frontend-bff/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import NxWelcome from './nx-welcome';

import { Link, Route, Routes } from 'react-router-dom';
import { LandingPage, Offers, UiCommon,Orders, GroupBilling, Summary, NavBar } from '@spos/ui/common';
import { LandingPage, Offers, Orders, GroupBilling, Summary, NavBar, TableBilling } from '@spos/ui/common';

export function App() {
return (
Expand All @@ -21,6 +21,7 @@ export function App() {
<Route path="/orders" element={<Orders />} />
<Route path="/navbar" element={<NavBar />} />
<Route path="/groupBilling" element={<GroupBilling />} />
<Route path="/tableBilling" element={<TableBilling />} />

</Routes>
{/* END: routes */}
Expand Down
1 change: 1 addition & 0 deletions libs/ui/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from './lib/offers/offers';
export * from './lib/orders/orders';
export * from './lib/summary/summary';
export * from './lib/groupBillingPage/groupBillingPage';
export * from './lib/tableBillingPage/tableBilling';
export * from './lib/utils/navbar';
90 changes: 0 additions & 90 deletions libs/ui/common/src/lib/groupBillingPage/groupBillingPage.css

This file was deleted.

86 changes: 44 additions & 42 deletions libs/ui/common/src/lib/groupBillingPage/groupBillingPage.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import './groupBillingPage.css';
import { Button, Typography, Box } from "@mui/material";
import { Box, Button, Typography } from "@mui/material";
import { useNavigate } from "react-router-dom";

export function GroupBilling() {
const navigate = useNavigate();
const billingData = [
{
number : 1,
elements : [
{quantity : 1, item: {id: 1, name: "Coca", price: 1.5}},
{quantity : 2, item: {id: 2, name: "Fried chicken", price: 4.35}}
number: 1,
elements: [
{ quantity: 1, item: { id: 1, name: "Coca", price: 1.5 } },
{ quantity: 2, item: { id: 2, name: "Fried chicken", price: 4.35 } }
]
},
{
number : 2,
elements : [
{quantity : 1, item: {id: 3, name: "Orangina", price: 1.5}},
{quantity : 6, item: {id: 4, name: "Mozzarella stick", price: 1}}
number: 2,
elements: [
{ quantity: 1, item: { id: 3, name: "Orangina", price: 1.5 } },
{ quantity: 6, item: { id: 4, name: "Mozzarella stick", price: 1 } }
]
}
];
Expand All @@ -28,47 +27,50 @@ export function GroupBilling() {
}, 0);

const validatePayment = () => {
console.log({totalPrice})
navigate("/")
}
console.log({ totalPrice });
navigate("/");
}

return (
<div id='billing-container' className='container'>
<Box className="group-billing">
<Typography align='left' variant="h1" component="h2" fontSize="8vw" fontWeight="bold">
<Box sx={{ backgroundColor: '#d9d9d9', minHeight: '100dvh', paddingTop: '5dvh', paddingLeft: '5dvw', paddingRight: '5dvw',
display: 'flex', flexDirection: 'column', justifyContent: 'space-around'}}>
<Box sx={{ minHeight: '75dvh'}}>
<Typography variant="h2" component="h2" sx={{ fontSize: '8vw', fontWeight: 'bold', paddingLeft: '100px' }}>
Billing
</Typography>
<div id="billing-section">
{billingData.map(table => (
<div key={table.number}>
<Typography id='table-title' align='left' variant="h3" component="h3" fontSize="5vw" fontWeight="bold" >
{"Table " + table.number}
</Typography>
<table>
{table.elements.map(element => (
<tbody key={element.item.id}>
<tr>
<td>{element.quantity} x {element.item.name}</td>
<td>{element.quantity * element.item.price}$</td>
</tr>
</tbody>
))}
</table>
</div>
))}
</div>
{billingData.map((table, index) => (
<Box key={index} sx={{ margin: '2vh 0', backgroundColor: '#d9d9d9' }}>
<Typography variant="h3" component="h3" sx={{ fontSize: '5vw', fontWeight: 'bold', textDecoration: 'underline' }}>
{"Table " + table.number}
</Typography>
<Box sx={{ padding: '2vh 0' }}>
{table.elements.map((element, index) => (
<Box key={index} sx={{ display: 'flex', justifyContent: 'space-between', padding: '1vh 3vw' }}>
<Typography variant="body1" component="span" fontWeight={400} fontSize={'3vw'}>
{element.quantity} x {element.item.name}
</Typography>
<Typography variant="body1" component="span" fontWeight={400} fontSize={'3vw'}>
${element.quantity * element.item.price}
</Typography>
</Box>
))}
</Box>
</Box>
))}
</Box>
<Box id="summary-section">
<hr />
<div>
<p>Total : {totalPrice}$</p>
<Box sx={{ padding: '3vh 5vw', backgroundColor: '#d9d9d9' }}>
<hr style={{border: 'none', borderTop:'1px solid rgba(0, 0, 0, 1)', margin: '20px 0'}} />
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<Typography variant="body1" component="span" fontWeight={400} fontSize={'3vw'}>
Total: ${totalPrice}
</Typography>
<Button onClick={validatePayment} variant="contained" color="inherit"
style={{padding: '20px 50px', borderRadius: '50px', fontSize: '4vw'}}>
sx={{ padding: '20px 50px', borderRadius: '50px', fontSize: '4vw' }}>
Paid
</Button>
</div>
</Box>
</Box>
</div>
</Box>
);
}

Expand Down
123 changes: 123 additions & 0 deletions libs/ui/common/src/lib/tableBillingPage/tableBilling.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { Button, Typography, Box } from "@mui/material";
import { useNavigate } from "react-router-dom";
import React, { useState } from 'react';
import NavBar from "../utils/navbar";

const theme = {
hr: {
border: 'none',
borderTop: '1px solid rgba(0, 0, 0, 1)',
margin: '20px 0'
}
};

export function TableBilling() {
const navigate = useNavigate();

const tableNumber = 1;

const data = [
{remaining : 1, item: {id: 1, name: "Coca", price: 1.5}},
{remaining : 2, item: {id: 2, name: "Fried chicken", price: 4.35}}
]

const [quantities, setQuantities] = useState(data.map((item) => ({ quantity: 0, ...item })));
const getTotalPrice = (): number => {
return quantities.reduce((acc, { quantity, item }) => acc + (quantity * item.price), 0);
};


const handleIncrementDecrement = (index: number, delta: number) => {
setQuantities((prevQuantities) => {
const updatedQuantities = [...prevQuantities];
let newQuantity = prevQuantities[index].quantity + delta;

// Ensure the quantity is not less than 0
if (newQuantity < 0) {
newQuantity = 0;
}

else if (newQuantity > data[index].remaining) {
newQuantity = data[index].remaining;
}

updatedQuantities[index].quantity = newQuantity;

return updatedQuantities;
});
};

const handleSelectAll = () => {
setQuantities((prevQuantities) => prevQuantities.map((item, index) => ({ ...item, quantity: data[index].remaining })));
};

const handleUnselectAll = () => {
setQuantities((prevQuantities) => prevQuantities.map((item, index) => ({ ...item, quantity: 0 })));
};

const validatePayment = () => {
console.log(getTotalPrice())
navigate("/")
}

return (
<Box sx={{minHeight: '100dvh', display: 'flex', flexDirection: 'row'}}>
<Box sx={{boxSizing: 'border-box', width: 'fit-content', borderRight: '2px solid #000'}}>
<NavBar />
</Box>
<Box id="test" sx={{boxSizing: 'border-box', backgroundColor: '#d9d9d9', flexGrow: 1,
paddingTop: '5dvh', paddingLeft: '5dvw', paddingRight: '5dvw'
}}>
<div id="billing-section" style={{minHeight: '75dvh'}}>
<Typography variant="h2" component="h2" sx={{ fontSize: '8vw', fontWeight: 'bold', paddingLeft: '100px' }}>
Billing
</Typography>
<div style={{display: "flex", justifyContent: "space-between", alignItems: "center"}}>
<Typography variant="h3" component="h3"
sx={{ fontSize: '5vw', fontWeight: 'bold', textDecoration: 'underline',
margin: '2vh 0' }}>
{"Table " + tableNumber}
</Typography>
<div>
<Button onClick={handleSelectAll} variant="contained" color="inherit"
sx={{borderRadius: '50px', fontSize: '3vw' }}>
Select All
</Button>
<Button onClick={handleUnselectAll} variant="contained" color="inherit"
sx={{borderRadius: '50px', fontSize: '3vw' }}>
Unselect All
</Button>
</div>
</div>
{data.map((element, index) => (
<div key={index} style={{display: "flex", flexDirection: "row",
justifyContent: "space-between", padding: '1vh 3vw', fontSize: '4vw',
alignItems: "center"}}>
<div>
<Button sx={{fontSize: '4vw', color: '#000'}} onClick={() => handleIncrementDecrement(index, -1)}>-</Button>
<span>{quantities[index].quantity}/{element.remaining}</span>
<Button sx={{fontSize: '4vw', color: '#000'}} onClick={() => handleIncrementDecrement(index, 1)}>+</Button>
<span> {element.item.name}</span>
</div>
<span>{element.item.price}$</span>
</div>
))}
</div>
<Box sx={{ padding: '3vh 5vw', backgroundColor: '#d9d9d9' }}>
<hr style={theme.hr} />
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<Typography variant="body1" component="span" fontWeight={400} fontSize={'3vw'}>
Total: ${getTotalPrice()}
</Typography>
<Button onClick={validatePayment} variant="contained" color="inherit"
sx={{ padding: '20px 50px', borderRadius: '50px', fontSize: '4vw' }}>
Paid
</Button>
</Box>
</Box>
</Box>
</Box>
)
}

export default TableBilling;

0 comments on commit 0273004

Please sign in to comment.