260427_01_ENH: 리스트 다이얼로그 및 리스트 작업 시작
This commit is contained in:
179
src/components/table-column/ListTableColumn.tsx
Normal file
179
src/components/table-column/ListTableColumn.tsx
Normal file
@@ -0,0 +1,179 @@
|
||||
import { DataTableColumn } from "@/components/data-table/DataTable.type";
|
||||
import {ListContactResult, listHeader, ListResultBase, ListSendResult} from "@/types/list";
|
||||
import { ListHeaderAssignConst, ListHeaderConst } from "@/const/listConst";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { formatKst } from "@/lib/utils";
|
||||
import { ResultCode, ResultCodeType } from "@/types/project";
|
||||
|
||||
export type ListTableRow = Record<string, unknown>;
|
||||
|
||||
const getAssignColumns = (userRole: number): DataTableColumn<ListTableRow>[] => {
|
||||
const targets: Array<{ id: string; header: string; key: number }> = [];
|
||||
|
||||
if (userRole < 9000) {
|
||||
targets.push(
|
||||
{ id: "assignOutsource", header: "외주 SV", key: ListHeaderAssignConst.OUTSOURCE },
|
||||
{ id: "assignContactInterviewer", header: "컨택원", key: ListHeaderAssignConst.CONTACT_INTERVIEWER },
|
||||
{ id: "assignFieldInterviewer", header: "면접원", key: ListHeaderAssignConst.FIELD_INTERVIEWER }
|
||||
);
|
||||
} else if (userRole === 9002) {
|
||||
targets.push({
|
||||
id: "assignContactInterviewer",
|
||||
header: "컨택원",
|
||||
key: ListHeaderAssignConst.CONTACT_INTERVIEWER,
|
||||
});
|
||||
} else if (userRole === 9003) {
|
||||
targets.push({
|
||||
id: "assignFieldInterviewer",
|
||||
header: "면접원",
|
||||
key: ListHeaderAssignConst.FIELD_INTERVIEWER,
|
||||
});
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<ListTableRow>[] = [];
|
||||
targets.forEach((target) => {
|
||||
columns.push({
|
||||
id: target.id,
|
||||
header: target.header,
|
||||
accessorFn: (row) => (row.assignList as Record<number, string> | undefined)?.[target.key] ?? "",
|
||||
enableSorting: false,
|
||||
});
|
||||
});
|
||||
|
||||
return columns;
|
||||
};
|
||||
|
||||
const getResultColumns = (resultCodeArray: ResultCode[]): DataTableColumn<ListTableRow>[] => {
|
||||
const labelByTypeCode = new Map<string, string>();
|
||||
resultCodeArray.forEach((item) => {
|
||||
labelByTypeCode.set(`${item.resultCdTy}:${item.resultCd}`, item.resultCdLbl);
|
||||
});
|
||||
|
||||
const getResultLabel = (resultType: ResultCodeType, result?: ListResultBase) => {
|
||||
const lastResultCd = result?.lastResultCd;
|
||||
if (lastResultCd === undefined) return "";
|
||||
|
||||
return labelByTypeCode.get(`${resultType}:${lastResultCd}`) ?? "";
|
||||
}
|
||||
|
||||
const formatResult = (resultType: ResultCodeType, result?: ListContactResult) => {
|
||||
const lastResultCd = result?.lastResultCd;
|
||||
if (lastResultCd === undefined) return "";
|
||||
|
||||
const label = getResultLabel(resultType, result);
|
||||
const count = result?.attemptCount ?? 0;
|
||||
const dt = `(${formatKst(result?.lastResultDt ?? "", "dateHourMin")})`;
|
||||
const resultText = `${lastResultCd}. ${label} (${count}회)`;
|
||||
|
||||
return (
|
||||
<div className="leading-tight">
|
||||
<div>{resultText}</div>
|
||||
<div>{dt}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const formatSendResult = (result?: ListSendResult) => {
|
||||
const label = result?.lastResultLabel ?? "";
|
||||
const dt = `(${formatKst(result?.lastResultDt ?? "", "dateHourMin")})`;
|
||||
|
||||
return (
|
||||
<div className="leading-tight">
|
||||
<div>{label}</div>
|
||||
<div>{dt}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
const columns: DataTableColumn<ListTableRow>[] = [
|
||||
{
|
||||
id: "contactResult",
|
||||
header: "컨택 결과",
|
||||
cell: ({ row }) =>
|
||||
formatResult(ResultCodeType.CONTACT, row.original.contactResult as ListContactResult | undefined),
|
||||
enableSorting: false,
|
||||
},
|
||||
{
|
||||
id: "mailSendResult",
|
||||
header: "email 발송 결과",
|
||||
cell: ({ row }) =>
|
||||
formatSendResult(row.original.emailSendResult as ListSendResult | undefined),
|
||||
enableSorting: false,
|
||||
},
|
||||
{
|
||||
id: "smsSendResult",
|
||||
header: "문자 발송 결과",
|
||||
cell: ({ row }) =>
|
||||
formatSendResult(row.original.smsSendResult as ListSendResult | undefined),
|
||||
enableSorting: false,
|
||||
},
|
||||
{
|
||||
id: "interviewResult",
|
||||
header: "면접 결과",
|
||||
cell: ({ row }) =>
|
||||
formatResult(ResultCodeType.INTERVIEW, row.original.interviewResult as ListContactResult | undefined),
|
||||
enableSorting: false,
|
||||
},
|
||||
{
|
||||
id: "surveyStatus",
|
||||
header: "설문 진행 상태",
|
||||
accessorFn: (row) => getResultLabel(ResultCodeType.SURVEY, row.surveyResult as ListResultBase | undefined),
|
||||
enableSorting: false,
|
||||
},
|
||||
];
|
||||
|
||||
return columns;
|
||||
};
|
||||
|
||||
export const getListColumns = (
|
||||
listHeaders: listHeader[],
|
||||
resultCodeArray: ResultCode[],
|
||||
userRole: number
|
||||
): DataTableColumn<ListTableRow>[] => {
|
||||
const visibleHeaders = listHeaders.filter((header) => {
|
||||
if (!header.useColView) return false;
|
||||
if (header.listHderTy === ListHeaderConst.SID) return true;
|
||||
|
||||
if (
|
||||
header.listHderTy === ListHeaderAssignConst.OUTSOURCE ||
|
||||
header.listHderTy === ListHeaderAssignConst.CONTACT_INTERVIEWER ||
|
||||
header.listHderTy === ListHeaderAssignConst.FIELD_INTERVIEWER
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (userRole >= 9000) return header.useIntrvwerView;
|
||||
return true;
|
||||
});
|
||||
|
||||
const headerColumns: DataTableColumn<ListTableRow>[] = visibleHeaders.map((header) => ({
|
||||
accessorKey: String(header.listHderId),
|
||||
header: header.listHderNm,
|
||||
enableSorting: true,
|
||||
}));
|
||||
|
||||
const startLabel = userRole === 9003 ? "면접 시작" : "컨택 시작";
|
||||
const startColumn: DataTableColumn<ListTableRow> = {
|
||||
id: "contactStart",
|
||||
header: startLabel,
|
||||
cell: () => (
|
||||
<Button size="sm" variant="outline" className="h-8 px-2">
|
||||
{startLabel}
|
||||
</Button>
|
||||
),
|
||||
enableSorting: false,
|
||||
};
|
||||
|
||||
const sidColumnIndex = visibleHeaders.findIndex((header) => header.listHderTy === ListHeaderConst.SID);
|
||||
if (sidColumnIndex < 0) {
|
||||
headerColumns.unshift(startColumn);
|
||||
} else {
|
||||
headerColumns.splice(sidColumnIndex + 1, 0, startColumn);
|
||||
}
|
||||
|
||||
const resultColumns = getResultColumns(resultCodeArray);
|
||||
const assignColumns = userRole < 9000 ? getAssignColumns(userRole) : [];
|
||||
|
||||
return [...headerColumns, ...resultColumns, ...assignColumns];
|
||||
};
|
||||
Reference in New Issue
Block a user