update
This commit is contained in:
@@ -366,6 +366,7 @@ export interface TrackingResponse {
|
||||
export interface ProductPrice {
|
||||
quantity: number;
|
||||
price: number;
|
||||
active_price?: boolean;
|
||||
}
|
||||
export interface Product {
|
||||
id: number;
|
||||
|
||||
@@ -70,10 +70,9 @@ function UserAccueil() {
|
||||
};
|
||||
|
||||
const getProductPrice = (product: Product): number => {
|
||||
if (!product.prices || product.prices.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
return product.prices[0]?.price || 0;
|
||||
const activePrices = product.prices?.filter(p => p.active_price !== false);
|
||||
if (!activePrices || activePrices.length === 0) return 0;
|
||||
return activePrices[0].price;
|
||||
};
|
||||
const hasProductVideo = (product: Product): boolean => {
|
||||
if (!product.media || product.media.length === 0) {
|
||||
@@ -210,7 +209,7 @@ function UserAccueil() {
|
||||
image={getProductImage(product)}
|
||||
stock={product.stock}
|
||||
category={product.category}
|
||||
prices={product.prices}
|
||||
prices={product.prices?.filter(p => p.active_price !== false)}
|
||||
hasVideo={hasProductVideo(product)}
|
||||
videoUrl={getProductVideoUrl(product)}
|
||||
categoryColor={
|
||||
|
||||
@@ -86,12 +86,15 @@ function ProductDetail() {
|
||||
const fixedProduct = {
|
||||
...response.data,
|
||||
prices:
|
||||
response.data.prices?.map(
|
||||
(p: { quantity: number; price: number }) => ({
|
||||
quantity: parseFloat(String(p.quantity)),
|
||||
price: parseFloat(String(p.price)),
|
||||
}),
|
||||
) || [],
|
||||
response.data.prices
|
||||
?.filter((p: { quantity: number; price: number; active_price?: boolean }) => p.active_price !== false)
|
||||
.map(
|
||||
(p: { quantity: number; price: number; active_price?: boolean }) => ({
|
||||
quantity: parseFloat(String(p.quantity)),
|
||||
price: parseFloat(String(p.price)),
|
||||
active_price: p.active_price,
|
||||
}),
|
||||
) || [],
|
||||
};
|
||||
|
||||
setProduct(fixedProduct);
|
||||
|
||||
Reference in New Issue
Block a user