Files
Checkmate/client/src/Pages/Account/components/TeamTable.tsx
T
gorkem-bwl 82998a7795 feat: add ability to remove team members
## Changes
- Add DELETE /api/v1/auth/users/:userId endpoint (admin + superadmin)
- Add deleteUserById service method with role hierarchy enforcement
- Superadmins can remove admins and regular users
- Admins can only remove regular users
- No one can remove superadmins, demo users, or themselves via this endpoint
- Add "Remove user" button with confirmation dialog on edit user page
- Allow admins to view user details and access the edit user page
- Add i18n strings for remove user button and confirmation dialog

## Access control
- superadmin -> can remove admin, user
- admin -> can remove user only
- admin cannot remove superadmin or other admins (enforced on both backend and frontend)
2026-03-06 14:18:27 -05:00

61 lines
1.5 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 type { Header } from "@/Components/design-elements/Table";
import { useIsAdmin } from "@/Hooks/useIsAdmin";
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 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={users}
onRowClick={isAdmin ? handleRowClick : undefined}
/>
);
};