| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import { ColumnDef } from '@tanstack/react-table'
- import { cn } from '@/lib/utils'
- import { Badge } from '@/components/ui/badge'
- import { Checkbox } from '@/components/ui/checkbox'
- import LongText from '@/components/long-text'
- import { callTypes, userTypes } from '../data/data'
- import { User } from '../data/schema'
- import { DataTableColumnHeader } from './data-table-column-header'
- import { DataTableRowActions } from './data-table-row-actions'
- export const columns: ColumnDef<User>[] = [
- {
- id: 'select',
- header: ({ table }) => (
- <Checkbox
- checked={
- table.getIsAllPageRowsSelected() ||
- (table.getIsSomePageRowsSelected() && 'indeterminate')
- }
- onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
- aria-label='Select all'
- className='translate-y-[2px]'
- />
- ),
- meta: {
- className: cn(
- 'sticky md:table-cell start-0 z-10 rounded-tl',
- 'bg-background group-hover/row:bg-muted group-data-[state=selected]/row:bg-muted'
- ),
- },
- cell: ({ row }) => (
- <Checkbox
- checked={row.getIsSelected()}
- onCheckedChange={(value) => row.toggleSelected(!!value)}
- aria-label='Select row'
- className='translate-y-[2px]'
- />
- ),
- enableSorting: false,
- enableHiding: false,
- },
- {
- accessorKey: 'username',
- header: ({ column }) => (
- <DataTableColumnHeader column={column} title='Username' />
- ),
- cell: ({ row }) => (
- <LongText className='max-w-36'>{row.getValue('username')}</LongText>
- ),
- meta: {
- className: cn(
- 'drop-shadow-[0_1px_2px_rgb(0_0_0_/_0.1)] dark:drop-shadow-[0_1px_2px_rgb(255_255_255_/_0.1)] lg:drop-shadow-none',
- 'bg-background group-hover/row:bg-muted group-data-[state=selected]/row:bg-muted',
- 'sticky start-6 md:table-cell'
- ),
- },
- enableHiding: false,
- },
- {
- id: 'fullName',
- header: ({ column }) => (
- <DataTableColumnHeader column={column} title='Name' />
- ),
- cell: ({ row }) => {
- const { firstName, lastName } = row.original
- const fullName = `${firstName} ${lastName}`
- return <LongText className='max-w-36'>{fullName}</LongText>
- },
- meta: { className: 'w-36' },
- },
- {
- accessorKey: 'email',
- header: ({ column }) => (
- <DataTableColumnHeader column={column} title='Email' />
- ),
- cell: ({ row }) => (
- <div className='w-fit text-nowrap'>{row.getValue('email')}</div>
- ),
- },
- {
- accessorKey: 'phoneNumber',
- header: ({ column }) => (
- <DataTableColumnHeader column={column} title='Phone Number' />
- ),
- cell: ({ row }) => <div>{row.getValue('phoneNumber')}</div>,
- enableSorting: false,
- },
- {
- accessorKey: 'status',
- header: ({ column }) => (
- <DataTableColumnHeader column={column} title='Status' />
- ),
- cell: ({ row }) => {
- const { status } = row.original
- const badgeColor = callTypes.get(status)
- return (
- <div className='flex space-x-2'>
- <Badge variant='outline' className={cn('capitalize', badgeColor)}>
- {row.getValue('status')}
- </Badge>
- </div>
- )
- },
- filterFn: (row, id, value) => {
- return value.includes(row.getValue(id))
- },
- enableHiding: false,
- enableSorting: false,
- },
- {
- accessorKey: 'role',
- header: ({ column }) => (
- <DataTableColumnHeader column={column} title='Role' />
- ),
- cell: ({ row }) => {
- const { role } = row.original
- const userType = userTypes.find(({ value }) => value === role)
- if (!userType) {
- return null
- }
- return (
- <div className='flex items-center gap-x-2'>
- {userType.icon && (
- <userType.icon size={16} className='text-muted-foreground' />
- )}
- <span className='text-sm capitalize'>{row.getValue('role')}</span>
- </div>
- )
- },
- filterFn: (row, id, value) => {
- return value.includes(row.getValue(id))
- },
- enableSorting: false,
- enableHiding: false,
- },
- {
- id: 'actions',
- cell: DataTableRowActions,
- },
- ]
|