chore: build
Frontend Client - EAS Build / build (push) Successful in 1h29m52s
Frontend Web - Build & Lint / build (push) Successful in 15m56s

This commit is contained in:
Xor290
2026-10-18 12:18:58 +02:00
parent dba8b02de9
commit b65e2b41d8
5 changed files with 259 additions and 14 deletions
+23
View File
@@ -2292,6 +2292,29 @@ export const getMyPointsRewards = async (): Promise<{
}
};
export const swapMyRewardProduct = async (
productId: number,
): Promise<{ success: boolean; product_names?: string[]; error?: string }> => {
const token = getAuthToken();
if (!token) return { success: false, error: "Non authentifié" };
try {
const response = await fetch(`${API_URL}/points/swap`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({ product_id: productId }),
});
const data = await safeJson(response);
if (!response.ok)
return { success: false, error: data.error || "Erreur" };
return { success: true, product_names: data.product_names };
} catch {
return { success: false, error: "Erreur de connexion" };
}
};
export const submitLivreurRating = async (
orderId: number,
rating: number,
+69 -3
View File
@@ -2,11 +2,11 @@ import { useCart } from "../../context/useCart";
import Navbar from "../../components/Navbar";
import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { isUserAuthenticated, getProductById, getMediaUrl } from "../../api/api";
import type { Product } from "../../api/api";
import { isUserAuthenticated, getProductById, getMediaUrl, getMyPointsRewards, swapMyRewardProduct } from "../../api/api";
import type { Product, RewardItemConfig } from "../../api/api";
import { Trash2, ShoppingCart, AlertTriangle, Leaf, X } from "lucide-react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faGift } from "@fortawesome/free-solid-svg-icons";
import { faGift, faRepeat } from "@fortawesome/free-solid-svg-icons";
import "./Cart.css";
interface CartItemWithMedia {
@@ -30,6 +30,9 @@ function Cart() {
const [currentVideoUrl, setCurrentVideoUrl] = useState<string>("");
const [enrichedItems, setEnrichedItems] = useState<CartItemWithMedia[]>([]);
const [loadingMedia, setLoadingMedia] = useState(false);
const [swapTarget, setSwapTarget] = useState<CartItemWithMedia | null>(null);
const [swapChoices, setSwapChoices] = useState<RewardItemConfig[]>([]);
const [swapLoading, setSwapLoading] = useState(false);
useEffect(() => {
if (!isUserAuthenticated()) navigate("/login/client", { replace: true });
@@ -105,6 +108,28 @@ function Cart() {
await removeFromCart(itemId);
};
const handleOpenSwap = async (item: CartItemWithMedia) => {
setSwapTarget(item);
setSwapChoices([]);
const res = await getMyPointsRewards();
const pool = res.pools.find((p) =>
p.eligible_reward_items.some((it) => it.product_id === item.product_id),
);
setSwapChoices(
(pool?.eligible_reward_items || []).filter((it) => it.product_id !== item.product_id),
);
};
const handleSwapChoice = async (productId: number) => {
setSwapLoading(true);
const res = await swapMyRewardProduct(productId);
setSwapLoading(false);
if (res.success) {
setSwapTarget(null);
await refreshCart();
}
};
const handleCheckout = () => {
if (!isUserAuthenticated()) { navigate("/login/client", { replace: true }); return; }
navigate("/user/checkout");
@@ -200,6 +225,19 @@ function Cart() {
</p>
</div>
{/* Changer le produit de la récompense */}
{item.is_reward && (
<button
className="cart-row-remove"
onClick={() => handleOpenSwap(item)}
disabled={loading}
aria-label={`Changer le produit de la récompense`}
title="Changer de produit"
>
<FontAwesomeIcon icon={faRepeat} />
</button>
)}
{/* Bouton supprimer */}
<button
className="cart-row-remove"
@@ -214,6 +252,34 @@ function Cart() {
)}
</div>
{/* Modale de changement de produit récompense */}
{swapTarget && (
<div style={{ position: "fixed", inset: 0, background: "rgba(0,0,0,0.6)", display: "flex", alignItems: "center", justifyContent: "center", zIndex: 1000 }}>
<div style={{ background: "#1a1a1a", borderRadius: 12, padding: 20, maxWidth: 360, width: "90%" }}>
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 12 }}>
<p style={{ color: "#fff", fontWeight: 700 }}>Choisir un autre produit</p>
<button onClick={() => setSwapTarget(null)} style={{ background: "none", border: "none", color: "#fff", cursor: "pointer" }}>
<X size={18} />
</button>
</div>
{swapChoices.length === 0 ? (
<p style={{ color: "#999", fontSize: "0.85rem" }}>Aucun autre produit disponible pour cette récompense.</p>
) : (
swapChoices.map((choice) => (
<button
key={choice.product_id}
onClick={() => handleSwapChoice(choice.product_id)}
disabled={swapLoading}
style={{ display: "block", width: "100%", textAlign: "left", padding: "8px 10px", marginBottom: 6, background: "#2a2a2a", border: "none", borderRadius: 8, color: "#fff", cursor: "pointer" }}
>
{choice.product_name} {choice.price === 0 ? "(offert)" : `(${choice.price.toFixed(2)} €)`}
</button>
))
)}
</div>
</div>
)}
{/* Footer fixe */}
<div className="cart-footer">
<div className="cart-footer-total">