mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-19 14:04:08 +01:00
feat: implement confirmation dialog for deleting inventory items
This commit is contained in:
parent
b5daa06955
commit
6413032537
@ -1,63 +1,58 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { CalendarIcon } from "lucide-react";
|
||||
import { format } from "date-fns";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Calendar } from "@/components/ui/calendar";
|
||||
import {
|
||||
Dialog,
|
||||
DialogTrigger,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { cn } from "@/lib/utils";
|
||||
// import { deleteInventoryItem } from "@/api/inventory";
|
||||
// import type { DeleteInventoryItemInput } from "@/types";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function DeleteInventoryItem() {
|
||||
const [date, setDate] = useState<Date | undefined>();
|
||||
export function DeleteInventoryItem({ id }: { id: string }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [itemName, setItemName] = useState("");
|
||||
const [itemType, setItemType] = useState("");
|
||||
const [itemCategory, setItemCategory] = useState("");
|
||||
const [itemQuantity, setItemQuantity] = useState(0);
|
||||
const [itemUnit, setItemUnit] = useState("");
|
||||
|
||||
// const queryClient = useQueryClient();
|
||||
|
||||
const handleDelete = () => {
|
||||
// handle delete item
|
||||
console.log(`Item with ID ${id} deleted.`);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* trigger button for the confirmation dialog */}
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
type="submit"
|
||||
type="button"
|
||||
className="bg-red-500 hover:bg-red-800 text-white"
|
||||
onClick={handleDelete}
|
||||
>
|
||||
Delete Item
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogTitle>Confirm Deletion</DialogTitle>
|
||||
<DialogDescription>
|
||||
Are you sure you want to delete this item? This action cannot be
|
||||
undone.
|
||||
</DialogDescription>
|
||||
|
||||
{/* footer with confirm and cancel buttons */}
|
||||
<DialogFooter>
|
||||
<Button
|
||||
className="bg-gray-500 hover:bg-gray-700 text-white"
|
||||
onClick={() => setOpen(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
className="bg-red-600 hover:bg-red-800 text-white"
|
||||
onClick={handleDelete}
|
||||
>
|
||||
Confirm Delete
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -162,7 +162,9 @@ export default function InventoryPage() {
|
||||
{
|
||||
accessorKey: "delete",
|
||||
header: "Delete",
|
||||
cell: () => <DeleteInventoryItem />,
|
||||
cell: ({ row }: { row: { original: EditInventoryItemProps } }) => (
|
||||
<DeleteInventoryItem id={row.original.id} />
|
||||
),
|
||||
enableSorting: false,
|
||||
},
|
||||
];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user