import { ContactPointInfo, deleteContactPoint, getContactPoints, } from '@/api/contactPoints' import { ConfirmModal } from '@/components/ConfirmModal' import { DataTable } from '@/components/DataTable' import { EditIcon, PlusIcon, TrashIcon } from '@/icons' import { useState } from 'preact/hooks' import { useMutation, useQuery } from 'react-query' import { NoContactPoints } from '../NoContactPoints' import { ContactPointFormModal } from './components/ContactPointFormModal' export const ContactPointsTable = () => { const contactPoints = useQuery('/contact-points', () => getContactPoints()) const deleteMutation = useMutation(deleteContactPoint, { onSuccess: () => { contactPoints.refetch() setShowDelete(undefined) }, }) const [showNew, setShowNew] = useState(false) const [edited, setEdited] = useState() const [showDelete, setShowDelete] = useState() return (

Contact Points

} columns={[ { key: 'name', title: 'Name', render: (c) => c.name, scale: 1 }, { key: 'type', title: 'Type', render: (c) => c.type, width: '5rem', }, { key: 'actions', title: 'Actions', width: '12rem', className: 'actions', render: (c) => (
), }, ]} />
{(showNew || edited) && ( { setShowNew(false) setEdited(undefined) }} /> )} {showDelete && ( deleteMutation.mutate(showDelete.id)} onCancel={() => setShowDelete(undefined)} confirmText="Delete" > Do you want to delete {showDelete.name} contact point? )}
) }