'use client' import { type ColumnDef } from '@tanstack/react-table' import { useToggle } from 'ahooks' import { EllipsisVerticalIcon, PencilIcon, UserRoundMinusIcon } from 'lucide-react' import { NavLink, useParams } from 'react-router' import { toast } from 'sonner' import { Abbr } from '@repo/ui/components/abbr' import { useDataTable, DataTableColumnDatetime, DataTableColumnHeader, DataTableColumnCpfCnpj } from '@repo/ui/components/data-table' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@repo/ui/components/ui/alert-dialog' import { Avatar, AvatarFallback } from '@repo/ui/components/ui/avatar' import { Button } from '@repo/ui/components/ui/button' import { Checkbox } from '@repo/ui/components/ui/checkbox' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@repo/ui/components/ui/dropdown-menu' import { Spinner } from '@repo/ui/components/ui/spinner' import { initials } from '@repo/ui/lib/utils' // This type is used to define the shape of our data. // You can use a Zod schema here if you want. export type User = { id: string name: string email: string cpf?: string cnpj?: string } export const columns: ColumnDef[] = [ { id: 'select', header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} className="cursor-pointer" aria-label="Selecionar tudo" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} className="cursor-pointer" aria-label="Selecionar linha" /> ) }, { header: 'Colaborador', cell: ({ row }) => { const { name, email } = row.original return (
{initials(name)}
  • {name}
  • {email}
) } }, { accessorKey: 'cpf', header: 'CPF', cell: ({ row, column }) => ( ) }, { accessorKey: 'createDate', enableSorting: true, meta: { title: 'Cadastrado em' }, header: ({ column }) => , cell: ({ row, column }) => ( ) }, { accessorKey: 'lastLogin', enableSorting: true, meta: { title: 'Último acesso' }, header: ({ column }) => , cell: ({ row, column }) => ( ) }, { id: 'actions', cell: ({ row }) => } ] function ActionMenu({ row }: { row: any }) { return (
e.preventDefault()}> {({ isPending }) => ( <> {isPending ? : } Editar )}
) } function UnlinkItem({ id }: { id: string }) { const [loading, { set }] = useToggle(false) const { orgid } = useParams() const { table } = useDataTable() const unlink = async (e) => { e.preventDefault() set(true) const r = await fetch(`/~/api/orgs/${orgid}/users/${id}`, { method: 'DELETE' }) if (r.ok) { toast.info('O colaborador foi desvinculado') // @ts-ignore table.options.meta?.removeRow?.(id) } } return ( e.preventDefault()} > Desvincular Tem certeza absoluta? Esta ação não pode ser desfeita. Isso{' '} removerá permanentemente o vínculo {' '} deste colaborador. Cancelar ) }