import { $alerts, pb } from '@/lib/stores' import { useStore } from '@nanostores/react' import { Dialog, DialogTrigger, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { BellIcon, ServerIcon } from 'lucide-react' import { alertInfo, cn } from '@/lib/utils' import { Button } from '@/components/ui/button' import { Switch } from '@/components/ui/switch' import { AlertRecord, SystemRecord } from '@/types' import { lazy, Suspense, useMemo, useState } from 'react' import { toast } from './ui/use-toast' import { Link } from './router' const Slider = lazy(() => import('./ui/slider')) const failedUpdateToast = () => toast({ title: 'Failed to update alert', description: 'Please check logs for more details.', variant: 'destructive', }) export default function AlertsButton({ system }: { system: SystemRecord }) { const alerts = useStore($alerts) const [opened, setOpened] = useState(false) const systemAlerts = alerts.filter((alert) => alert.system === system.id) as AlertRecord[] const active = systemAlerts.length > 0 return ( setOpened(false)} > {opened && ( <> {system.name} alerts See{' '} notification settings {' '} to configure how you receive alerts.
{Object.keys(alertInfo).map((key) => { const alert = alertInfo[key as keyof typeof alertInfo] return ( ) })}
)}
) } function AlertStatus({ system, alerts }: { system: SystemRecord; alerts: AlertRecord[] }) { const [pendingChange, setPendingChange] = useState(false) const alert = alerts.find((alert) => alert.name === 'Status') return ( ) } function AlertWithSlider({ system, alerts, name, title, description, unit = '%', max = 99, Icon, }: { system: SystemRecord alerts: AlertRecord[] name: string title: string description: string unit?: string max?: number Icon: React.FC> }) { const [pendingChange, setPendingChange] = useState(false) const [value, setValue] = useState(80) const [min, setMin] = useState(10) const key = name.replaceAll(' ', '-') const alert = useMemo(() => { const alert = alerts.find((alert) => alert.name === name) if (alert) { setValue(alert.value) setMin(alert.min || 1) } return alert }, [alerts]) const updateAlert = (obj: Partial) => { obj.triggered = false alert && pb.collection('alerts').update(alert.id, obj) } return (
{alert && (
}>

Average exceeds{' '} {value} {unit}

updateAlert({ value: val[0] })} onValueChange={(val) => setValue(val[0])} min={1} max={max} />

For {min} minute {min > 1 && 's'}

updateAlert({ min: val[0] })} onValueChange={(val) => setMin(val[0])} min={1} max={60} />
)}
) }