diff --git a/client/src/pages/patients/PatientsTable.jsx b/client/src/pages/patients/PatientsTable.jsx index 3e1e111e..efd38ad0 100644 --- a/client/src/pages/patients/PatientsTable.jsx +++ b/client/src/pages/patients/PatientsTable.jsx @@ -1,20 +1,15 @@ import PropTypes from 'prop-types'; -import { useState, useContext } from 'react'; -import { Link } from 'react-router-dom'; -import { Paper, Table, ActionIcon, Menu, Modal, Button } from '@mantine/core'; +import { useState, useContext, useMemo, useCallback } from 'react'; +import { Paper, Table, Modal, Button } from '@mantine/core'; import { useDisclosure } from '@mantine/hooks'; import { useDeletePatient } from './useDeletePatient'; import { notifications } from '@mantine/notifications'; -import { - IconDotsVertical, - IconUser, - IconQrcode, - IconTrash, -} from '@tabler/icons-react'; import classes from './Patients.module.css'; import Context from '../../Context'; +import PatientTableRow from './PatientTableRow'; + const patientTableProps = { headers: PropTypes.arrayOf( PropTypes.shape({ @@ -41,14 +36,16 @@ const patientTableProps = { export default function PatientsTable({ headers, data }) { const [opened, { open, close }] = useDisclosure(false); const [selectedPatient, setSelectedPatient] = useState(null); - const { mutate: deletePatient } = useDeletePatient(); + const { mutateAsync: deletePatient, isPending } = useDeletePatient(); const { user } = useContext(Context); - const showDeleteConfirmation = (patient) => { - setSelectedPatient(patient); - open(); - }; - + const showDeleteConfirmation = useCallback( + (patient) => { + setSelectedPatient(patient); + open(); + }, + [open], + ); const confirmPatientDeletion = async () => { try { await deletePatient(selectedPatient.id); @@ -65,9 +62,40 @@ export default function PatientsTable({ headers, data }) { color: 'red', }); } + if (!isPending) { + setSelectedPatient(null); + close(); + } + }; + + const cancelPatientDeletion = () => { + setSelectedPatient(null); close(); }; + const emptyStateRow = useMemo( + () => ( +
Are you sure you want to delete this patient record?
-