forked from basir/next-amazona
-
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.
Video-09-Create-Product Details-Page
- Loading branch information
Showing
4 changed files
with
103 additions
and
6 deletions.
There are no files selected for viewing
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,17 +1,102 @@ | ||
import React from 'react'; | ||
import NextLink from 'next/link'; | ||
import Image from 'next/image'; | ||
import { | ||
Grid, | ||
Link, | ||
List, | ||
ListItem, | ||
Typography, | ||
Card, | ||
Button, | ||
} from '@material-ui/core'; | ||
import { useRouter } from 'next/router'; | ||
import data from '../../utils/data'; | ||
import Layout from '../../components/Layout'; | ||
import useStyles from '../../utils/styles'; | ||
|
||
export default function ProductScreen() { | ||
const classes = useStyles(); | ||
const router = useRouter(); | ||
const { slug } = router.query; | ||
const product = data.products.find((a) => a.slug === slug); | ||
if (!product) { | ||
return <div>Product Not Found</div>; | ||
} | ||
return ( | ||
<div> | ||
<h1>{product.name}</h1> | ||
</div> | ||
<Layout title={product.name} description={product.description}> | ||
<div className={classes.section}> | ||
<NextLink href="/" passHref> | ||
<Link> | ||
<Typography>back to products</Typography> | ||
</Link> | ||
</NextLink> | ||
</div> | ||
<Grid container spacing={1}> | ||
<Grid item md={6} xs={12}> | ||
<Image | ||
src={product.image} | ||
alt={product.name} | ||
width={640} | ||
height={640} | ||
layout="responsive" | ||
></Image> | ||
</Grid> | ||
<Grid item md={3} xs={12}> | ||
<List> | ||
<ListItem> | ||
<Typography component="h1">{product.name}</Typography> | ||
</ListItem> | ||
<ListItem> | ||
<Typography>Category: {product.category}</Typography> | ||
</ListItem> | ||
<ListItem> | ||
<Typography>Brand: {product.brand}</Typography> | ||
</ListItem> | ||
<ListItem> | ||
<Typography> | ||
Rating: {product.rating} stars ({product.numReviews} reviews) | ||
</Typography> | ||
</ListItem> | ||
<ListItem> | ||
<Typography> Description: {product.description}</Typography> | ||
</ListItem> | ||
</List> | ||
</Grid> | ||
<Grid item md={3} xs={12}> | ||
<Card> | ||
<List> | ||
<ListItem> | ||
<Grid container> | ||
<Grid item xs={6}> | ||
<Typography>Price</Typography> | ||
</Grid> | ||
<Grid item xs={6}> | ||
<Typography>${product.price}</Typography> | ||
</Grid> | ||
</Grid> | ||
</ListItem> | ||
<ListItem> | ||
<Grid container> | ||
<Grid item xs={6}> | ||
<Typography>Status</Typography> | ||
</Grid> | ||
<Grid item xs={6}> | ||
<Typography> | ||
{product.countInStock > 0 ? 'In stock' : 'Unavailable'} | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
</ListItem> | ||
<ListItem> | ||
<Button fullWidth variant="contained" color="primary"> | ||
Add to cart | ||
</Button> | ||
</ListItem> | ||
</List> | ||
</Card> | ||
</Grid> | ||
</Grid> | ||
</Layout> | ||
); | ||
} |
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