"use client"; import { Row } from "@tanstack/react-table"; import { Pencil, Trash2, UserMinus } from "lucide-react"; import { useState } from "react"; import { ActionDropdown, ActionDropdownDangerZone, ActionDropdownItem, } from "@/components/shadcn/dropdown"; import { Modal } from "@/components/shadcn/modal"; import { DeleteForm, EditForm, ExpelUserForm } from "../forms"; interface UserRowRole { name?: string; } interface UserRowAttributes { name?: string; email?: string; company_name?: string; role?: UserRowRole; } interface UserRowData { id: string; attributes?: UserRowAttributes; canBeExpelled?: boolean; currentTenantId?: string; isCurrentUser?: boolean; } interface DataTableRowActionsProps { row: Row; roles?: { id: string; name: string }[]; } export function DataTableRowActions({ row, roles, }: DataTableRowActionsProps) { const [isEditOpen, setIsEditOpen] = useState(false); const [isDeleteOpen, setIsDeleteOpen] = useState(false); const [isExpelOpen, setIsExpelOpen] = useState(false); const userId = row.original.id; const userName = row.original.attributes?.name; const userEmail = row.original.attributes?.email; const userCompanyName = row.original.attributes?.company_name; const userRole = row.original.attributes?.role?.name; // Expel gate is resolved server-side against the active tenant's membership // role (owner vs member), mirroring the backend rule in // TenantMembersViewSet.destroy. The row is only expel-eligible when the // current user is an owner of the active tenant and the row is not theirs. const canExpelUser = row.original.canBeExpelled === true && !!row.original.currentTenantId; const currentTenantId = row.original.currentTenantId; // A user can only delete their own account (enforced by the backend), so the // delete action is shown exclusively for the current user's row. const canDeleteUser = row.original.isCurrentUser === true; return ( <> {canDeleteUser && ( )} {canExpelUser && currentTenantId && ( )}
); }