"use client"; import { useRouter } from "next/navigation"; import { flexRender, getCoreRowModel, type ColumnDef, useReactTable, } from "@tanstack/react-table"; import { useMemo } from "react"; import type { MaestroListItem } from "@/lib/maestros"; import { cn } from "@/lib/utils"; import { formatDate, getAccountTypeLabel, getActivateStatusLabel, } from "@/lib/utils"; type MaestrosTableProps = { data: MaestroListItem[]; }; export function MaestrosTable({ data }: MaestrosTableProps) { const router = useRouter(); const columns = useMemo[]>( () => [ { accessorKey: "maestroID", header: "ID", cell: ({ row }) => ( {row.original.maestroID} ), }, { accessorKey: "name", header: "이름", cell: ({ row }) => (

{row.original.name}

{row.original.email}

), }, { accessorKey: "email", header: "이메일", cell: ({ row }) => ( {row.original.email} ), }, { accessorKey: "accountType", header: "계정 유형", cell: ({ row }) => getAccountTypeLabel(row.original.accountType), }, { accessorKey: "activateStatus", header: "상태", cell: ({ row }) => ( {getActivateStatusLabel(row.original.activateStatus)} ), }, { accessorKey: "playerCount", header: "학생 수", cell: ({ row }) => ( {row.original.playerCount.toLocaleString()} ), }, { accessorKey: "acceptClausesDateTime", header: "가입일", cell: ({ row }) => formatDate(row.original.acceptClausesDateTime), }, { accessorKey: "availableActivateDateTime", header: "만료일", cell: ({ row }) => formatDate(row.original.availableActivateDateTime), }, ], [] ); // TanStack Table manages internal functions that React Compiler should not memoize. // eslint-disable-next-line react-hooks/incompatible-library const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), }); return (
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => ( ))} ))} {table.getRowModel().rows.length > 0 ? ( table.getRowModel().rows.map((row) => ( { router.push(`/maestros/${row.original.maestroID}`); }} onKeyDown={(event) => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); router.push(`/maestros/${row.original.maestroID}`); } }} role="link" tabIndex={0} > {row.getVisibleCells().map((cell) => ( ))} )) ) : ( )}
{header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext() )}
{flexRender( cell.column.columnDef.cell, cell.getContext() )}
조건에 맞는 마에스트로가 없습니다.
); } function getActivateStatusBadgeClass(maestro: MaestroListItem) { if ( maestro.activateStatus === 2 && isBeforeToday(maestro.availableActivateDateTime) ) { return "border-rose-200 bg-rose-50 text-rose-700"; } if (maestro.activateStatus === 2) { return "border-emerald-200 bg-emerald-50 text-emerald-700"; } if (maestro.activateStatus === 100) { return "border-muted bg-muted text-muted-foreground"; } return "border-amber-200 bg-amber-50 text-amber-700"; } function isBeforeToday(value: string) { const date = new Date(value); if (Number.isNaN(date.getTime())) { return false; } const targetDate = new Date(date); const today = new Date(); targetDate.setHours(0, 0, 0, 0); today.setHours(0, 0, 0, 0); return targetDate.getTime() < today.getTime(); }