"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"; import { Modal, message } from "antd"; import { deleteStaff } from "@/lib/http/staff"; type Props = { api: { id: string; workspaceId: string; name: string; }; }; const intent = "delete my api"; const { confirm } = Modal; /** * 删除节点 * @param selectedRows */ const handleRemove = async (id: number) => { const hide = message.loading('正在删除员工'); console.log("---删除员工--->", id) try { await deleteStaff(Number(id)); hide(); message.success('删除成功,即将刷新'); return true; } catch (error) { hide(); message.error('删除失败,请重试'); return false; } }; export const DeleteApi: React.FC = ({ api }) => { const [open, setOpen] = useState(false); const showDeleteConfirm = () => { confirm({ title: '是否删除员工?', content: '删除的记录不能恢复,请确认!', rootClassName: "bg-[#fff]", onOk() { const id = Number(api.id) handleRemove(id).then(() => { window.location.href = `/manage` }); }, onCancel() { }, }); }; 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 该 员工客服 及其所有密钥和数据将被删除。此操作无法撤消。 setOpen(o)}> 删除员工 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: )} />
); };