"use client"; import { Button } from "@usesend/ui/src/button"; import { DeleteResource } from "~/components/DeleteResource"; import { api } from "~/trpc/react"; import { ContactBook } from "@prisma/client"; import { toast } from "@usesend/ui/src/toaster"; import { Trash2 } from "lucide-react"; import { z } from "zod"; export const DeleteContactBook: React.FC<{ contactBook: Partial & { id: string }; }> = ({ contactBook }) => { const deleteContactBookMutation = api.contacts.deleteContactBook.useMutation(); const utils = api.useUtils(); const contactBookSchema = z .object({ confirmation: z .string() .min(1, "Please type the contact book name to confirm"), }) .refine((data) => data.confirmation === contactBook.name, { message: "Contact book name does not match", path: ["confirmation"], }); async function onContactBookDelete( values: z.infer, ) { deleteContactBookMutation.mutate( { contactBookId: contactBook.id, }, { onSuccess: () => { utils.contacts.getContactBooks.invalidate(); toast.success(`Contact book deleted`); }, }, ); } return ( } confirmLabel="Delete Contact Book" /> ); }; export default DeleteContactBook;