-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
belinda-nextjs-03-231-modify-add-components-product-page (#232)
* refactor and add buttons * add store jwt and update buttons
- Loading branch information
1 parent
f3e075b
commit d239499
Showing
4 changed files
with
162 additions
and
109 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 was deleted.
Oops, something went wrong.
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,30 +1,115 @@ | ||
import React from "react"; | ||
import Image from "next/image"; | ||
import * as React from "react"; | ||
import Grid from "@mui/material/Grid"; | ||
import Paper from "@mui/material/Paper"; | ||
import Typography from "@mui/material/Typography"; | ||
import ButtonBase from "@mui/material/ButtonBase"; | ||
import { StaticImageData } from "next/image"; | ||
import Link from 'next/link'; | ||
import styles from '../app/category-page/[categoryId]/page.module.css'; // Import style from category page | ||
import { Stack, Button, Link } from "@mui/material"; | ||
import Image from "next/image"; | ||
import DeleteIcon from "@mui/icons-material/Delete"; | ||
import ArchiveIcon from "@mui/icons-material/Archive"; | ||
|
||
type ProductCardProps = { | ||
image: StaticImageData; | ||
categories: string[]; | ||
description: string; | ||
href: string; | ||
}; | ||
|
||
const ProductCard: React.FC<ProductCardProps> = ({ image, categories, description, href }) => { | ||
return ( | ||
<Link href={href} passHref> | ||
<div tabIndex={0} className={`product-card-container cursor-pointer px-4 py-2 border-4 border-gray-300 rounded-md hover:border-blue-500 focus:outline-none focus:border-blue-500 w-1/4 ${styles.product}`}> | ||
<Image src={image} alt={`Image for ${categories.join(', ')}`} width={200} height={200} layout="responsive" /> | ||
<div className="py-4" style={{ flexGrow: 1 }}> | ||
<p className="font-bold text-l mb-2 text-white h-8 truncate text-center">{categories.join(', ')}</p> | ||
<p className="text-sm text-gray-200 text-center" style={{ overflow: 'hidden', textOverflow: 'ellipsis', display: '-webkit-box', WebkitLineClamp: 3, WebkitBoxOrient: 'vertical' }}> | ||
{description} | ||
</p> | ||
</div> | ||
</div> | ||
</Link> | ||
); | ||
image: StaticImageData; | ||
categories: string[]; | ||
gender: string; | ||
sizeShoe: string; | ||
sizePantsWaist: string; | ||
sizePantsInseam: string; | ||
size: string; | ||
description: string; | ||
href: string; | ||
}; | ||
export default function ProductCard({ | ||
image, | ||
categories, | ||
gender, | ||
sizeShoe, | ||
size, | ||
sizePantsWaist, | ||
sizePantsInseam, | ||
description, | ||
href, | ||
}: ProductCardProps) { | ||
const [userRole, setUserRole] = React.useState(""); | ||
|
||
export default ProductCard; | ||
// Get user role from token | ||
React.useEffect(() => { | ||
const token = localStorage.getItem("token"); | ||
if (token) { | ||
const role = JSON.parse(atob(token.split(".")[1])).role; | ||
setUserRole(role); | ||
} | ||
}, []); | ||
return ( | ||
<Paper | ||
sx={{ | ||
p: 2, | ||
margin: "auto", | ||
maxWidth: 500, | ||
flexGrow: 1, | ||
backgroundColor: (theme) => | ||
theme.palette.mode === "dark" ? "#1A2027" : "#fff", | ||
}} | ||
> | ||
<Grid container spacing={2}> | ||
<Grid item> | ||
<ButtonBase> | ||
<Link href={href}> | ||
<Image | ||
src={image} | ||
alt="product image" | ||
style={{ width: 128, height: 128 }} | ||
/> | ||
</Link> | ||
</ButtonBase> | ||
</Grid> | ||
<Grid item xs={12} sm container> | ||
<Grid item xs container direction="column" spacing={2}> | ||
<Grid item xs> | ||
<Typography gutterBottom variant="subtitle1" component="div"> | ||
{categories} | ||
</Typography> | ||
<Typography variant="body2" color="text.secondary"> | ||
{gender} | ||
</Typography> | ||
<Typography variant="body2" color="text.secondary"> | ||
{sizeShoe} | ||
</Typography> | ||
<Typography variant="body2" color="text.secondary"> | ||
{size} | ||
</Typography> | ||
<Typography variant="body2" color="text.secondary"> | ||
{sizePantsWaist} | ||
</Typography> | ||
<Typography variant="body2" color="text.secondary"> | ||
{sizePantsInseam} | ||
</Typography> | ||
<Typography variant="body2" gutterBottom> | ||
{description} | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
<Stack direction="row" spacing={2} justifyContent="flex-end" mt={2}> | ||
<Button variant="contained" href={href} color="primary"> | ||
View | ||
</Button> | ||
{userRole === "admin" || | ||
(userRole === "creator" && ( | ||
<Stack direction="row" spacing={2}> | ||
{/* TODO: Add delete function to this button */} | ||
<Button variant="contained" startIcon={<DeleteIcon />} color="error"> | ||
Delete | ||
</Button> | ||
{/* TODO: Add archive function to this button */} | ||
<Button variant="contained" startIcon={<ArchiveIcon />} color="warning"> | ||
Archive | ||
</Button> | ||
</Stack> | ||
))} | ||
</Stack> | ||
</Paper> | ||
); | ||
} |