|
| 1 | +import React from 'react'; |
| 2 | +import { makeStyles } from '@material-ui/core/styles'; |
| 3 | +import Typography from '@material-ui/core/Typography'; |
| 4 | +import List from '@material-ui/core/List'; |
| 5 | +import ListItem from '@material-ui/core/ListItem'; |
| 6 | +import ListItemText from '@material-ui/core/ListItemText'; |
| 7 | +import Grid from '@material-ui/core/Grid'; |
| 8 | +import { useHistory } from 'react-router-dom'; |
| 9 | + |
| 10 | +const useStyles = makeStyles((theme) => ({ |
| 11 | + listItem: { |
| 12 | + padding: theme.spacing(1, 0), |
| 13 | + }, |
| 14 | + total: { |
| 15 | + fontWeight: 700, |
| 16 | + }, |
| 17 | + title: { |
| 18 | + marginTop: theme.spacing(2), |
| 19 | + }, |
| 20 | +})); |
| 21 | + |
| 22 | +export default function Review({ userData }) { |
| 23 | + const history = useHistory(); |
| 24 | + console.log(history.location.state.checkedProducts); |
| 25 | + const products = history.location.state.checkedProducts; |
| 26 | + const totalPrice = products.reduce( |
| 27 | + (prevProduct, newProduct) => prevProduct.new_price + newProduct.new_price |
| 28 | + ); |
| 29 | + |
| 30 | + const classes = useStyles(); |
| 31 | + |
| 32 | + return ( |
| 33 | + <> |
| 34 | + <Typography variant="h6" gutterBottom> |
| 35 | + ملخص الطلبية |
| 36 | + </Typography> |
| 37 | + <List disablePadding> |
| 38 | + {products.map((product) => ( |
| 39 | + <ListItem className={classes.listItem} key={product.name}> |
| 40 | + <ListItemText primary={product.name} secondary={product.desc} /> |
| 41 | + <Typography variant="body2">{product.new_price}</Typography> |
| 42 | + </ListItem> |
| 43 | + ))} |
| 44 | + <ListItem className={classes.listItem}> |
| 45 | + <ListItemText primary="Total" /> |
| 46 | + <Typography variant="subtitle1" className={classes.total}> |
| 47 | + {totalPrice} |
| 48 | + </Typography> |
| 49 | + </ListItem> |
| 50 | + </List> |
| 51 | + </> |
| 52 | + ); |
| 53 | +} |
0 commit comments