Files
frontend/apps/st/src/components/util/column/management/GeneralVerificationColumn.tsx
T

137 lines
3.8 KiB
TypeScript

import { useState } from "react";
import type { ColumnDef } from "@tanstack/react-table";
import dayjs from "dayjs";
import type { GeneralverificationList } from "@/entities/statistics/model/general-verification-interface";
import { Button } from "@common/components";
import CopyDialog from "@/components/statistics/verification/generalVerification/CopyDialog";
import RegistDialog from "@/components/statistics/verification/generalVerification/RegistDialog";
export const getGeneralVerificationColumns = (
onUpdateSuccess?: () => void,
options?: { mutationBlocked?: boolean; blockedMessage?: string | null },
): ColumnDef<GeneralverificationList>[] => [
{
id: "no",
header: "NO",
cell: ({ row, table }) => {
const totalRows = table.getRowCount();
const { pageIndex, pageSize } = table.getState().pagination;
return totalRows - (pageIndex * pageSize + row.index);
},
},
{
accessorKey: "trgtStatsNm",
header: "통계항목",
},
{
accessorKey: "vrfcNm",
header: "검증명",
},
{
accessorKey: "vrfcClsfNm",
header: "검증 분류",
},
{
accessorKey: "useYn",
header: "사용 여부",
},
{
accessorKey: "regDt",
header: "등록일",
cell: ({ row }) => {
const date = dayjs(row.original.regDt);
return date.format("YYYY-MM-DD");
},
},
{
id: "copy",
header: "복사",
cell: ({ row }) => (
<div onClick={(e) => e.stopPropagation()}>
<GeneralVerificationCopyButton
row={row.original}
onSuccess={onUpdateSuccess}
mutationBlocked={options?.mutationBlocked}
blockedMessage={options?.blockedMessage}
/>
</div>
),
},
{
id: "actions",
header: "관리",
cell: ({ row }) => (
<div onClick={(e) => e.stopPropagation()}>
<GeneralVerificationManageButton
vrfcSn={row.original.vrfcSn}
onSuccess={onUpdateSuccess}
mutationBlocked={options?.mutationBlocked}
blockedMessage={options?.blockedMessage}
/>
</div>
),
},
];
const GeneralVerificationManageButton = ({
vrfcSn,
onSuccess,
mutationBlocked,
blockedMessage,
}: {
vrfcSn: number;
onSuccess?: () => void;
mutationBlocked?: boolean;
blockedMessage?: string | null;
}) => {
const [dialogOpen, setDialogOpen] = useState(false);
return (
<RegistDialog
open={dialogOpen}
onOpenChange={setDialogOpen}
vrfcSn={vrfcSn}
onSuccess={onSuccess}
mutationBlocked={mutationBlocked}
blockedMessage={blockedMessage}
>
<Button size="sm">관리</Button>
</RegistDialog>
);
};
const GeneralVerificationCopyButton = ({
row,
onSuccess,
mutationBlocked,
blockedMessage,
}: {
row: GeneralverificationList;
onSuccess?: () => void;
mutationBlocked?: boolean;
blockedMessage?: string | null;
}) => {
const [dialogOpen, setDialogOpen] = useState(false);
if (mutationBlocked) {
return (
<span title={blockedMessage ?? undefined}>
<Button size="sm" color="white" disabled type="button">
복사
</Button>
</span>
);
}
return (
<CopyDialog
open={dialogOpen}
onOpenChange={setDialogOpen}
row={row}
onSuccess={onSuccess}
>
<Button size="sm" color="white">복사</Button>
</CopyDialog>
);
};