-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
268 additions
and
27 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { Container, Typography, Button, Grid } from '@mui/material'; | ||
import CartItem from './CartItem/CartItem'; | ||
import { Link } from "react-router-dom"; | ||
|
||
import useStyles from './styles'; | ||
|
||
const Cart = ({ cart, handleUpdateCartQty, handleRemoveFromCart, handleEmptyCart }) => { | ||
|
||
const classes = useStyles(); | ||
|
||
const emptyCart = () => ( | ||
<Typography align='center' variant="subtitle1">You have no item in your shopping cart. | ||
<Link to="/" className={ classes.link }>Please add some items.</Link> | ||
</Typography> | ||
); | ||
|
||
const filledCart = () => ( | ||
<> | ||
<Grid container spacing={ 2 }> | ||
{ cart.line_items.map((item) => ( | ||
<Grid item xs={ 12 } md={ 6 } sm={ 4 } key={ item.id }> | ||
<CartItem item={ item } onUpdateCart={ handleUpdateCartQty } onRemoveFromCart={ handleRemoveFromCart } /> | ||
</Grid> | ||
)) } | ||
</Grid> | ||
<div className={ classes.cardDetails }> | ||
<Typography variant="h4"> | ||
Subtotal: { cart.subtotal.formatted_with_symbol } | ||
</Typography> | ||
<div> | ||
<Button className={ classes.emptyButton } size='large' type='button' variant='contained' color='secondary' onClick={ handleEmptyCart }>Empty Cart</Button> | ||
<Button component={ Link } to="/checkout" className={ classes.checkoutButton } size='large' type='button' variant='contained' color='primary'>Checkout</Button> | ||
</div> | ||
</div> | ||
</> | ||
|
||
); | ||
|
||
if (!cart.line_items) return "Loading..." | ||
|
||
return ( | ||
<Container> | ||
<div className={ classes.toolbar } /> | ||
<Typography className={ classes.title } variant='h4' gutterBottom>Your Shopping Cart</Typography> | ||
{ !cart.line_items.length ? emptyCart() : filledCart() } | ||
</Container> | ||
) | ||
} | ||
|
||
export default Cart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import { CardActions, Card, CardContent, CardMedia, Typography, Button } from '@mui/material'; | ||
|
||
import useStyles from './styles'; | ||
|
||
const CartItem = ({ item, onUpdateCart, onRemoveFromCart }) => { | ||
const classes = useStyles(); | ||
return ( | ||
<Card className="cart-item"> | ||
<CardMedia image={ item.image.url } alt={ item.name } className={ classes.media } /> | ||
<CardContent className={ classes.cardContent }> | ||
<Typography variant='h5'>{ item.name }</Typography> | ||
<Typography variant='h5'>{ item.line_total.formatted_with_symbol }</Typography> | ||
</CardContent> | ||
<CardActions className={ classes.cardActions }> | ||
<div className={ classes.buttons }> | ||
<Button type='button' size='small' onClick={ () => onUpdateCart(item.id, item.quantity - 1) }>-</Button> | ||
<Typography>{ item.quantity }</Typography> | ||
<Button type='button' size='small' onClick={ () => onUpdateCart(item.id, item.quantity + 1) }>+</Button> | ||
</div> | ||
<Button variant='contained' type='button' color='secondary' onClick={ () => onRemoveFromCart(item.id) }>Remove</Button> | ||
</CardActions> | ||
</Card> | ||
) | ||
} | ||
|
||
export default CartItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { makeStyles } from "@mui/styles"; | ||
|
||
export default makeStyles(() => ({ | ||
media: { | ||
height: 260, | ||
}, | ||
cardContent: { | ||
display: "flex", | ||
justifyContent: "space-between", | ||
}, | ||
cardActions: { | ||
justifyContent: "space-between", | ||
}, | ||
buttons: { | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,30 @@ | ||
import { makeStyles } from "@mui/styles"; | ||
|
||
export default makeStyles(() => ({})); | ||
export default makeStyles((theme) => ({ | ||
toolbar: theme.mixins.toolbar, | ||
title: { | ||
paddingTop: "5%", | ||
textAlign: "center", | ||
}, | ||
emptyButton: { | ||
minWidth: "150px", | ||
[theme.breakpoints.down("xs")]: { | ||
marginBottom: "5px", | ||
}, | ||
[theme.breakpoints.up("xs")]: { | ||
marginRight: "20px", | ||
}, | ||
}, | ||
checkoutButton: { | ||
minWidth: "150px", | ||
}, | ||
link: { | ||
textDecoration: "none", | ||
}, | ||
cardDetails: { | ||
display: "flex", | ||
marginTop: "10%", | ||
width: "100%", | ||
justifyContent: "space-between", | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as Navbar } from "./Navbar/Navbar"; | ||
export { default as Products } from "./Products/Products"; | ||
export { default as Cart } from "./Cart/Cart"; | ||
export { default as Checkout } from "./CheckoutForm/Checkout/Checkout"; |