chore: build
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<number | null>(null);
|
||||
const [showClearModal, setShowClearModal] = useState(false);
|
||||
const [swapTarget, setSwapTarget] = useState<EnrichedItem | null>(null);
|
||||
const [swapChoices, setSwapChoices] = useState<RewardItemConfig[]>([]);
|
||||
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() {
|
||||
<Text style={styles.itemPrice}>
|
||||
{item.price.toFixed(2)} €
|
||||
</Text>
|
||||
{(item as EnrichedItem).is_reward && (
|
||||
<View style={styles.rewardBadge}>
|
||||
<Ionicons
|
||||
name="gift-outline"
|
||||
size={10}
|
||||
color="#f59e0b"
|
||||
/>
|
||||
<Text
|
||||
style={styles.rewardBadgeText}
|
||||
>
|
||||
Récompense
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
<View style={styles.itemActions}>
|
||||
{(item as EnrichedItem).is_reward && (
|
||||
<TouchableOpacity
|
||||
onPress={() =>
|
||||
handleOpenSwap(
|
||||
item as EnrichedItem,
|
||||
)
|
||||
}
|
||||
style={styles.removeBtn}
|
||||
>
|
||||
<Ionicons
|
||||
name="swap-horizontal-outline"
|
||||
size={20}
|
||||
color={colors.accent}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
<TouchableOpacity
|
||||
onPress={() => handleRemove(item.id)}
|
||||
style={styles.removeBtn}
|
||||
>
|
||||
<Ionicons
|
||||
name="trash-outline"
|
||||
size={20}
|
||||
color={colors.danger}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
<TouchableOpacity
|
||||
onPress={() => handleRemove(item.id)}
|
||||
style={styles.removeBtn}
|
||||
>
|
||||
<Ionicons
|
||||
name="trash-outline"
|
||||
size={20}
|
||||
color={colors.danger}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
)}
|
||||
/>
|
||||
@@ -463,6 +567,43 @@ export default function CartScreen() {
|
||||
</View>
|
||||
</View>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
visible={swapTarget !== null}
|
||||
onClose={() => setSwapTarget(null)}
|
||||
title="Choisir un autre produit"
|
||||
icon="swap-horizontal-outline"
|
||||
iconColor={colors.accent}
|
||||
>
|
||||
<View style={styles.modalBody}>
|
||||
{swapChoices.length === 0 ? (
|
||||
<Text style={styles.swapEmptyText}>
|
||||
Aucun autre produit disponible pour cette
|
||||
récompense.
|
||||
</Text>
|
||||
) : (
|
||||
swapChoices.map((choice) => (
|
||||
<TouchableOpacity
|
||||
key={choice.product_id}
|
||||
style={styles.swapChoice}
|
||||
disabled={swapLoading}
|
||||
onPress={() =>
|
||||
handleSwapChoice(choice.product_id)
|
||||
}
|
||||
>
|
||||
<Text style={styles.swapChoiceText}>
|
||||
{choice.product_name}
|
||||
</Text>
|
||||
<Text style={styles.swapChoiceText}>
|
||||
{choice.price === 0
|
||||
? "Offert"
|
||||
: `${choice.price.toFixed(2)} €`}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
))
|
||||
)}
|
||||
</View>
|
||||
</Modal>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user