chore: build

This commit is contained in:
2026-06-13 14:23:23 +02:00
parent 6f699bea6a
commit 446b15d29c
13 changed files with 137 additions and 34 deletions
+7
View File
@@ -718,6 +718,9 @@ export const createCheckout = async (checkoutData: CheckoutData) => {
pay_currency: data.pay_currency as string | undefined,
price_amount: data.price_amount as number | undefined,
price_currency: data.price_currency as string | undefined,
referral_used: data.referral_used as number | undefined,
referral_balance: data.referral_balance as number | undefined,
client_order_number: data.client_order_number as number | undefined,
};
} catch (error) {
console.error("❌ [CHECKOUT] Erreur:", error);
@@ -2194,6 +2197,8 @@ export const claimMyReward = async (poolKey: string): Promise<{
success: boolean;
description?: string;
remaining_rewards?: number;
product_added?: boolean;
product_name?: string;
error?: string;
}> => {
const token = getAuthToken();
@@ -2213,6 +2218,8 @@ export const claimMyReward = async (poolKey: string): Promise<{
success: true,
description: data.description,
remaining_rewards: data.remaining_rewards,
product_added: data.product_added,
product_name: data.product_name,
};
} catch {
return { success: false, error: "Erreur de connexion" };
+1
View File
@@ -110,6 +110,7 @@ export interface CartItem {
quantity: number;
category: string;
image?: string;
is_reward?: boolean;
}
/**
+15 -2
View File
@@ -176,9 +176,22 @@ function Cart() {
{/* Infos */}
<div className="cart-row-info">
<p className="cart-row-name">{item.name_product}</p>
<p className="cart-row-name">
{item.name_product}
{item.is_reward && (
<span style={{ marginLeft: "6px", fontSize: "0.7rem", fontWeight: 700, color: "#f59e0b", background: "rgba(245,158,11,0.12)", borderRadius: "4px", padding: "1px 6px" }}>
🎁 Récompense
</span>
)}
</p>
<p className="cart-row-qty">{item.quantity}g</p>
<p className="cart-row-price">{item.price.toFixed(2)} </p>
<p className="cart-row-price">
{item.is_reward ? (
<span style={{ color: "#10b981", fontWeight: 700 }}>Offert</span>
) : (
`${item.price.toFixed(2)}`
)}
</p>
</div>
{/* Bouton supprimer */}
+2 -2
View File
@@ -355,13 +355,13 @@ function Checkout() {
// ✅ Préparer les données pour le modal
setConfirmationData({
command_id,
client_order_number: (response as Record<string, unknown>).client_order_number as number | undefined,
client_order_number: response.client_order_number,
assigned_to,
queue_info,
delivery_address: delivery_address || address,
arrivalTime,
total: frontendTotal,
referral_used: (response as Record<string, unknown>).referral_used as number | undefined,
referral_used: response.referral_used,
clientInfo: {
first_name: firstName,
last_name: lastName,
@@ -176,7 +176,10 @@ function ConsultationHistorique() {
const res = await claimMyReward(poolKey);
setClaimingPool(null);
if (res.success) {
setClaimFeedback({ pool: poolKey, type: "success", text: res.description || "Récompense réclamée !" });
const text = res.product_added && res.product_name
? `🎁 ${res.product_name} ajouté à votre panier ! Commandez au moins un produit pour en profiter.`
: res.description || "Récompense réclamée !";
setClaimFeedback({ pool: poolKey, type: "success", text });
getMyPointsRewards().then((r) => { if (r.success) setPointsRewards(r); });
} else {
setClaimFeedback({ pool: poolKey, type: "error", text: res.error || "Erreur" });
+21 -23
View File
@@ -73,30 +73,21 @@ interface ToastMessage {
* Somme des prix individuels (pas de multiplication)
*/
const getTotalAmount = (order: OrderWithTracking): number => {
// 1. Priorité: champ total stocké en DB
let gross = 0;
if (typeof order.total === "number" && order.total > 0) {
return order.total;
}
// 2. Fallback: total_prix
if (typeof order.total_prix === "number" && order.total_prix > 0) {
return order.total_prix;
}
// 3. Calcul depuis items (comme dans Checkout: somme des prix)
if (order.items && order.items.length > 0) {
const calculatedTotal = order.items.reduce((sum, item) => {
gross = order.total;
} else if (typeof order.total_prix === "number" && order.total_prix > 0) {
gross = order.total_prix;
} else if (order.items && order.items.length > 0) {
gross = order.items.reduce((sum, item) => {
const itemPrice = item.prix || item.price || 0;
return sum + itemPrice; // ✅ Somme simple (pas de × quantity)
return sum + itemPrice;
}, 0);
console.log(
`💰 [getTotalAmount] Commande ${order.id}: ${calculatedTotal.toFixed(2)}`,
);
return calculatedTotal;
}
return 0;
const referralUsed = typeof order.referral_used === "number" ? order.referral_used : 0;
return Math.max(0, gross - referralUsed);
};
const getClientInfo = (order: OrderWithTracking) => {
@@ -933,14 +924,21 @@ function SuiviLivraison() {
/>{" "}
Montant total
</h4>
{(order.referral_used ?? 0) > 0 && (
<p style={{ margin: "0 0 2px", fontSize: "0.85rem", color: "var(--text-muted)" }}>
Brut : {(order.total_prix ?? 0).toFixed(2)} €
</p>
)}
<p className="total-amount">
<strong>
{getTotalAmount(
order,
).toFixed(2)}{" "}
{getTotalAmount(order).toFixed(2)} €
</strong>
</p>
{(order.referral_used ?? 0) > 0 && (
<p style={{ margin: "4px 0 0", fontSize: "0.82rem", color: "#10b981", fontWeight: 500 }}>
— dont {(order.referral_used!).toFixed(2)} € parrainage déduit
</p>
)}
</div>
<div className="detail-section">