feat: add delete functionality to admin forms list and correct redirection paths

This commit is contained in:
2026-06-30 17:17:20 +07:00 Unverified
parent 14abb54108
commit 01e97bb6c6
2 changed files with 9 additions and 3 deletions
+2 -2
View File
@@ -54,6 +54,6 @@ export async function deleteForm(id: string) {
} }
await db.delete(forms).where(eq(forms.id, id)); await db.delete(forms).where(eq(forms.id, id));
revalidatePath("/form/admin"); revalidatePath("/admin/form");
redirect("/form/admin"); redirect("/admin/form");
} }
+7 -1
View File
@@ -11,8 +11,9 @@ import {
TableRow, TableRow,
} from "@/components/ui/table"; } from "@/components/ui/table";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import { Plus } from "lucide-react"; import { Plus, Trash2 } from "lucide-react";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { deleteForm } from "@/app/actions/form";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
@@ -83,6 +84,11 @@ export default async function AdminFormsPage() {
<Button variant="outline" asChild size="sm"> <Button variant="outline" asChild size="sm">
<Link href={`/admin/form/${form.id}/result`}>Results</Link> <Link href={`/admin/form/${form.id}/result`}>Results</Link>
</Button> </Button>
<form className="inline-block" action={deleteForm.bind(null, form.id)}>
<Button variant="outline" size="sm" type="submit" className="text-destructive hover:text-destructive">
<Trash2 className="h-4 w-4" />
</Button>
</form>
</TableCell> </TableCell>
</TableRow> </TableRow>
)) ))