'use client'; /* IMPORT */ import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Checkbox } from '@/components/ui/checkbox'; import { Copy, Eye, MoreHorizontal, Trash } 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 { getCategoryDisplayName, getCategoryVariant } from '../validations'; import Link from 'next/link'; import { type ColumnDef } from '@tanstack/react-table'; import { type Dispatch, type SetStateAction } from 'react'; import { type DataTableRowAction } from '@/types/table'; import { type TemplateListView } from '@/db/schema'; // ---------------------------------------------------------------------------------------------------- /* 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] Template Name Column { accessorKey: 'name', header: ({ column }) => ( ), cell: ({ row }) => { const template = row.original return (
{template.name} {template.description && (
{template.description}
)}
) }, enableSorting: true, enableHiding: false, size: 200, }, // [3] Email Subject Column { accessorKey: 'subject', header: ({ column }) => ( ), cell: ({ getValue }) => { const subject = getValue() as string; return (
{subject}
) }, enableSorting: true, size: 250, }, // [4] Slug Column { accessorKey: 'slug', header: ({ column }) => ( ), cell: ({ getValue }) => { const slug = getValue() as string; return (
{slug}
) }, enableSorting: true, size: 120, }, // [5] Category Column { accessorKey: 'category', header: ({ column }) => ( ), cell: ({ row }) => { const category = row.original.category; const displayName = getCategoryDisplayName(category); const variant = getCategoryVariant(category); return ( {displayName} ); }, filterFn: (row, id, value) => { return value.includes(row.getValue(id)); }, enableSorting: true, size: 120, }, // [6] Variable Count Column { accessorKey: 'variableCount', header: ({ column }) => ( ), cell: ({ row }) => { const variableCount = row.original.variableCount; const requiredCount = row.original.requiredVariableCount; return (
{variableCount}
{requiredCount > 0 && (
필수: {requiredCount}
)}
); }, enableSorting: true, size: 80, }, // [7] Version Column { accessorKey: 'version', header: ({ column }) => ( ), cell: ({ getValue }) => { const version = getValue() as number; return (
v{version}
) }, enableSorting: true, size: 80, }, // [8] Created At Column { accessorKey: 'createdAt', header: ({ column }) => ( ), cell: ({ cell }) => { const date = cell.getValue() as Date; return (
{formatDate(date)}
) }, enableSorting: true, size: 150, }, // [9] Updated At Column { accessorKey: 'updatedAt', header: ({ column }) => ( ), cell: ({ cell }) => { const date = cell.getValue() as Date; return (
{formatDate(date)}
) }, enableSorting: true, size: 150, }, // [10] Actions Column { id: 'actions', cell: ({ row }) => { const template = row.original; return ( { setRowAction({ type: 'duplicate', row }) }} > { setRowAction({ type: 'delete', row }) }} className="text-destructive focus:text-destructive" > ) }, enableSorting: false, enableHiding: false, size:80 }, ]; }