62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import dayjs from "dayjs";
|
|
import type { ColumnDef } from "@tanstack/react-table";
|
|
import type { Post } from "@/entities/post";
|
|
import { Badge, Button } from "@common/components";
|
|
|
|
export const columns: ColumnDef<Post>[] = [
|
|
{
|
|
id: "no",
|
|
header: "NO",
|
|
cell: ({ row }) => row.index + 1,
|
|
},
|
|
{
|
|
accessorKey: "pstTtl",
|
|
header: "제목",
|
|
cell: ({ row }) => {
|
|
const { pstTtl, inqNocs } = row.original;
|
|
|
|
return (
|
|
<div className="flex min-w-[20vw] items-center gap-2 text-left">
|
|
{inqNocs >= 100 && <Badge color="red">HOT</Badge>}
|
|
{dayjs().diff(dayjs(row.original.regDt), "hour") < 24 && (
|
|
<Badge color="blue">NEW</Badge>
|
|
)}
|
|
{pstTtl}
|
|
</div>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "inqNocs",
|
|
header: "조회수",
|
|
},
|
|
{
|
|
accessorKey: "atflCd",
|
|
header: "첨부파일",
|
|
cell: ({ row }) => {
|
|
const atflCd = row.original.atflCd;
|
|
if (!atflCd) return null;
|
|
return <AttachmentButton atflCd={atflCd} />;
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "rgtrNm",
|
|
header: "작성자",
|
|
},
|
|
{
|
|
accessorKey: "regDt",
|
|
header: "등록일",
|
|
cell: ({ row }) => dayjs(row.original.regDt).format("YYYY-MM-DD"),
|
|
},
|
|
];
|
|
|
|
const AttachmentButton = ({ atflCd }: { atflCd: string }) => {
|
|
if (!atflCd) return null;
|
|
return (
|
|
<Button size="sm" color="white" className="flex items-center gap-2">
|
|
<i className="diveicon di-download" />
|
|
다운로드
|
|
</Button>
|
|
);
|
|
};
|