Update Product type and enhance ProductItem component
Modified the `Product` type to make `status` and `coverUrl` optional, and added a new `version` property for improved flexibility. Updated the `getProducts` function to reflect these changes. In the `ProductItem` component, added a new `Label` to display the product's version and ensured a default image is used if `coverUrl` is not provided. Updated rendering logic to conditionally show both status and version.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
export type Product = {
|
||||
id: string;
|
||||
name: string;
|
||||
price?: number;
|
||||
status: string;
|
||||
coverUrl: string;
|
||||
colors?: string[];
|
||||
priceSale?: number;
|
||||
id: string;
|
||||
name: string;
|
||||
price?: number;
|
||||
status?: string;
|
||||
version?: string;
|
||||
coverUrl?: string;
|
||||
colors?: string[];
|
||||
priceSale?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -18,14 +19,12 @@ export function getProducts(): Promise<Product[]> {
|
||||
{
|
||||
id: '1',
|
||||
name: "User Manager",
|
||||
coverUrl: "/assets/images/product/product-default.webp",
|
||||
status: "1.0.0"
|
||||
version: "1.0.0"
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
name: "Envelope Generator",
|
||||
coverUrl: "/assets/images/product/product-default.webp",
|
||||
status: "1.0.0"
|
||||
version: "1.0.0"
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -33,7 +33,23 @@ export function ProductItem({ product }: { product: Product }) {
|
||||
</Label>
|
||||
);
|
||||
|
||||
const [imgSrc, setImgSrc] = useState(product.coverUrl);
|
||||
const renderVersion = (
|
||||
<Label
|
||||
variant="inverted"
|
||||
color='info'
|
||||
sx={{
|
||||
zIndex: 9,
|
||||
top: 16,
|
||||
right: 16,
|
||||
position: 'absolute',
|
||||
textTransform: 'uppercase',
|
||||
}}
|
||||
>
|
||||
{product.version}
|
||||
</Label>
|
||||
);
|
||||
|
||||
const [imgSrc, setImgSrc] = useState(product.coverUrl ?? "/assets/images/product/product-default.webp");
|
||||
|
||||
const renderImg = (
|
||||
<Box
|
||||
@@ -72,6 +88,7 @@ export function ProductItem({ product }: { product: Product }) {
|
||||
<Card>
|
||||
<Box sx={{ pt: '100%', position: 'relative' }}>
|
||||
{product.status && renderStatus}
|
||||
{product.version && renderVersion}
|
||||
{renderImg}
|
||||
</Box>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user