import dayjs from "dayjs"; import type { ColumnDef } from "@tanstack/react-table"; import { Badge, Button, Checkbox } from "@common/components"; import { AttachmentApi } from "@/entities/attachment"; import type { Post } from "@/entities/post"; export const columns: ColumnDef[] = [ { id: "select", header: ({ table }) => ( e.stopPropagation()} onCheckedChange={(checked) => table.toggleAllPageRowsSelected(!!checked) } className="h-4 w-4 rounded border-gray-300" /> ), cell: ({ row }) => ( e.stopPropagation()} onCheckedChange={(checked) => row.toggleSelected(!!checked)} className="h-4 w-4 rounded border-gray-300" /> ), }, { accessorKey: "rowNo", header: "NO", cell: ({ row }) => { if (row.original.isUpndFixPost) { return ( ); } return row.original.rowNo; }, }, { accessorKey: "pstTtl", header: "제목", cell: ({ row }) => { const { ansPstn, pstTtl, inqNocs } = row.original; return (
{ansPstn > 0 && (
답변
)} {inqNocs >= 100 && HOT} {dayjs().diff(dayjs(row.original.regDt), "hour") < 24 && ( NEW )} {pstTtl}
); }, }, { accessorKey: "inqNocs", header: "조회수", }, { accessorKey: "atflCd", header: "첨부파일", cell: ({ row }) => { const atflCd = row.original.atflCd; if (!atflCd) return null; return ; }, }, { accessorKey: "rgtrNm", header: "작성자", }, { accessorKey: "regDt", header: "등록일", cell: ({ row }) => dayjs(row.original.regDt).format("YYYY-MM-DD"), }, ]; const AttachmentButton = ({ atflCd }: { atflCd: string }) => { const handleDownload = async (e: React.MouseEvent) => { e.stopPropagation(); try { let filename = ""; const response = await AttachmentApi.downloadAttachmentByAtflCd(atflCd); const contentDisposition = response.headers["content-disposition"]; if (contentDisposition) { const filenameMatch = contentDisposition.match( /filename\*=UTF-8''([^;]+)/, ); if (filenameMatch) { filename = decodeURIComponent(filenameMatch[1]); } } const blob = new Blob([response.data]); const url = window.URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = filename; document.body.appendChild(link); link.click(); window.URL.revokeObjectURL(url); document.body.removeChild(link); } catch (error) { console.error(error); } }; return ( ); };