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:
2025-07-02 17:07:06 +02:00
parent 3d49f32175
commit 0acdfdb1eb
2 changed files with 28 additions and 12 deletions

View File

@@ -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"
}
]);
}

View File

@@ -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>