Files
Checkmate/client/src/Pages/Account/components/TeamTable.tsx
T
gorkem-bwl 897204ead3 refactor(client): extract useClientPagination hook and clean up Select prop
- Replace duplicated page/rowsPerPage state in Team, Notifications and Status Pages tables with a shared useClientPagination hook
- Drop unused placeholderColor prop from Select; placeholder always uses secondary text
- Restore LAYOUT.MD constant for the account menu item gap
2026-04-26 00:22:14 -04:00

67 lines
1.8 KiB
TypeScript

import Typography from "@mui/material/Typography";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Table } from "@/Components/design-elements";
import { Pagination } from "@/Components/design-elements/Table";
import type { Header } from "@/Components/design-elements/Table";
import { useIsAdmin } from "@/Hooks/useIsAdmin";
import { useClientPagination } from "@/Hooks/useClientPagination";
import type { User } from "@/Types/User";
interface TeamTableProps {
users: User[];
}
export const TeamTable = ({ users }: TeamTableProps) => {
const { t } = useTranslation();
const navigate = useNavigate();
const isAdmin = useIsAdmin();
const { pagedRows, paginationProps } = useClientPagination(users);
const headers: Header<User>[] = [
{
id: "name",
content: t("common.table.headers.name"),
render: (row) => <Typography>{`${row.firstName} ${row.lastName}`}</Typography>,
},
{
id: "email",
content: t("pages.account.team.table.headers.email"),
render: (row) => <Typography>{row.email}</Typography>,
},
{
id: "role",
content: t("pages.account.team.table.headers.role"),
render: (row) => (
<Typography>
{row.role.map((r) => t(`common.auth.roles.${r}`)).join(", ")}
</Typography>
),
},
{
id: "created",
content: t("pages.account.team.table.headers.created"),
render: (row) => (
<Typography>{new Date(row.createdAt).toLocaleDateString()}</Typography>
),
},
];
const handleRowClick = (row: User) => {
if (isAdmin) {
navigate(`/account/team/${row.id}`);
}
};
return (
<>
<Table
headers={headers}
data={pagedRows}
onRowClick={isAdmin ? handleRowClick : undefined}
/>
{users.length > 0 && <Pagination {...paginationProps} />}
</>
);
};