mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-05-06 05:38:51 +00:00
fix: stabilize admin frontend and resolve TS build errors
This commit is contained in:
@@ -30,7 +30,6 @@ import {
|
|||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select"
|
} from "@/components/ui/select"
|
||||||
import { IconButton } from "@/components/xui/icon-button"
|
import { IconButton } from "@/components/xui/icon-button"
|
||||||
import { asOptionalField } from "@/lib/utils"
|
|
||||||
import { ModelNotification } from "@/types"
|
import { ModelNotification } from "@/types"
|
||||||
import { nrequestMethods, nrequestTypes } from "@/types"
|
import { nrequestMethods, nrequestTypes } from "@/types"
|
||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export const NotificationProvider: React.FC<NotificationProviderProps> = ({
|
|||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const n = (await getNotification()) || []
|
const n = (await getNotification()) || []
|
||||||
const nData = n.map(({ id, name }) => ({ id, name }))
|
const nData = n.map(({ id, name }) => ({ id: id!, name }))
|
||||||
setNotifier(nData)
|
setNotifier(nData)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
toast("NotificationProvider Error", {
|
toast("NotificationProvider Error", {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export const ServerProvider: React.FC<ServerProviderProps> = ({
|
|||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const s = (await getServers()) || []
|
const s = (await getServers()) || []
|
||||||
const serverData = s.map(({ id, name }) => ({ id, name }))
|
const serverData = s.map(({ id, name }) => ({ id: id!, name }))
|
||||||
setServer(serverData)
|
setServer(serverData)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
toast("ServerProvider Error", {
|
toast("ServerProvider Error", {
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ export default function AlertRulePage() {
|
|||||||
className="flex gap-2"
|
className="flex gap-2"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteAlertRules,
|
fn: deleteAlertRules,
|
||||||
id: s.id,
|
id: s.id!,
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -147,7 +147,7 @@ export default function AlertRulePage() {
|
|||||||
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteAlertRules,
|
fn: deleteAlertRules,
|
||||||
id: selectedRows.map((r) => r.original.id),
|
id: selectedRows.map((r) => r.original.id!),
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
+3
-3
@@ -164,7 +164,7 @@ export default function CronPage() {
|
|||||||
return (
|
return (
|
||||||
<ActionButtonGroup
|
<ActionButtonGroup
|
||||||
className="flex gap-2"
|
className="flex gap-2"
|
||||||
delete={{ fn: deleteCron, id: s.id, mutate: mutate }}
|
delete={{ fn: deleteCron, id: s.id!, mutate: mutate }}
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<IconButton
|
<IconButton
|
||||||
@@ -172,7 +172,7 @@ export default function CronPage() {
|
|||||||
icon="play"
|
icon="play"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
try {
|
try {
|
||||||
await runCron(s.id)
|
await runCron(s.id!)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
toast(t("Error"), {
|
toast(t("Error"), {
|
||||||
@@ -215,7 +215,7 @@ export default function CronPage() {
|
|||||||
className="flex gap-2 flex-wrap shrink-0"
|
className="flex gap-2 flex-wrap shrink-0"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteCron,
|
fn: deleteCron,
|
||||||
id: selectedRows.map((r) => r.original.id),
|
id: selectedRows.map((r) => r.original.id!),
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
+2
-2
@@ -121,7 +121,7 @@ export default function DDNSPage() {
|
|||||||
className="flex gap-2"
|
className="flex gap-2"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteDDNSProfiles,
|
fn: deleteDDNSProfiles,
|
||||||
id: s.id,
|
id: s.id!,
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -152,7 +152,7 @@ export default function DDNSPage() {
|
|||||||
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteDDNSProfiles,
|
fn: deleteDDNSProfiles,
|
||||||
id: selectedRows.map((r) => r.original.id),
|
id: selectedRows.map((r) => r.original.id!),
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
+2
-2
@@ -106,7 +106,7 @@ export default function NATPage() {
|
|||||||
return (
|
return (
|
||||||
<ActionButtonGroup
|
<ActionButtonGroup
|
||||||
className="flex gap-2"
|
className="flex gap-2"
|
||||||
delete={{ fn: deleteNAT, id: s.id, mutate: mutate }}
|
delete={{ fn: deleteNAT, id: s.id!, mutate: mutate }}
|
||||||
>
|
>
|
||||||
<NATCard mutate={mutate} data={s} />
|
<NATCard mutate={mutate} data={s} />
|
||||||
</ActionButtonGroup>
|
</ActionButtonGroup>
|
||||||
@@ -135,7 +135,7 @@ export default function NATPage() {
|
|||||||
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteNAT,
|
fn: deleteNAT,
|
||||||
id: selectedRows.map((r) => r.original.id),
|
id: selectedRows.map((r) => r.original.id!),
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export default function NotificationGroupPage() {
|
|||||||
className="flex gap-2"
|
className="flex gap-2"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteNotificationGroups,
|
fn: deleteNotificationGroups,
|
||||||
id: s.group.id,
|
id: s.group.id!,
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -128,7 +128,7 @@ export default function NotificationGroupPage() {
|
|||||||
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteNotificationGroups,
|
fn: deleteNotificationGroups,
|
||||||
id: selectedRows.map((r) => r.original.group.id),
|
id: selectedRows.map((r) => r.original.group.id!),
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export default function NotificationPage() {
|
|||||||
accessorFn: (row) => {
|
accessorFn: (row) => {
|
||||||
return (
|
return (
|
||||||
notifierGroup
|
notifierGroup
|
||||||
?.filter((ng) => ng.notifications?.includes(row.id))
|
?.filter((ng) => ng.notifications?.includes(row.id!))
|
||||||
.map((ng) => ng.group.id) || []
|
.map((ng) => ng.group.id) || []
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -112,7 +112,7 @@ export default function NotificationPage() {
|
|||||||
className="flex gap-2"
|
className="flex gap-2"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteNotification,
|
fn: deleteNotification,
|
||||||
id: s.id,
|
id: s.id!,
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -143,7 +143,7 @@ export default function NotificationPage() {
|
|||||||
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteNotification,
|
fn: deleteNotification,
|
||||||
id: selectedRows.map((r) => r.original.id),
|
id: selectedRows.map((r) => r.original.id!),
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table"
|
} from "@/components/ui/table"
|
||||||
import { useAuth } from "@/hooks/useAuth"
|
import { useAuth } from "@/hooks/useAuth"
|
||||||
import { ModelOnlineUser, ModelOnlineUserApi } from "@/types"
|
import { GithubComNezhahqNezhaModelPaginatedResponseArrayModelOnlineUserModelOnlineUser, ModelOnlineUser } from "@/types"
|
||||||
import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table"
|
import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table"
|
||||||
import { useEffect, useMemo } from "react"
|
import { useEffect, useMemo } from "react"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
@@ -40,7 +40,7 @@ export default function OnlineUserPage() {
|
|||||||
// 计算 offset
|
// 计算 offset
|
||||||
const offset = (page - 1) * pageSize
|
const offset = (page - 1) * pageSize
|
||||||
|
|
||||||
const { data, mutate, error, isLoading } = useSWR<ModelOnlineUserApi, Error>(
|
const { data, mutate, error, isLoading } = useSWR<GithubComNezhahqNezhaModelPaginatedResponseArrayModelOnlineUserModelOnlineUser, Error>(
|
||||||
`/api/v1/online-user?offset=${offset}&limit=${pageSize}`,
|
`/api/v1/online-user?offset=${offset}&limit=${pageSize}`,
|
||||||
swrFetcher,
|
swrFetcher,
|
||||||
)
|
)
|
||||||
@@ -94,7 +94,7 @@ export default function OnlineUserPage() {
|
|||||||
accessorFn: (row) => row.connected_at,
|
accessorFn: (row) => row.connected_at,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const s = row.original
|
const s = row.original
|
||||||
const date = new Date(s.connected_at)
|
const date = new Date(s.connected_at!)
|
||||||
return <span>{date.toISOString()}</span>
|
return <span>{date.toISOString()}</span>
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -125,7 +125,7 @@ export default function OnlineUserPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dataCache = useMemo(() => {
|
const dataCache = useMemo(() => {
|
||||||
return data?.value ?? []
|
return data?.data?.value ?? []
|
||||||
}, [data])
|
}, [data])
|
||||||
|
|
||||||
const table = useReactTable<ModelOnlineUser>({
|
const table = useReactTable<ModelOnlineUser>({
|
||||||
@@ -137,9 +137,9 @@ export default function OnlineUserPage() {
|
|||||||
const selectedRows = table.getSelectedRowModel().rows
|
const selectedRows = table.getSelectedRowModel().rows
|
||||||
|
|
||||||
const renderPagination = () => {
|
const renderPagination = () => {
|
||||||
if (!data?.pagination) return null
|
if (!data?.data?.pagination) return null
|
||||||
|
|
||||||
const { total } = data.pagination
|
const { total = 0 } = data.data.pagination
|
||||||
const totalPages = Math.ceil(total / pageSize)
|
const totalPages = Math.ceil(total / pageSize)
|
||||||
|
|
||||||
const handlePageChange = (newPage: number) => {
|
const handlePageChange = (newPage: number) => {
|
||||||
|
|||||||
+1
-2
@@ -4,8 +4,7 @@ import { Toaster } from "@/components/ui/sonner"
|
|||||||
import useSetting from "@/hooks/useSetting"
|
import useSetting from "@/hooks/useSetting"
|
||||||
import i18n from "@/lib/i18n"
|
import i18n from "@/lib/i18n"
|
||||||
import { InjectContext } from "@/lib/inject"
|
import { InjectContext } from "@/lib/inject"
|
||||||
import { DateTime } from "luxon"
|
import { useEffect } from "react"
|
||||||
import { useEffect, useState } from "react"
|
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { Outlet } from "react-router-dom"
|
import { Outlet } from "react-router-dom"
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export default function ServerGroupPage() {
|
|||||||
className="flex gap-2"
|
className="flex gap-2"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteServerGroups,
|
fn: deleteServerGroups,
|
||||||
id: s.group.id,
|
id: s.group.id!,
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -128,7 +128,7 @@ export default function ServerGroupPage() {
|
|||||||
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteServerGroups,
|
fn: deleteServerGroups,
|
||||||
id: selectedRows.map((r) => r.original.group.id),
|
id: selectedRows.map((r) => r.original.group.id!),
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ export default function ServicePage() {
|
|||||||
return (
|
return (
|
||||||
<ActionButtonGroup
|
<ActionButtonGroup
|
||||||
className="flex gap-2"
|
className="flex gap-2"
|
||||||
delete={{ fn: deleteService, id: s.id, mutate: mutate }}
|
delete={{ fn: deleteService, id: s.id!, mutate: mutate }}
|
||||||
>
|
>
|
||||||
<ServiceCard mutate={mutate} data={s} />
|
<ServiceCard mutate={mutate} data={s} />
|
||||||
</ActionButtonGroup>
|
</ActionButtonGroup>
|
||||||
@@ -181,7 +181,7 @@ export default function ServicePage() {
|
|||||||
className="flex gap-2 flex-wrap shrink-0"
|
className="flex gap-2 flex-wrap shrink-0"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteService,
|
fn: deleteService,
|
||||||
id: selectedRows.map((r) => r.original.id),
|
id: selectedRows.map((r) => r.original.id!),
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ export default function SettingsPage() {
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Telegram Bot Token</FormLabel>
|
<FormLabel>Telegram Bot Token</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder="123456789:ABCDEF..." {...field} />
|
<Input placeholder="123456789:ABCDEF..." {...field} value={field.value as string || ""} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
@@ -273,7 +273,7 @@ export default function SettingsPage() {
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Telegram Admin Chat ID</FormLabel>
|
<FormLabel>Telegram Admin Chat ID</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder="12345678" {...field} />
|
<Input placeholder="12345678" {...field} value={field.value as string || ""} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|||||||
+2
-2
@@ -90,7 +90,7 @@ export default function UserPage() {
|
|||||||
className="flex gap-2"
|
className="flex gap-2"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteUser,
|
fn: deleteUser,
|
||||||
id: s.id,
|
id: s.id!,
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -121,7 +121,7 @@ export default function UserPage() {
|
|||||||
className="flex-2 flex gap-2 ml-auto"
|
className="flex-2 flex gap-2 ml-auto"
|
||||||
delete={{
|
delete={{
|
||||||
fn: deleteUser,
|
fn: deleteUser,
|
||||||
id: selectedRows.map((r) => r.original.id),
|
id: selectedRows.map((r) => r.original.id!),
|
||||||
mutate: mutate,
|
mutate: mutate,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
+3
-3
@@ -98,13 +98,13 @@ export default function WAFPage() {
|
|||||||
header: t("LastBlockReason"),
|
header: t("LastBlockReason"),
|
||||||
accessorKey: "lastBlockReason",
|
accessorKey: "lastBlockReason",
|
||||||
accessorFn: (row) => row.block_reason,
|
accessorFn: (row) => row.block_reason,
|
||||||
cell: ({ row }) => <span>{wafBlockReasons[row.original.block_reason] || ""}</span>,
|
cell: ({ row }) => <span>{wafBlockReasons[row.original.block_reason!] || ""}</span>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: t("BlockIdentifier"),
|
header: t("BlockIdentifier"),
|
||||||
accessorKey: "BlockIdentifier",
|
accessorKey: "BlockIdentifier",
|
||||||
accessorFn: (row) => {
|
accessorFn: (row) => {
|
||||||
return wafBlockIdentifiers[row.block_identifier] || row.block_identifier
|
return wafBlockIdentifiers[row.block_identifier!] || row.block_identifier
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -158,7 +158,7 @@ export default function WAFPage() {
|
|||||||
const renderPagination = () => {
|
const renderPagination = () => {
|
||||||
if (!data?.pagination) return null
|
if (!data?.pagination) return null
|
||||||
|
|
||||||
const { total } = data.pagination
|
const { total = 0 } = data.pagination
|
||||||
const totalPages = Math.ceil(total / pageSize)
|
const totalPages = Math.ceil(total / pageSize)
|
||||||
|
|
||||||
const handlePageChange = (newPage: number) => {
|
const handlePageChange = (newPage: number) => {
|
||||||
|
|||||||
@@ -397,6 +397,8 @@ export interface ModelNotification {
|
|||||||
updated_at?: string
|
updated_at?: string
|
||||||
url: string
|
url: string
|
||||||
verify_tls?: boolean
|
verify_tls?: boolean
|
||||||
|
skip_check?: boolean
|
||||||
|
format_metric_units?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ModelNotificationForm {
|
export interface ModelNotificationForm {
|
||||||
@@ -410,6 +412,8 @@ export interface ModelNotificationForm {
|
|||||||
skip_check?: boolean
|
skip_check?: boolean
|
||||||
url?: string
|
url?: string
|
||||||
verify_tls?: boolean
|
verify_tls?: boolean
|
||||||
|
skip_check?: boolean
|
||||||
|
format_metric_units?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ModelNotificationGroup {
|
export interface ModelNotificationGroup {
|
||||||
@@ -595,6 +599,7 @@ export interface ModelService {
|
|||||||
enable_trigger_task?: boolean
|
enable_trigger_task?: boolean
|
||||||
/** 失败时执行的触发任务id */
|
/** 失败时执行的触发任务id */
|
||||||
fail_trigger_tasks: number[]
|
fail_trigger_tasks: number[]
|
||||||
|
display_index: number
|
||||||
id?: number
|
id?: number
|
||||||
latency_notify?: boolean
|
latency_notify?: boolean
|
||||||
max_latency: number
|
max_latency: number
|
||||||
@@ -689,6 +694,8 @@ export interface ModelSetting {
|
|||||||
custom_links?: string
|
custom_links?: string
|
||||||
background_image_day?: string
|
background_image_day?: string
|
||||||
background_image_night?: string
|
background_image_night?: string
|
||||||
|
telegram_bot_token?: string
|
||||||
|
telegram_admin_chat_id?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ModelSettingForm {
|
export interface ModelSettingForm {
|
||||||
@@ -722,6 +729,8 @@ export interface ModelSettingForm {
|
|||||||
background_image_day?: string
|
background_image_day?: string
|
||||||
/** 夜间背景图链接 */
|
/** 夜间背景图链接 */
|
||||||
background_image_night?: string
|
background_image_night?: string
|
||||||
|
telegram_bot_token?: string
|
||||||
|
telegram_admin_chat_id?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ModelSettingResponse {
|
export interface ModelSettingResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user