清除冗余代码
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { Table, TableHeader, TableBody, TableHead, TableRow, TableCell } from '@/components/ui/table'
|
|
||||||
import { getCityNodeCount, type CityNode } from '@/actions/stats'
|
import { getCityNodeCount, type CityNode } from '@/actions/stats'
|
||||||
import { Page } from '@/components/page'
|
import { Page } from '@/components/page'
|
||||||
import { DataTable } from '@/components/data-table'
|
import { DataTable } from '@/components/data-table'
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { Pagination } from '@/components/ui/pagination'
|
import { Pagination } from '@/components/ui/pagination'
|
||||||
import { Table, TableHeader, TableBody, TableHead, TableRow, TableCell } from '@/components/ui/table'
|
|
||||||
import { getEdgeNodes, type Edge } from '@/actions/stats'
|
import { getEdgeNodes, type Edge } from '@/actions/stats'
|
||||||
import { zodResolver } from '@hookform/resolvers/zod'
|
import { zodResolver } from '@hookform/resolvers/zod'
|
||||||
import { useForm } from 'react-hook-form'
|
import { useForm } from 'react-hook-form'
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { useEffect, useState, Suspense, useCallback } from 'react'
|
import { useEffect, useState, Suspense, useCallback } from 'react'
|
||||||
import { Table, TableHeader, TableBody, TableHead, TableRow, TableCell } from '@/components/ui/table'
|
|
||||||
import { getGatewayInfo, getGatewayConfig, type GatewayConfig, type GatewayInfo } from '@/actions/stats'
|
import { getGatewayInfo, getGatewayConfig, type GatewayConfig, type GatewayInfo } from '@/actions/stats'
|
||||||
import { Pagination } from '@/components/ui/pagination'
|
import { Pagination } from '@/components/ui/pagination'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/com
|
|||||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
|
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
|
||||||
import { UserIcon, LockIcon, SearchIcon, Trash2Icon, PlusIcon, XIcon } from 'lucide-react'
|
import { UserIcon, LockIcon, SearchIcon, Trash2Icon, PlusIcon, XIcon } from 'lucide-react'
|
||||||
import { toast, Toaster } from 'sonner'
|
import { toast, Toaster } from 'sonner'
|
||||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
|
||||||
import { findUsers, createUser, removeUser } from '@/actions/user'
|
import { findUsers, createUser, removeUser } from '@/actions/user'
|
||||||
import { Page } from '@/components/page'
|
import { Page } from '@/components/page'
|
||||||
|
import { DataTable } from '@/components/data-table'
|
||||||
|
|
||||||
// 用户类型定义
|
// 用户类型定义
|
||||||
interface UserData {
|
interface UserData {
|
||||||
@@ -62,7 +62,6 @@ export default function Settings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始加载用户列表
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchUsers()
|
fetchUsers()
|
||||||
}, [])
|
}, [])
|
||||||
@@ -83,7 +82,7 @@ export default function Settings() {
|
|||||||
})
|
})
|
||||||
form.reset()
|
form.reset()
|
||||||
setIsCreateMode(false)
|
setIsCreateMode(false)
|
||||||
fetchUsers() // 刷新用户列表
|
fetchUsers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@@ -108,7 +107,7 @@ export default function Settings() {
|
|||||||
toast.success('用户删除成功', {
|
toast.success('用户删除成功', {
|
||||||
description: '用户账户已删除',
|
description: '用户账户已删除',
|
||||||
})
|
})
|
||||||
fetchUsers() // 刷新用户列表
|
fetchUsers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@@ -118,10 +117,13 @@ export default function Settings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 过滤用户列表
|
const newData = users
|
||||||
const filteredUsers = users.filter(user =>
|
.filter(user => user.account.toLowerCase().includes(searchTerm.toLowerCase()))
|
||||||
user.account.toLowerCase().includes(searchTerm.toLowerCase()),
|
.map(user => ({
|
||||||
)
|
id: user.id,
|
||||||
|
account: user.account,
|
||||||
|
createdAt: new Date(user.createdAt).toLocaleDateString(),
|
||||||
|
}))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
@@ -260,42 +262,34 @@ export default function Settings() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="border rounded-lg">
|
<div className="border rounded-lg">
|
||||||
<Table>
|
<DataTable
|
||||||
<TableHeader>
|
data={newData}
|
||||||
<TableRow>
|
columns={[
|
||||||
<TableHead>账号</TableHead>
|
{
|
||||||
<TableHead>创建时间</TableHead>
|
label: '账号',
|
||||||
<TableHead className="text-right">操作</TableHead>
|
props: 'account',
|
||||||
</TableRow>
|
},
|
||||||
</TableHeader>
|
{
|
||||||
<TableBody>
|
label: '创建时间',
|
||||||
{filteredUsers.length === 0 ? (
|
props: 'createdAt',
|
||||||
<TableRow>
|
},
|
||||||
<TableCell colSpan={3} className="text-center py-4">
|
{
|
||||||
暂无用户数据
|
label: '操作',
|
||||||
</TableCell>
|
render: (val) => {
|
||||||
</TableRow>
|
return (
|
||||||
) : (
|
<Button
|
||||||
filteredUsers.map(user => (
|
variant="outline"
|
||||||
<TableRow key={user.id}>
|
size="sm"
|
||||||
<TableCell className="font-medium">{user.account}</TableCell>
|
className="h-5 border-0 hover:bg-transparent"
|
||||||
<TableCell>{new Date(user.createdAt).toLocaleDateString()}</TableCell>
|
onClick={() => handleDeleteUser(Number(val.id))}
|
||||||
<TableCell className="text-right">
|
>
|
||||||
<div className="flex justify-end">
|
<Trash2Icon className="h-4 w-4" />
|
||||||
<Button
|
</Button>
|
||||||
variant="outline"
|
)
|
||||||
size="sm"
|
},
|
||||||
className="h-5 border-0 hover:bg-transparent"
|
},
|
||||||
onClick={() => handleDeleteUser(Number(user.id))}
|
]}
|
||||||
><Trash2Icon className="h-4 w-4" />
|
/>
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Toaster richColors />
|
<Toaster richColors />
|
||||||
|
|||||||
Reference in New Issue
Block a user