import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query" import { Skeleton, Table, Tooltip, notification, Modal, Input, Form, Switch } from "antd" import { Trash2, Pen, Computer, Zap } from "lucide-react" import { useState } from "react" import { deletePromptById, getAllPrompts, savePrompt, updatePrompt } from "~/libs/db" export const PromptBody = () => { const queryClient = useQueryClient() const [open, setOpen] = useState(false) const [openEdit, setOpenEdit] = useState(false) const [editId, setEditId] = useState("") const [createForm] = Form.useForm() const [editForm] = Form.useForm() const { data, status } = useQuery({ queryKey: ["fetchAllPrompts"], queryFn: getAllPrompts }) const { mutate: deletePrompt } = useMutation({ mutationFn: deletePromptById, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["fetchAllPrompts"] }) notification.success({ message: "Model Deleted", description: "Model has been deleted successfully" }) }, onError: (error) => { notification.error({ message: "Error", description: error?.message || "Something went wrong" }) } }) const { mutate: savePromptMutation, isPending: savePromptLoading } = useMutation({ mutationFn: savePrompt, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["fetchAllPrompts"] }) setOpen(false) createForm.resetFields() notification.success({ message: "Prompt Added", description: "Prompt has been added successfully" }) }, onError: (error) => { notification.error({ message: "Error", description: error?.message || "Something went wrong" }) } }) const { mutate: updatePromptMutation, isPending: isUpdatingPrompt } = useMutation({ mutationFn: async (data: any) => { return await updatePrompt({ ...data, id: editId }) }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["fetchAllPrompts"] }) setOpenEdit(false) editForm.resetFields() notification.success({ message: "Prompt Updated", description: "Prompt has been updated successfully" }) }, onError: (error) => { notification.error({ message: "Error", description: error?.message || "Something went wrong" }) } }) return (