"use client"; import { Button } from "@/components/ui/button"; import React, { useState } from "react"; import { Card, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { toast } from "@/components/ui/toaster"; import { Loading } from "@/components/dashboard/loading"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; // import { trpc } from "@/lib/trpc/client"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { revalidate } from "./actions"; type Props = { api: { id: string; workspaceId: string; name: string; }; }; const intent = "delete my api"; export const DeleteApi: React.FC = ({ api }) => { const [open, setOpen] = useState(false); const formSchema = z.object({ name: z.string().refine((v) => v === api.name, "Please confirm the API name"), intent: z.string().refine((v) => v === intent, "Please confirm your intent"), }); const form = useForm>({ // resolver: zodResolver(formSchema), }); const router = useRouter(); // const deleteApi = trpc.api.delete.useMutation({ // async onSuccess() { // toast.message("API Deleted", { // description: "Your API and all its keys has been deleted.", // }); // await revalidate(); // router.push("/app/apis"); // }, // onError(err) { // console.error(err); // toast.error(err.message); // }, // }); const isValid = form.watch("intent") === intent && form.watch("name") === api.name; async function onSubmit(_values: z.infer) { // deleteApi.mutate({ apiId: api.id }); } return ( <> Delete This api will be deleted, along with all of its keys and data. This action cannot be undone. setOpen(o)}> Delete API This api will be deleted, along with all of its keys. This action cannot be undone.
Warning This action is not reversible. Please be certain. ( {" "} Enter the API name{" "} {api.name} to continue: )} /> ( To verify, type{" "} delete my api below: )} />
); };