users-columns.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import { type ColumnDef } from '@tanstack/react-table'
  2. import { cn } from '@/lib/utils'
  3. import { Badge } from '@/components/ui/badge'
  4. import { Checkbox } from '@/components/ui/checkbox'
  5. import { DataTableColumnHeader } from '@/components/data-table'
  6. import { LongText } from '@/components/long-text'
  7. import { type User } from '@/types/users.types'
  8. import { DataTableRowActions } from './data-table-row-actions'
  9. import { planDurations } from '@/constants/users/users-constants'
  10. export const usersColumns: ColumnDef<User>[] = [
  11. {
  12. id: 'select',
  13. header: ({ table }) => (
  14. <Checkbox
  15. checked={
  16. table.getIsAllPageRowsSelected() ||
  17. (table.getIsSomePageRowsSelected() && 'indeterminate')
  18. }
  19. onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
  20. aria-label='Select all'
  21. className='translate-y-0.5'
  22. />
  23. ),
  24. cell: ({ row }) => (
  25. <Checkbox
  26. checked={row.getIsSelected()}
  27. onCheckedChange={(value) => row.toggleSelected(!!value)}
  28. aria-label='Select row'
  29. className='translate-y-0.5'
  30. />
  31. ),
  32. enableSorting: false,
  33. enableHiding: false,
  34. meta: {
  35. className: cn('inset-s-0 z-10 rounded-tl-[inherit] max-md:sticky'),
  36. },
  37. },
  38. {
  39. accessorKey: 'id',
  40. header: ({ column }) => (
  41. <DataTableColumnHeader column={column} title='شناسه' />
  42. ),
  43. cell: ({ row }) => <div className='w-15'>#{row.original.id}</div>,
  44. enableSorting: true,
  45. },
  46. {
  47. accessorKey: 'username',
  48. header: ({ column }) => (
  49. <DataTableColumnHeader column={column} title='نام کاربری' />
  50. ),
  51. cell: ({ row }) => (
  52. <LongText className='max-w-36 ps-3'>{row.original.username}</LongText>
  53. ),
  54. enableHiding: false,
  55. meta: {
  56. className: cn(
  57. 'drop-shadow-[0_1px_2px_rgb(0_0_0_/_0.1)]',
  58. 'dark:drop-shadow-[0_1px_2px_rgb(255_255_255_/_0.1)]',
  59. 'inset-s-6 ps-0.5 max-md:sticky',
  60. '@4xl/content:table-cell',
  61. '@4xl/content:drop-shadow-none'
  62. ),
  63. },
  64. },
  65. {
  66. accessorKey: 'full_name',
  67. header: ({ column }) => (
  68. <DataTableColumnHeader column={column} title='نام کامل' />
  69. ),
  70. cell: ({ row }) => (
  71. <LongText className='max-w-40'>{row.original.full_name}</LongText>
  72. ),
  73. },
  74. {
  75. accessorKey: 'phone',
  76. header: ({ column }) => (
  77. <DataTableColumnHeader column={column} title='شماره موبایل' />
  78. ),
  79. cell: ({ row }) => <div dir='ltr'>{row.original.phone}</div>,
  80. },
  81. // {
  82. // accessorKey: 'email',
  83. // header: ({ column }) => (
  84. // <DataTableColumnHeader column={column} title='ایمیل' />
  85. // ),
  86. // cell: ({ row }) => (
  87. // <div className='text-nowrap'>{row.original.email ?? '-'}</div>
  88. // ),
  89. // },
  90. {
  91. accessorKey: 'subscription',
  92. header: ({ column }) => (
  93. <DataTableColumnHeader column={column} title='اشتراک' />
  94. ),
  95. cell: ({ row }) => (
  96. <div className='text-nowrap'>
  97. {row.original.subscription?.plan
  98. ? `${row.original.subscription?.plan?.type} (${planDurations[row.original.subscription?.plan?.duration]})`
  99. : '-'}
  100. </div>
  101. ),
  102. },
  103. {
  104. accessorKey: 'followers_count',
  105. header: ({ column }) => (
  106. <DataTableColumnHeader column={column} title='دنبال‌کننده' />
  107. ),
  108. cell: ({ row }) => (
  109. <Badge variant='secondary'>{row.original.followers_count}</Badge>
  110. ),
  111. },
  112. {
  113. accessorKey: 'created_at',
  114. header: ({ column }) => (
  115. <DataTableColumnHeader column={column} title='تاریخ عضویت' />
  116. ),
  117. cell: ({ row }) => {
  118. return (
  119. <div className='text-sm text-muted-foreground'>
  120. {new Date(row.original.created_at).toLocaleDateString('fa-IR')}
  121. </div>
  122. )
  123. },
  124. },
  125. {
  126. id: 'actions',
  127. cell: DataTableRowActions,
  128. enableSorting: false,
  129. enableHiding: false,
  130. },
  131. ]