feat: add Sync WHOIS button and API integration

This commit is contained in:
Bot
2026-04-16 23:08:56 +08:00
parent cd3b8fdf91
commit 825bcb08f4
2 changed files with 19 additions and 2 deletions
+5
View File
@@ -37,3 +37,8 @@ export const deleteDomain = (id: number) => {
export const updateDomain = (id: number, data: { is_public: boolean, billing_data: BillingDataMod }) => { export const updateDomain = (id: number, data: { is_public: boolean, billing_data: BillingDataMod }) => {
return fetcher<Domain>(FetcherMethod.PUT, `/api/v1/domains/${id}`, data) return fetcher<Domain>(FetcherMethod.PUT, `/api/v1/domains/${id}`, data)
} }
// 同步 Whois 信息
export const syncDomainWHOIS = (id: number) => {
return fetcher<Domain>(FetcherMethod.POST, `/api/v1/domains/${id}/sync`)
}
+14 -2
View File
@@ -1,7 +1,7 @@
// src/routes/domain.tsx (最终 Bug 修复版) // src/routes/domain.tsx (最终 Bug 修复版)
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { PlusCircle, RefreshCw, MoreVertical, Trash2, Edit, CheckCircle } from 'lucide-react' import { PlusCircle, RefreshCw, MoreVertical, Trash2, Edit, CheckCircle, RefreshCcw } from 'lucide-react'
// 导入 shadcn/ui 组件 // 导入 shadcn/ui 组件
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
@@ -19,7 +19,7 @@ import { toast } from 'sonner'
// 导入 API 类型和函数 // 导入 API 类型和函数
import type { Domain, BillingDataMod } from '@/types/api' import type { Domain, BillingDataMod } from '@/types/api'
import { useDomainList, addDomain, verifyDomain, deleteDomain, updateDomain } from '@/api/domain' import { useDomainList, addDomain, verifyDomain, deleteDomain, updateDomain, syncDomainWHOIS } from '@/api/domain'
import useSWR from 'swr' import useSWR from 'swr'
@@ -83,6 +83,17 @@ export default function DomainPage() {
} }
} }
const handleSyncWhois = async (domainId: number) => {
const loadingToast = toast.loading('正在同步 Whois 信息...')
try {
await syncDomainWHOIS(domainId)
toast.success('同步成功', { id: loadingToast, description: '域名 Whois 信息已更新。' })
mutate()
} catch (err) {
toast.error('同步失败', { id: loadingToast, description: (err as Error).message })
}
}
const handleDelete = async (domainId: number, domainName: string) => { const handleDelete = async (domainId: number, domainName: string) => {
if (window.confirm(`确定要删除域名 ${domainName} 吗?`)) { if (window.confirm(`确定要删除域名 ${domainName} 吗?`)) {
try { try {
@@ -213,6 +224,7 @@ export default function DomainPage() {
<DropdownMenuTrigger asChild><Button variant="ghost" size="icon"><MoreVertical className="h-4 w-4" /></Button></DropdownMenuTrigger> <DropdownMenuTrigger asChild><Button variant="ghost" size="icon"><MoreVertical className="h-4 w-4" /></Button></DropdownMenuTrigger>
<DropdownMenuContent> <DropdownMenuContent>
{domain.Status === 'pending' && (<DropdownMenuItem onClick={() => handleVerify(domain.ID)}><CheckCircle className="mr-2 h-4 w-4" /> </DropdownMenuItem>)} {domain.Status === 'pending' && (<DropdownMenuItem onClick={() => handleVerify(domain.ID)}><CheckCircle className="mr-2 h-4 w-4" /> </DropdownMenuItem>)}
{domain.Status === 'verified' && (<DropdownMenuItem onClick={() => handleSyncWhois(domain.ID)}><RefreshCcw className="mr-2 h-4 w-4" /> Whois</DropdownMenuItem>)}
<DropdownMenuItem onClick={() => handleEditClick(domain)}><Edit className="mr-2 h-4 w-4" /> </DropdownMenuItem> <DropdownMenuItem onClick={() => handleEditClick(domain)}><Edit className="mr-2 h-4 w-4" /> </DropdownMenuItem>
<DropdownMenuItem className="text-red-600" onClick={() => handleDelete(domain.ID, domain.Domain)}><Trash2 className="mr-2 h-4 w-4" /> </DropdownMenuItem> <DropdownMenuItem className="text-red-600" onClick={() => handleDelete(domain.ID, domain.Domain)}><Trash2 className="mr-2 h-4 w-4" /> </DropdownMenuItem>
</DropdownMenuContent> </DropdownMenuContent>