diff --git a/mobile/src/api/api.ts b/mobile/src/api/api.ts
index b37f964d..908fa126 100644
--- a/mobile/src/api/api.ts
+++ b/mobile/src/api/api.ts
@@ -1071,6 +1071,19 @@ export const claimMyReward = async (
}
};
+export const swapMyRewardProduct = async (
+ productId: number,
+): Promise<{ success: boolean; product_names?: string[]; error?: string }> => {
+ try {
+ const { data } = await apiClient.put(`${V1}/points/swap`, {
+ product_id: productId,
+ });
+ return { success: true, product_names: data.product_names };
+ } catch (e: any) {
+ return { success: false, error: e?.response?.data?.error || "Erreur" };
+ }
+};
+
export const submitLivreurRating = async (
orderId: number,
rating: number,
diff --git a/mobile/src/context/CartContext.tsx b/mobile/src/context/CartContext.tsx
index 6591b697..1f08063c 100644
--- a/mobile/src/context/CartContext.tsx
+++ b/mobile/src/context/CartContext.tsx
@@ -23,6 +23,7 @@ export interface CartItem {
quantity: number;
category: string;
image?: string;
+ is_reward?: boolean;
}
interface ToastData {
@@ -89,6 +90,7 @@ export function CartProvider({ children }: { children: ReactNode }) {
quantity: item.quantity,
category: (item.category || "autre").toLowerCase().trim(),
image: item.image,
+ is_reward: item.is_reward,
}));
setCartItems(items);
} else {
diff --git a/mobile/src/screens/client/CartScreen.tsx b/mobile/src/screens/client/CartScreen.tsx
index e8bd8552..9c5b4323 100644
--- a/mobile/src/screens/client/CartScreen.tsx
+++ b/mobile/src/screens/client/CartScreen.tsx
@@ -12,7 +12,12 @@ import { useNavigation, useFocusEffect } from "@react-navigation/native";
import type { NativeStackNavigationProp } from "@react-navigation/native-stack";
import { Ionicons } from "@expo/vector-icons";
import { useCart } from "../../context/CartContext";
-import { getProductById } from "../../api/api";
+import {
+ getProductById,
+ getMyPointsRewards,
+ swapMyRewardProduct,
+} from "../../api/api";
+import type { RewardItemConfig } from "../../api/api";
import type { ClientStackParamList } from "../../navigation/types";
import LoadingSpinner from "../../components/ui/LoadingSpinner";
import Button from "../../components/ui/Button";
@@ -37,6 +42,7 @@ interface EnrichedItem {
price: number;
quantity: number;
category: string;
+ is_reward?: boolean;
imageUri?: string;
}
@@ -58,6 +64,9 @@ export default function CartScreen() {
const [loadingMedia, setLoadingMedia] = useState(false);
const [removeId, setRemoveId] = useState(null);
const [showClearModal, setShowClearModal] = useState(false);
+ const [swapTarget, setSwapTarget] = useState(null);
+ const [swapChoices, setSwapChoices] = useState([]);
+ const [swapLoading, setSwapLoading] = useState(false);
useFocusEffect(
useCallback(() => {
@@ -106,6 +115,32 @@ export default function CartScreen() {
const handleClear = () => setShowClearModal(true);
+ const handleOpenSwap = async (item: EnrichedItem) => {
+ 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 confirmClear = () => {
clearCart();
setShowClearModal(false);
@@ -210,6 +245,43 @@ export default function CartScreen() {
removeBtn: {
padding: spacing.m,
},
+ rewardBadge: {
+ flexDirection: "row",
+ alignItems: "center",
+ alignSelf: "flex-start",
+ gap: 4,
+ marginTop: 2,
+ paddingHorizontal: spacing.s,
+ paddingVertical: 2,
+ borderRadius: borderRadius.sm,
+ backgroundColor: "rgba(245,158,11,0.12)",
+ },
+ rewardBadgeText: {
+ fontSize: fontSize.xs,
+ fontWeight: fontWeight.semibold,
+ color: "#f59e0b",
+ },
+ itemActions: {
+ alignItems: "center",
+ },
+ swapChoice: {
+ flexDirection: "row",
+ justifyContent: "space-between",
+ alignItems: "center",
+ padding: spacing.m,
+ borderRadius: borderRadius.sm,
+ backgroundColor: colors.bgInput,
+ marginBottom: spacing.s,
+ },
+ swapChoiceText: {
+ color: colors.textPrimary,
+ fontSize: fontSize.sm,
+ },
+ swapEmptyText: {
+ color: colors.textMuted,
+ fontSize: fontSize.sm,
+ textAlign: "center",
+ },
modalBody: {
gap: spacing.l,
},
@@ -351,17 +423,49 @@ export default function CartScreen() {
{item.price.toFixed(2)} €
+ {(item as EnrichedItem).is_reward && (
+
+
+
+ Récompense
+
+
+ )}
+
+
+ {(item as EnrichedItem).is_reward && (
+
+ handleOpenSwap(
+ item as EnrichedItem,
+ )
+ }
+ style={styles.removeBtn}
+ >
+
+
+ )}
+ handleRemove(item.id)}
+ style={styles.removeBtn}
+ >
+
+
- handleRemove(item.id)}
- style={styles.removeBtn}
- >
-
-
)}
/>
@@ -463,6 +567,43 @@ export default function CartScreen() {
+
+ setSwapTarget(null)}
+ title="Choisir un autre produit"
+ icon="swap-horizontal-outline"
+ iconColor={colors.accent}
+ >
+
+ {swapChoices.length === 0 ? (
+
+ Aucun autre produit disponible pour cette
+ récompense.
+
+ ) : (
+ swapChoices.map((choice) => (
+
+ handleSwapChoice(choice.product_id)
+ }
+ >
+
+ {choice.product_name}
+
+
+ {choice.price === 0
+ ? "Offert"
+ : `${choice.price.toFixed(2)} €`}
+
+
+ ))
+ )}
+
+
);
}