import { Avatar, AvatarFallback, AvatarImage, } from '@affine/admin/components/ui/avatar'; import { cn } from '@affine/admin/utils'; import { FeatureType } from '@affine/graphql'; import { AccountIcon, EmailIcon, EmailWarningIcon, LockIcon, UnlockIcon, } from '@blocksuite/icons/rc'; import type { ColumnDef } from '@tanstack/react-table'; import { type Dispatch, type ReactNode, type SetStateAction, useMemo, } from 'react'; import { Checkbox } from '../../../components/ui/checkbox'; import type { UserType } from '../schema'; import { DataTableColumnHeader } from './data-table-column-header'; import { DataTableRowActions } from './data-table-row-actions'; const StatusItem = ({ condition, IconTrue, IconFalse, textTrue, textFalse, }: { condition: boolean | null; IconTrue: ReactNode; IconFalse: ReactNode; textTrue: string; textFalse: string; }) => (
{condition ? ( <> {IconTrue} {textTrue} ) : ( <> {IconFalse} {textFalse} )}
); export const useColumns = ({ setSelectedUserIds, }: { setSelectedUserIds: Dispatch>>; }) => { const columns: ColumnDef[] = useMemo(() => { return [ { id: 'select', meta: { className: 'w-[40px] flex-shrink-0', }, header: ({ table }) => ( { if (value) { setSelectedUserIds( prev => new Set([ ...prev, ...table .getFilteredRowModel() .rows.map(row => row.original.id), ]) ); } else { // remove selected users in the current page setSelectedUserIds( prev => new Set( [...prev].filter( id => !table .getFilteredRowModel() .rows.some(row => row.original.id === id) ) ) ); } table.toggleAllPageRowsSelected(!!value); }} aria-label="Select all" className="translate-y-[2px]" /> ), cell: ({ row }) => ( { if (value) { setSelectedUserIds(prev => new Set([...prev, row.original.id])); } else { setSelectedUserIds( prev => new Set([...prev].filter(id => id !== row.original.id)) ); } row.toggleSelected(!!value); }} aria-label="Select row" className="translate-y-[2px]" /> ), enableSorting: false, enableHiding: false, }, { accessorKey: 'info', meta: { className: 'w-[250px] flex-shrink-0', }, header: ({ column }) => ( ), cell: ({ row }) => (
{row.original.name} {row.original.features.includes(FeatureType.Admin) && ( Admin )} {row.original.disabled && ( Disabled )}
{row.original.email}
), enableSorting: false, enableHiding: false, }, { accessorKey: 'property', header: ({ column }) => ( ), cell: ({ row: { original: user } }) => (
{user.id}
} IconFalse={ } textTrue="Password Set" textFalse="No Password" /> } IconFalse={ } textTrue="Email Verified" textFalse="Email Not Verified" />
{user.features.length ? ( user.features.map(feature => ( {feature} )) ) : ( No features )}
), }, { id: 'actions', meta: { className: 'w-[80px]', }, header: ({ column }) => ( ), cell: ({ row: { original: user } }) => ( ), }, ]; }, [setSelectedUserIds]); return columns; };