Files
frontend/apps/cs/src/pages/popup/model/table-columns.tsx
T

101 lines
2.5 KiB
TypeScript

import dayjs from "dayjs";
import { type ColumnDef } from "@tanstack/react-table";
import { Button, Checkbox } from "@common/components";
import { PopupApi } from "../api/popup-service";
import type { Popup } from "./popup-interface";
export const columns: ColumnDef<Popup>[] = [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={table.getIsAllPageRowsSelected()}
onClick={(e) => e.stopPropagation()}
onCheckedChange={(checked) =>
table.toggleAllPageRowsSelected(!!checked)
}
className="h-4 w-4 rounded border-gray-300"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onClick={(e) => e.stopPropagation()}
onCheckedChange={(checked) => row.toggleSelected(!!checked)}
className="h-4 w-4 rounded border-gray-300"
/>
),
},
{
id: "no",
header: "NO",
cell: ({ row, table }) => {
const { pageIndex, pageSize } = table.getState().pagination;
const totalRows = table.getRowCount();
return totalRows - (pageIndex * pageSize + row.index);
},
},
{
accessorKey: "popupTtl",
header: "제목",
},
{
accessorKey: "popupTypeNm",
header: "팝업유형",
},
{
accessorKey: "contsTypeNm",
header: "콘텐츠유형",
},
{
accessorKey: "useYn",
header: "사용여부",
},
{
accessorKey: "mdfcnDt",
header: "최종수정일",
cell: ({ row }) => {
const date = dayjs(row.original.mdfcnDt);
return date.format("YYYY-MM-DD");
},
},
{
accessorKey: "mdfrNm",
header: "최종수정자",
},
{
id: "preview",
header: "미리보기",
cell: ({ row }) => <PreviewButton popupSn={row.original.popupSn} />,
},
];
const PreviewButton = ({ popupSn }: { popupSn: number }) => {
const handlePreview = async (e: React.MouseEvent) => {
e.stopPropagation();
try {
const response = await PopupApi.getPopupInfo(popupSn);
if (!response) return;
const width = response.popupWdth;
const height = response.popupHgt;
const left = response.popupHrzntltyPstn + window.screenX;
const top = response.popupVtclPstn + window.screenY;
window.open(
`/view/popup/${popupSn}`,
"",
`width=${width},height=${height},left=${left},top=${top}`,
);
} catch (error) {
console.error(error);
}
};
return (
<Button size="sm" onClick={handlePreview}>
미리보기
</Button>
);
};