From 0acdfdb1eba2c9595cd9e4722f5d4e9ef4213bbd Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 2 Jul 2025 17:07:06 +0200 Subject: [PATCH] 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. --- .../dd-hub-react/src/api/product-service.ts | 21 +++++++++---------- .../src/sections/product/product-item.tsx | 19 ++++++++++++++++- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/client/dd-hub-react/src/api/product-service.ts b/src/client/dd-hub-react/src/api/product-service.ts index f55d3aa..ed57109 100644 --- a/src/client/dd-hub-react/src/api/product-service.ts +++ b/src/client/dd-hub-react/src/api/product-service.ts @@ -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 { { 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" } ]); } \ No newline at end of file diff --git a/src/client/dd-hub-react/src/sections/product/product-item.tsx b/src/client/dd-hub-react/src/sections/product/product-item.tsx index 492d724..7225ad6 100644 --- a/src/client/dd-hub-react/src/sections/product/product-item.tsx +++ b/src/client/dd-hub-react/src/sections/product/product-item.tsx @@ -33,7 +33,23 @@ export function ProductItem({ product }: { product: Product }) { ); - const [imgSrc, setImgSrc] = useState(product.coverUrl); + const renderVersion = ( + + ); + + const [imgSrc, setImgSrc] = useState(product.coverUrl ?? "/assets/images/product/product-default.webp"); const renderImg = ( {product.status && renderStatus} + {product.version && renderVersion} {renderImg}