import { AlertInfo, deleteAlert, getAlerts } from '@/api/alerts' import { ConfirmModal } from '@/components/ConfirmModal' import { DataTable } from '@/components/DataTable' import { useState } from 'preact/hooks' import { useMutation, useQuery } from 'react-query' import { AlertFormModal } from './components/AlertFormModal' export const AlertsTable = () => { const alerts = useQuery('/alerts', () => getAlerts()) const deleteMutation = useMutation(deleteAlert, { onSuccess: () => { alerts.refetch() setShowDelete(undefined) }, }) const [showNew, setShowNew] = useState(false) const [edited, setEdited] = useState() const [showDelete, setShowDelete] = useState() return (

Alerts

c.name, scale: 1 }, { key: 'lastStatus', title: 'Last status', render: (c) => c.lastStatus, width: '10rem', }, { key: 'actions', title: 'Actions', width: '10rem', className: 'actions', render: (c) => (
), }, ]} />
{(showNew || edited) && ( { setEdited(undefined) setShowNew(false) }} /> )} {showDelete && ( deleteMutation.mutate(showDelete.id)} onCancel={() => setShowDelete(undefined)} > Are you sure you want to delete {showDelete.name} alert? )}
) }