chore: fix
This commit is contained in:
@@ -1220,8 +1220,8 @@ export const calculateOrderTotal = (order: Record<string, unknown>): number => {
|
||||
// Fallback: calculer depuis les items si présents
|
||||
if (Array.isArray(order.items) && order.items.length > 0) {
|
||||
return (order.items as Record<string, unknown>[]).reduce((sum: number, item) => {
|
||||
const price = item.prix || item.price || 0;
|
||||
const quantity = item.quantite || item.quantity || 1;
|
||||
const price = Number(item.prix || item.price || 0);
|
||||
const quantity = Number(item.quantite || item.quantity || 1);
|
||||
return sum + price * quantity;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@@ -113,21 +113,22 @@ export function CartProvider({ children }: { children: ReactNode }) {
|
||||
} else {
|
||||
// ✅ Transformer les items - quantity = grammes
|
||||
const items: CartItem[] = panierData.map((item) => {
|
||||
const category = (item.category || "autre")
|
||||
const category = String(item.category || "autre")
|
||||
.toLowerCase()
|
||||
.trim();
|
||||
|
||||
return {
|
||||
id: item.id,
|
||||
product_id: item.product_id,
|
||||
name_product:
|
||||
id: item.id as number,
|
||||
product_id: item.product_id as number,
|
||||
name_product: String(
|
||||
item.product_name ||
|
||||
item.name_product ||
|
||||
"Produit",
|
||||
price: item.price,
|
||||
quantity: item.quantity, // ✨ En grammes (5, 10, 25, etc.)
|
||||
),
|
||||
price: item.price as number,
|
||||
quantity: item.quantity as number,
|
||||
category: category,
|
||||
image: item.image, // Image sera gérée par Cart.tsx avec getProductById
|
||||
image: item.image as string | undefined,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ function Cart() {
|
||||
const res = await getProductById(item.product_id);
|
||||
if (res.success && res.data) {
|
||||
const p = res.data;
|
||||
const videoMedia = p.media?.find((m) => m && m.type === "video");
|
||||
const videoMedia = p.media?.find((m: { type: string; url?: string }) => m && m.type === "video");
|
||||
return {
|
||||
...item,
|
||||
image: getProductImage(p),
|
||||
|
||||
@@ -21,6 +21,7 @@ import type {
|
||||
ETAResponse,
|
||||
TrackingResponse,
|
||||
OrderDetail,
|
||||
OrderItem,
|
||||
CancelCommandResponse,
|
||||
} from "../../api/api_types";
|
||||
import Navbar from "../../components/Navbar";
|
||||
@@ -110,12 +111,11 @@ const getDeliveryAddress = (order: OrderWithTracking): string => {
|
||||
return order.delivery_address || order.adresse || "Non disponible";
|
||||
};
|
||||
|
||||
const formatOrderItem = (item: Record<string, unknown>) => {
|
||||
const formatOrderItem = (item: OrderItem) => {
|
||||
return {
|
||||
name:
|
||||
item.produit || item.product_name || item.name_product || "Produit",
|
||||
quantity: item.quantite || item.quantity || 0, // Grammes
|
||||
price: item.prix || item.price || 0,
|
||||
name: String(item.produit || item.product_name || item.name_product || "Produit"),
|
||||
quantity: Number(item.quantite || item.quantity || 0),
|
||||
price: Number(item.prix || item.price || 0),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -187,9 +187,9 @@ const calculateOrderPoints = (
|
||||
let excludedTotal = 0;
|
||||
|
||||
if (order.items && order.items.length > 0) {
|
||||
order.items.forEach((item: Record<string, unknown>) => {
|
||||
const cat = (item.category || "").toLowerCase();
|
||||
const itemPrice = item.prix || item.price || 0;
|
||||
order.items.forEach((item: OrderItem) => {
|
||||
const cat = String(item.category || "").toLowerCase();
|
||||
const itemPrice = Number(item.prix || item.price || 0);
|
||||
|
||||
if (cat.includes("gros") || cat.includes("semi")) {
|
||||
excludedTotal += itemPrice;
|
||||
@@ -464,7 +464,7 @@ function SuiviLivraison() {
|
||||
const pointsEarned =
|
||||
response.points_earned || selectedOrderPoints;
|
||||
const apiCategory =
|
||||
response.category || (response as Record<string, unknown> & { data?: { category?: string } }).data?.category || "";
|
||||
response.category || response.data?.category || "";
|
||||
|
||||
const displayCategory =
|
||||
apiCategory && apiCategory !== "total"
|
||||
@@ -898,7 +898,7 @@ function SuiviLivraison() {
|
||||
<div className="items-list">
|
||||
{order.items.map(
|
||||
(
|
||||
item: Record<string, unknown>,
|
||||
item: OrderItem,
|
||||
idx: number,
|
||||
) => {
|
||||
const formatted =
|
||||
|
||||
Reference in New Issue
Block a user