import { useMemo, useState } from "react"; import { useNavigate } from "react-router"; import DeleteOutlineIcon from "@mui/icons-material/DeleteOutlined"; import EditOutlinedIcon from "@mui/icons-material/EditOutlined"; import { Alert, Box, Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, IconButton, Paper, Stack, Table, TableBody, TableCell, TableContainer, TableHead, TablePagination, TableRow, TextField, Tooltip, Typography, } from "@mui/material"; import type { ContactListItem } from "@/domain/contacts/types/contact"; import { useContactsList } from "@/domain/contacts/use-cases/use-contacts-list"; import { useDeleteContact } from "@/domain/contacts/use-cases/use-delete-contact"; import { useDebounce } from "@/hooks/use-debounce"; export default function ContactsListPage() { const navigate = useNavigate(); const [search, setSearch] = useState(""); const [page, setPage] = useState(0); const [pageSize, setPageSize] = useState(12); const [deleteTarget, setDeleteTarget] = useState(null); const debouncedSearch = useDebounce(search, 300); const deleteContact = useDeleteContact(); const listParams = useMemo( () => ({ search: debouncedSearch, page: page + 1, pageSize }), [debouncedSearch, page, pageSize], ); const { data, isLoading, isFetching, error } = useContactsList(listParams); const rows = data?.items ?? []; const totalCount = data?.totalCount ?? 0; return ( Contacts {totalCount} total {isFetching && !isLoading && } { setSearch(e.target.value); setPage(0); }} placeholder="Search contacts..." className="min-w-sidebar" /> {Boolean(error) && ( {error instanceof Error ? error.message : "Failed to load contacts"} )} Name Account Title Email Phone Owner Actions {isLoading ? ( ) : rows.length === 0 ? ( No contacts found ) : ( rows.map((row) => ( {row.account || "—"} {row.title || "—"} {row.email || "—"} {row.phoneNumber || "—"} {row.owner || "—"} navigate(`/contacts/edit/${row.id}`)}> setDeleteTarget(row)}> )) )}
setPage(nextPage)} rowsPerPage={pageSize} onRowsPerPageChange={(e) => { setPageSize(Number(e.target.value)); setPage(0); }} rowsPerPageOptions={[12, 24, 48]} /> setDeleteTarget(null)}> Delete Contact Are you sure you want to delete "{deleteTarget?.name}"?
); }