"use client" import Link from "next/link" import {useState} from "react" import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query" import {useSearchParams} from "next/navigation" import {ArrowLeft, MapPin, Trash2} from "lucide-react" import {toast} from "sonner" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog" import {EmptyStateWithBorder} from "@/components/layout/empty" import {ErrorInline} from "@/components/layout/error" import {LoadingStateWithBorder} from "@/components/layout/loading" import {Badge} from "@/components/ui/badge" import {Button} from "@/components/ui/button" import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow,} from "@/components/ui/table" import {OriginService} from "@/lib/services/openflare" import {formatDateTime} from "@/lib/utils" import {OriginEditorDialog} from "../components/origin-editor-dialog" export function OriginDetailPageClient() { const searchParams = useSearchParams() const queryClient = useQueryClient() const originId = searchParams.get("id")?.trim() ?? "" const parsedId = Number(originId) const enabled = originId !== "" && Number.isFinite(parsedId) const [editorOpen, setEditorOpen] = useState(false) const [deleteOpen, setDeleteOpen] = useState(false) const originQuery = useQuery({ queryKey: ["openflare", "origins", originId], queryFn: () => OriginService.get(parsedId), enabled, }) const deleteMutation = useMutation({ mutationFn: () => OriginService.delete(parsedId), onSuccess: async () => { toast.success("源站已删除") await queryClient.invalidateQueries({ queryKey: ["openflare", "origins"] }) window.location.href = "/origins" }, onError: (error) => { toast.error(error instanceof Error ? error.message : "删除失败") }, }) const origin = originQuery.data if (!enabled) { return (
) } if (originQuery.isLoading) { return (
) } if (originQuery.isError) { return (
void originQuery.refetch()} />
) } if (!origin) { return (
) } return (

{origin.name}

{origin.address}

绑定规则

{origin.route_count} 条规则

创建时间

{formatDateTime(origin.created_at)}

更新时间

{formatDateTime(origin.updated_at)}

备注

{origin.remark || "暂无备注"}

关联规则

展示当前源站作为主源站绑定的规则。

{origin.routes.length === 0 ? ( ) : ( 域名 源站地址 状态 更新时间 {origin.routes.map((route) => ( {route.domain} {route.origin_url} {route.enabled ? "启用" : "停用"} {formatDateTime(route.updated_at)} ))}
)}
void originQuery.refetch()} /> 删除源站 确认删除源站 {origin.name} 吗? 取消 deleteMutation.mutate()} > 确认删除
) }