'use client'; /* IMPORT */ import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Checkbox } from '@/components/ui/checkbox'; import { MoreHorizontal, Trash, Pencil } from 'lucide-react'; import { DataTableColumnHeaderSimple } from '@/components/data-table/data-table-column-simple-header'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { formatDate } from '@/lib/utils'; import { type ColumnDef } from '@tanstack/react-table'; import { type Dispatch, type SetStateAction } from 'react'; import { type DataTableRowAction } from '@/types/table'; import { type EmailWhitelist } from '../service'; // ---------------------------------------------------------------------------------------------------- /* TYPES */ interface GetColumnsProps { setRowAction: Dispatch | null>>; } // ---------------------------------------------------------------------------------------------------- /* FUNCTION FOR GETTING COLUMNS SETTING */ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { return [ // [1] Checkbox Column { id: 'select', header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" className="translate-y-0.5" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" className="translate-y-0.5" /> ), enableSorting: false, enableHiding: false, }, // [2] ID Column { accessorKey: 'id', header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue('id')}
, enableSorting: false, enableHiding: false, size: 80, }, // [3] Email/Domain Column { accessorKey: 'displayValue', header: ({ column }) => ( ), cell: ({ row }) => { const displayValue = row.getValue('displayValue') as string; const isEmail = displayValue.includes('@'); return (
{isEmail ? displayValue : `@${displayValue}`}
); }, enableSorting: false, size: 220, }, // [4] Description Column { accessorKey: 'description', header: ({ column }) => ( ), cell: ({ row }) => { const description = row.getValue('description') as string; return (
{description || '-'}
); }, enableSorting: false, size: 200, }, // [5] Created At Column { accessorKey: 'createdAt', header: ({ column }) => ( ), cell: ({ row }) => { const date = row.getValue('createdAt') as Date; return
{formatDate(date, "KR")}
; }, enableSorting: false, size: 120, }, // [6] Created By Column { accessorKey: 'createdByName', header: ({ column }) => ( ), cell: ({ row }) => { const name = row.getValue('createdByName') as string; return
{name || '-'}
; }, enableSorting: false, size: 100, }, // [7] Updated At Column { accessorKey: 'updatedAt', header: ({ column }) => ( ), cell: ({ row }) => { const date = row.getValue('updatedAt') as Date; return
{formatDate(date, "KR")}
; }, enableSorting: false, size: 120, }, // [8] Updated By Column { accessorKey: 'updatedByName', header: ({ column }) => ( ), cell: ({ row }) => { const name = row.getValue('updatedByName') as string; return
{name || '-'}
; }, enableSorting: false, size: 100, }, // [9] Actions Column { id: 'actions', cell: ({ row }) => ( setRowAction({ row, type: 'update' })} > 수정 setRowAction({ row, type: 'delete' })} className="text-destructive" > 삭제 ), enableSorting: false, enableHiding: false, enableResizing: false, size: 80, minSize: 80, maxSize: 80, }, ]; }