diff --git a/frontend-admin/src/screens/admin/OrdersScreen.tsx b/frontend-admin/src/screens/admin/OrdersScreen.tsx index 05d8dda8..b351d8db 100644 --- a/frontend-admin/src/screens/admin/OrdersScreen.tsx +++ b/frontend-admin/src/screens/admin/OrdersScreen.tsx @@ -22,6 +22,7 @@ import { notifyClientToDescend, confirmReceptionAdmin, deleteCommand, + deleteCommandItem, } from "../../api/api_admin"; import type { CommandResponse } from "../../api/types"; import type { AdminStackParamList } from "../../navigation/types"; @@ -179,6 +180,23 @@ export default function OrdersScreen() { ); }; + const handleDeleteItem = (commandId: number, itemId: number, itemName: string) => { + showConfirm( + "Supprimer l'article", + `Supprimer "${itemName}" de la commande #${commandId} ?`, + async () => { + try { + await deleteCommandItem(commandId, itemId); + const result = await getCommandItems(commandId); + setItemsModal((prev) => ({ ...prev, items: result.items })); + } catch (e: any) { + showError("Erreur", e.message); + } + }, + "Supprimer", + ); + }; + const handleDelete = (commandId: number) => { showConfirm( "Supprimer", @@ -345,6 +363,15 @@ export default function OrdersScreen() { color: colors.textMuted, fontSize: fontSize.xs, }, + itemRow: { + flexDirection: "row", + alignItems: "center", + justifyContent: "space-between", + }, + itemDeleteBtn: { + padding: spacing.xs, + marginLeft: spacing.s, + }, }), [colors], ); @@ -558,13 +585,33 @@ export default function OrdersScreen() { {itemsModal.items.map((item: any) => ( - - {item.produit ?? item.product_name} - - - Qté: {item.quantite ?? item.quantity} ·{" "} - {(item.prix ?? item.price)?.toFixed(2)} € - + + + + {item.produit ?? item.product_name} + + + Qté: {item.quantite ?? item.quantity} ·{" "} + {(item.prix ?? item.price)?.toFixed(2)} € + + + + handleDeleteItem( + itemsModal.commandId!, + item.id, + item.produit ?? item.product_name, + ) + } + > + + + ))}