import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query" import { Form, Input, Skeleton, Table, Tooltip, message } from "antd" import { Trash2 } from "lucide-react" import { SaveButton } from "~components/Common/SaveButton" import { deleteWebshare, getAllWebshares, getUserId } from "~libs/db" import { getPageShareUrl, setPageShareUrl } from "~services/ollama" import { verifyPageShareURL } from "~utils/verify-page-share" export const OptionShareBody = () => { const queryClient = useQueryClient() const { status, data } = useQuery({ queryKey: ["fetchShareInfo"], queryFn: async () => { const [url, shares] = await Promise.all([ getPageShareUrl(), getAllWebshares() ]) return { url, shares } } }) const onSubmit = async (values: { url: string }) => { const isOk = await verifyPageShareURL(values.url) if (isOk) { await setPageShareUrl(values.url) } } const onDelete = async ({ api_url, share_id, id }: { id: string share_id: string api_url: string }) => { const owner_id = await getUserId() const res = await fetch(`${api_url}/api/v1/share/delete`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ share_id, owner_id }) }) if (!res.ok) throw new Error("Failed to delete share link") await deleteWebshare(id) return "ok" } const { mutate: updatePageShareUrl, isPending: isUpdatePending } = useMutation({ mutationFn: onSubmit, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["fetchShareInfo"] }) message.success("Page Share URL updated successfully") }, onError: (error) => { message.error(error?.message || "Failed to update Page Share URL") } }) const { mutate: deleteMutation } = useMutation({ mutationFn: onDelete, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["fetchShareInfo"] }) message.success("Webshare deleted successfully") }, onError: (error) => { message.error(error?.message || "Failed to delete Webshare") } }) return (