({
categories,
}: {
categories: {
id: string;
category: string;
}[];
})
| 17 | import { useRouter } from "next/navigation"; |
| 18 | |
| 19 | const EditCategories = ({ |
| 20 | categories, |
| 21 | }: { |
| 22 | categories: { |
| 23 | id: string; |
| 24 | category: string; |
| 25 | }[]; |
| 26 | }) => { |
| 27 | const router = useRouter(); |
| 28 | const [newCategory, setNewCategory] = useState<string>(""); |
| 29 | async function handleAddCategory() { |
| 30 | if (!newCategory) { |
| 31 | toast({ |
| 32 | title: "Category cannot be empty", |
| 33 | description: "Please enter a category", |
| 34 | }); |
| 35 | return; |
| 36 | } |
| 37 | toast({ |
| 38 | title: "Adding category", |
| 39 | }); |
| 40 | try { |
| 41 | await addCategory(newCategory); |
| 42 | router.refresh(); |
| 43 | toast({ |
| 44 | title: "Category added", |
| 45 | description: `Category ${newCategory} added`, |
| 46 | }); |
| 47 | } catch (error) { |
| 48 | toast({ |
| 49 | title: "Error adding category", |
| 50 | }); |
| 51 | } |
| 52 | } |
| 53 | async function handleDeleteCategory(categoryId: string) { |
| 54 | toast({ |
| 55 | title: "Deleting category", |
| 56 | }); |
| 57 | try { |
| 58 | await deleteCategory(categoryId); |
| 59 | router.refresh(); |
| 60 | toast({ |
| 61 | title: "Category deleted", |
| 62 | }); |
| 63 | } catch (error) { |
| 64 | toast({ |
| 65 | title: "Error deleting category", |
| 66 | }); |
| 67 | } |
| 68 | } |
| 69 | return ( |
| 70 | <Dialog> |
| 71 | <DialogTrigger asChild> |
| 72 | <Button variant="outline">Edit categories</Button> |
| 73 | </DialogTrigger> |
| 74 | <DialogContent className="sm:max-w-[425px]"> |
| 75 | <div className="grid gap-4 py-4"> |
| 76 | {categories.map((category) => ( |
nothing calls this directly
no test coverage detected