Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions components/edit-category-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client';

import { useRouter } from 'next/navigation';
import { useState } from 'react';
import { useForm } from 'react-hook-form';

import { zodResolver } from '@hookform/resolvers/zod';
import { useQueryClient } from '@tanstack/react-query';
import { Loader2, Trash2 } from 'lucide-react';
import { toast } from 'sonner';
import { z } from 'zod/v4';

import { deleteCategory, updateCategory } from '@/prisma/services/category';
Expand Down Expand Up @@ -54,7 +54,6 @@
trigger: React.ReactNode;
categoryYearId?: string;
}) {
const router = useRouter();
const queryClient = useQueryClient();
const [open, setOpen] = useState<boolean>(false);
const [confirmDelete, setConfirmDelete] = useState<boolean>(false);
Expand All @@ -75,7 +74,10 @@
success: 'Spending category updated successfully',
error: 'Failed to update spending category',
},
onSuccess: () => {
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: ['categories-budget'],
});
setOpen(false);
},
});
Expand Down Expand Up @@ -111,7 +113,7 @@
onSuccess: () => {
setOpen(false);
// Navigate to the parent designation page
router.push(`/designation`);

Check failure on line 116 in components/edit-category-dialog.tsx

View workflow job for this annotation

GitHub Actions / run-tsc-check

Cannot find name 'router'.
},
});
}
Expand Down Expand Up @@ -150,7 +152,13 @@
</DialogHeader>

<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
<form
onSubmit={form.handleSubmit(onSubmit, (errors) => {
const first = Object.values(errors)[0];
if (first?.message) toast.error(String(first.message));
})}
className="space-y-8"
>
<FormField
control={form.control}
name="name"
Expand Down
Loading