Add delete functionality for gifts in the dashboard

Introduced `handleDeleteGift` to delete a gift and refetch items after deletion. Connected the delete action to the dropdown menu, enabling users to remove gifts from the UI seamlessly. This enhances gift management capabilities on the dashboard.
This commit is contained in:
2025-03-19 08:23:26 +01:00
parent 1441843a55
commit 472a0b7834

View File

@@ -62,6 +62,7 @@ export default function GiftRegistryPage() {
refetchItems,
currentEventId,
setCurrentEventId,
deleteItem,
} = useGifts();
// State for modals
@@ -188,6 +189,11 @@ export default function GiftRegistryPage() {
setIsAddGiftModalOpen(true);
};
const handleDeleteGift = async (id: string) => {
await deleteItem(id);
await refetchItems(undefined, event?.id);
};
const handleEditGift = (giftId: string) => {
setSelectedGiftId(giftId);
setIsEditGiftModalOpen(true);
@@ -412,7 +418,10 @@ export default function GiftRegistryPage() {
<Edit className="h-4 w-4 mr-2" /> Edit
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem className="text-red-600">
<DropdownMenuItem
className="text-red-600"
onClick={() => handleDeleteGift(item.id)}
>
<Trash className="h-4 w-4 mr-2" /> Delete
</DropdownMenuItem>
</DropdownMenuContent>