mirror of
https://github.com/henrygd/beszel.git
synced 2026-04-26 06:21:50 +02:00
upupdate
This commit is contained in:
@@ -18,6 +18,17 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
|||||||
import { PlusIcon } from "lucide-react"
|
import { PlusIcon } from "lucide-react"
|
||||||
import { useToast } from "@/components/ui/use-toast"
|
import { useToast } from "@/components/ui/use-toast"
|
||||||
import { $systems } from "@/lib/stores"
|
import { $systems } from "@/lib/stores"
|
||||||
|
import * as v from "valibot"
|
||||||
|
|
||||||
|
const Schema = v.object({
|
||||||
|
system: v.string(),
|
||||||
|
target: v.string(),
|
||||||
|
protocol: v.picklist(["icmp", "tcp", "http"]),
|
||||||
|
port: v.number(),
|
||||||
|
interval: v.pipe(v.string(), v.toNumber(), v.minValue(1), v.maxValue(3600)),
|
||||||
|
enabled: v.boolean(),
|
||||||
|
name: v.optional(v.string()),
|
||||||
|
})
|
||||||
|
|
||||||
export function AddProbeDialog({ systemId }: { systemId?: string }) {
|
export function AddProbeDialog({ systemId }: { systemId?: string }) {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
@@ -45,16 +56,20 @@ export function AddProbeDialog({ systemId }: { systemId?: string }) {
|
|||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await pb.collection("network_probes").create({
|
const payload = v.parse(Schema, {
|
||||||
system: systemId ?? selectedSystemId,
|
system: systemId ?? selectedSystemId,
|
||||||
name: name || targetName,
|
|
||||||
target,
|
target,
|
||||||
protocol,
|
protocol,
|
||||||
port: protocol === "tcp" ? Number(port) : 0,
|
port: protocol === "tcp" ? Number(port) : 0,
|
||||||
interval: Number(probeInterval),
|
interval: probeInterval,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
})
|
})
|
||||||
|
if (name && name !== target) {
|
||||||
|
payload.name = name
|
||||||
|
}
|
||||||
|
await pb.collection("network_probes").create(payload)
|
||||||
resetForm()
|
resetForm()
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
@@ -116,6 +131,7 @@ export function AddProbeDialog({ systemId }: { systemId?: string }) {
|
|||||||
<Label>
|
<Label>
|
||||||
<Trans>Protocol</Trans>
|
<Trans>Protocol</Trans>
|
||||||
</Label>
|
</Label>
|
||||||
|
|
||||||
<Select value={protocol} onValueChange={setProtocol}>
|
<Select value={protocol} onValueChange={setProtocol}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue />
|
<SelectValue />
|
||||||
|
|||||||
Reference in New Issue
Block a user