chore: build
This commit is contained in:
@@ -1161,13 +1161,22 @@ function PromotionProductPicker({
|
||||
});
|
||||
};
|
||||
|
||||
const updateProductQuantity = (id: number, quantity: number) => {
|
||||
onChange({
|
||||
...catConfig,
|
||||
products: catConfig.products.map((pq) =>
|
||||
pq.product_id === id ? { ...pq, quantity } : pq
|
||||
),
|
||||
});
|
||||
// Chaque produit peut être en promo sur plusieurs paliers de quantité en
|
||||
// même temps (ex: 1g ET 3g) — on ajoute/retire l'entrée {product_id,
|
||||
// quantity} correspondante plutôt que de remplacer une quantité unique.
|
||||
const toggleProductQuantity = (id: number, quantity: number) => {
|
||||
const exists = catConfig.products.some((pq) => pq.product_id === id && pq.quantity === quantity);
|
||||
if (exists) {
|
||||
onChange({
|
||||
...catConfig,
|
||||
products: catConfig.products.filter((pq) => !(pq.product_id === id && pq.quantity === quantity)),
|
||||
});
|
||||
} else {
|
||||
onChange({
|
||||
...catConfig,
|
||||
products: [...catConfig.products, { product_id: id, quantity }],
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -1227,8 +1236,9 @@ function PromotionProductPicker({
|
||||
</View>
|
||||
)}
|
||||
|
||||
{/* Mode "Sélection" : chaque produit choisi a sa propre quantité,
|
||||
via les paliers de prix réels du produit (pas de saisie libre) */}
|
||||
{/* Mode "Sélection" : chaque produit choisi peut être en promo sur
|
||||
plusieurs paliers de quantité à la fois, via les paliers de
|
||||
prix réels du produit (pas de saisie libre) */}
|
||||
{!catConfig.all_products && (
|
||||
<View style={{ gap: spacing.xs }}>
|
||||
{catProducts.length === 0 ? (
|
||||
@@ -1263,13 +1273,16 @@ function PromotionProductPicker({
|
||||
|
||||
{catConfig.products.length > 0 && (
|
||||
<View style={{ gap: spacing.s, marginTop: spacing.xs }}>
|
||||
{catConfig.products.map((pq) => {
|
||||
const prod = catProducts.find((p) => p.id === pq.product_id);
|
||||
{Array.from(new Set(catConfig.products.map((pq) => pq.product_id))).map((productId) => {
|
||||
const prod = catProducts.find((p) => p.id === productId);
|
||||
const tiers = (prod?.prices ?? []).filter((pr) => pr.active_price !== false);
|
||||
const selectedQuantities = catConfig.products
|
||||
.filter((pq) => pq.product_id === productId)
|
||||
.map((pq) => pq.quantity);
|
||||
return (
|
||||
<View key={pq.product_id} style={{ gap: 4 }}>
|
||||
<View key={productId} style={{ gap: 4 }}>
|
||||
<Text style={{ fontSize: 12, color: colors.textMuted }} numberOfLines={1}>
|
||||
{prod?.name ?? `Produit #${pq.product_id}`}
|
||||
{prod?.name ?? `Produit #${productId}`}
|
||||
</Text>
|
||||
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 4 }}>
|
||||
{tiers.length === 0 ? (
|
||||
@@ -1277,11 +1290,11 @@ function PromotionProductPicker({
|
||||
Aucun palier de prix actif pour ce produit
|
||||
</Text>
|
||||
) : tiers.map((tier) => {
|
||||
const isSel = pq.quantity === tier.quantity;
|
||||
const isSel = selectedQuantities.includes(tier.quantity);
|
||||
return (
|
||||
<TouchableOpacity
|
||||
key={tier.quantity}
|
||||
onPress={() => updateProductQuantity(pq.product_id, tier.quantity)}
|
||||
onPress={() => toggleProductQuantity(productId, tier.quantity)}
|
||||
style={{
|
||||
paddingHorizontal: spacing.s, paddingVertical: 3,
|
||||
borderRadius: borderRadius.sm, borderWidth: 1.5,
|
||||
|
||||
Reference in New Issue
Block a user