Skip to content

Commit

Permalink
Introduced drone interface as well. Pulling much more accurate inform…
Browse files Browse the repository at this point in the history
…ation from backend to populate frontend with more dynamic content
  • Loading branch information
santoniriccardo committed Mar 1, 2022
1 parent d04929c commit 36fdd2c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/Customer/CustomerMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
} from '@mui/material';
import React, { useEffect } from 'react';
import { Link } from 'react-router-dom';
import DonutInterface from '../Donuts/Donut';
import { donutImages } from '../Donuts/donutImages';
import DonutInterface from '../Dronut/Donut';
import { donutImages } from '../Dronut/donutImages';

function Copyright() {
return (
Expand Down Expand Up @@ -50,7 +50,7 @@ function Menu() {
{/* End hero unit */}
<Grid container spacing={4}>
{donuts.map((donut) => (
<Grid item key={donut.id} xs={12} sm={6} md={4}>
<Grid item key={donut._id} xs={12} sm={6} md={4}>
<Card
sx={{
height: '100%',
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/Drone/Drone.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default interface DroneInterface {
_id: string;
battery_life: number;
critcal: false;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default interface DonutInterface {
id: string;
_id: string;
flavor: string;
price: number;
}
24 changes: 12 additions & 12 deletions frontend/src/components/Employee/Orders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ import TableRow from '@mui/material/TableRow';
import Typography from '@mui/material/Typography';
import { createStyles, makeStyles } from '@mui/styles';
import React, { useEffect } from 'react';
import DonutInterface from '../Donuts/Donut';
import { donutImages } from '../Donuts/donutImages';
import DonutInterface from '../Dronut/Donut';
import DroneInterface from '../Drone/Drone';
import { donutImages } from '../Dronut/donutImages';

// TODO (rsantoni) : Improve interface with all relevant details

export interface Order {
id: number;
_id: number;
first_name: string;
last_name: string;
drone: DroneInterface;
items: Array<DonutInterface>;
price: number;
}
Expand All @@ -45,7 +47,7 @@ export default function Orders() {

function handleCompleteOrder(id) {
console.log(id);
const newOrders = orders.filter((item) => item.id !== id);
const newOrders = orders.filter((item) => item._id !== id);
// const oldOrder = orders.filter((item) => item.id == id);
// const orderlength = oldOrder[0].items.length;
// console.log(oldOrder[0].items);
Expand Down Expand Up @@ -78,9 +80,10 @@ export default function Orders() {
console.log('items: ');
console.log(order.items);
let new_order: Order = {
id: order._id,
_id: order._id,
first_name: customerResponse.first_name,
last_name: customerResponse.last_name,
drone: order.drone,
items: order.items,
price: order.price
};
Expand Down Expand Up @@ -122,7 +125,7 @@ export default function Orders() {
<Table size="medium">
<TableBody>
{orders.map((row) => (
<TableRow key={row.id}>
<TableRow key={row._id}>
<Card>
<CardContent>
<Box
Expand All @@ -138,7 +141,7 @@ export default function Orders() {
<InputLabel>
Order for {row.first_name} {row.last_name}{' '}
</InputLabel>
<InputLabel>Drone Id : {row.id}</InputLabel>
<InputLabel>Drone Id : {row.drone._id}</InputLabel>
</Box>
<Grid lg={12} md={8} sm={12}>
<List>
Expand All @@ -150,10 +153,7 @@ export default function Orders() {
src={donutImages[donut.flavor]}
/>
</ListItemAvatar>
<ListItemText
primary={donut.flavor}
secondary={'Secondary text'}
/>
<ListItemText primary={donut.flavor} />
<ListItemText
style={{
display: 'flex',
Expand Down Expand Up @@ -194,7 +194,7 @@ export default function Orders() {
}}
variant="contained"
endIcon={<SendIcon />}
onClick={() => handleCompleteOrder(row.id)}
onClick={() => handleCompleteOrder(row._id)}
>
Order Packed
</Button>
Expand Down

0 comments on commit 36fdd2c

Please sign in to comment.