|
|
|
|
@@ -1,8 +1,9 @@
|
|
|
|
|
import { DataTableColumn } from "@/components/data-table/DataTable.type";
|
|
|
|
|
import {ListContactResult, listHeader, ListIsUse, ListResultBase, ListSendResult} from "@/types/list";
|
|
|
|
|
import {ListContactResult, listHeader, ListIsUse, ListResultBase, ListSendResult, SurveyResult} from "@/types/list";
|
|
|
|
|
import { ListHeaderConst, ListHeaderDefaultConst, ListHeaderDefaultFieldConst } from "@/const/listConst";
|
|
|
|
|
import { formatKst } from "@kri/common";
|
|
|
|
|
import { ResultCode, ResultCodeType } from "@/types/project";
|
|
|
|
|
import { formatKoreanPhoneNumber } from "@/utils/phone";
|
|
|
|
|
import { ProjectSurvey, ResultCode, ResultCodeType } from "@/types/project";
|
|
|
|
|
import { isListHeaderVisibleByAccess } from "@/utils/listAccess";
|
|
|
|
|
|
|
|
|
|
export type ListTableRow = Record<string, unknown>;
|
|
|
|
|
@@ -15,117 +16,111 @@ export const LIST_IS_USE_LABEL: Record<ListIsUse, string> = {
|
|
|
|
|
[ListIsUse.TEST]: "테스트",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getResultColumns = (resultCodeArray: ResultCode[]): DataTableColumn<ListTableRow>[] => {
|
|
|
|
|
const getResultColumns = (resultCodeArray: ResultCode[], surveys: ProjectSurvey[]): 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 formatResult = (
|
|
|
|
|
result?: ListResultBase,
|
|
|
|
|
options?: { resultType?: ResultCodeType; showCount?: boolean },
|
|
|
|
|
) => {
|
|
|
|
|
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 fallbackLabel =
|
|
|
|
|
options?.resultType !== undefined ? labelByTypeCode.get(`${options.resultType}:${lastResultCd}`) ?? "" : "";
|
|
|
|
|
const label = result?.lastResultViewLabel || fallbackLabel;
|
|
|
|
|
const showCount = options?.showCount ?? true;
|
|
|
|
|
const count = result?.attemptCount ?? 0;
|
|
|
|
|
const dt = `(${formatKst(result?.lastResultDt ?? "", "dateHourMin")})`;
|
|
|
|
|
const resultText = `${lastResultCd}. ${label} (${count}회)`;
|
|
|
|
|
const resultText = showCount ? `${lastResultCd}. ${label} (${count}회)` : `${lastResultCd}. ${label}`;
|
|
|
|
|
const dt = result?.lastResultDt ? formatKst(result.lastResultDt, "dateHourMin") : "";
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="leading-tight">
|
|
|
|
|
<div>{resultText}</div>
|
|
|
|
|
<div>{dt}</div>
|
|
|
|
|
{dt && <div>({dt})</div>}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const formatSendResult = (result?: ListSendResult) => {
|
|
|
|
|
const label = result?.lastResultLabel ?? "";
|
|
|
|
|
const dt = `(${formatKst(result?.lastResultDt ?? "", "dateHourMin")})`;
|
|
|
|
|
const formatSurveyResult = (result?: SurveyResult) => {
|
|
|
|
|
if (result === undefined) return "";
|
|
|
|
|
|
|
|
|
|
const fallbackLabel = labelByTypeCode.get(`${ResultCodeType.SURVEY}:${result.lastResultCd}`) ?? "";
|
|
|
|
|
const dt = result.lastResultDt ? formatKst(result.lastResultDt, "dateHourMin") : "";
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="leading-tight">
|
|
|
|
|
<div>{label}</div>
|
|
|
|
|
<div>{dt}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="leading-tight">
|
|
|
|
|
<div>{`${result.lastResultCd}. ${fallbackLabel}`}</div>
|
|
|
|
|
{dt && <div>({dt})</div>}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const formatSurveyResult = (result?: ListResultBase) => {
|
|
|
|
|
const lastResultCd = result?.lastResultCd;
|
|
|
|
|
if (lastResultCd === undefined) return "";
|
|
|
|
|
|
|
|
|
|
const label = getResultLabel(ResultCodeType.SURVEY, result);
|
|
|
|
|
const dt = `(${formatKst(result?.lastResultDt ?? "", "dateHourMin")})`;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="leading-tight">
|
|
|
|
|
<div>{label}</div>
|
|
|
|
|
<div>{dt}</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const columns: DataTableColumn<ListTableRow>[] = [
|
|
|
|
|
{
|
|
|
|
|
id: "contactResult",
|
|
|
|
|
id: "result-contact",
|
|
|
|
|
header: "컨택 결과",
|
|
|
|
|
accessorFn: (row) => (row.contactResult as ListContactResult | undefined)?.lastResultCd ?? null,
|
|
|
|
|
cell: ({ row }) =>
|
|
|
|
|
formatResult(ResultCodeType.CONTACT, row.original.contactResult as ListContactResult | undefined),
|
|
|
|
|
enableSorting: false,
|
|
|
|
|
formatResult(row.original.contactResult as ListContactResult | undefined, { resultType: ResultCodeType.CONTACT }),
|
|
|
|
|
enableSorting: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "mailSendResult",
|
|
|
|
|
header: "email 발송 결과",
|
|
|
|
|
cell: ({ row }) =>
|
|
|
|
|
formatSendResult(row.original.mailSendResult as ListSendResult | undefined),
|
|
|
|
|
formatResult(row.original.mailSendResult as ListSendResult | undefined),
|
|
|
|
|
enableSorting: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "smsSendResult",
|
|
|
|
|
header: "문자 발송 결과",
|
|
|
|
|
cell: ({ row }) =>
|
|
|
|
|
formatSendResult(row.original.smsSendResult as ListSendResult | undefined),
|
|
|
|
|
formatResult(row.original.smsSendResult as ListSendResult | undefined),
|
|
|
|
|
enableSorting: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "interviewResult",
|
|
|
|
|
id: "result-interview",
|
|
|
|
|
header: "면접 결과",
|
|
|
|
|
accessorFn: (row) => (row.interviewResult as ListContactResult | undefined)?.lastResultCd ?? null,
|
|
|
|
|
cell: ({ row }) =>
|
|
|
|
|
formatResult(ResultCodeType.INTERVIEW, row.original.interviewResult as ListContactResult | undefined),
|
|
|
|
|
enableSorting: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "surveyStatus",
|
|
|
|
|
header: "설문 진행 상태",
|
|
|
|
|
cell: ({ row }) =>
|
|
|
|
|
formatSurveyResult(row.original.surveyResult as ListResultBase | undefined),
|
|
|
|
|
enableSorting: false,
|
|
|
|
|
formatResult(row.original.interviewResult as ListContactResult | undefined, { resultType: ResultCodeType.INTERVIEW }),
|
|
|
|
|
enableSorting: true,
|
|
|
|
|
},
|
|
|
|
|
...surveys.map((survey): DataTableColumn<ListTableRow> => ({
|
|
|
|
|
id: `result-survey-${survey.prjctSurveyIdx}`,
|
|
|
|
|
header: survey.surveyName,
|
|
|
|
|
accessorFn: (row) => {
|
|
|
|
|
const surveyResults = (row.surveyResults as SurveyResult[] | undefined) ?? [];
|
|
|
|
|
return surveyResults.find((item) => item.prjctSurveyIdx === survey.prjctSurveyIdx)?.lastResultCd ?? null;
|
|
|
|
|
},
|
|
|
|
|
cell: ({ row }) => {
|
|
|
|
|
const surveyResults = (row.original.surveyResults as SurveyResult[] | undefined) ?? [];
|
|
|
|
|
const result = surveyResults.find((item) => item.prjctSurveyIdx === survey.prjctSurveyIdx);
|
|
|
|
|
return formatSurveyResult(result);
|
|
|
|
|
},
|
|
|
|
|
enableSorting: true,
|
|
|
|
|
})),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const resultColumnOrder = new Map([
|
|
|
|
|
["contactResult", 0],
|
|
|
|
|
["interviewResult", 1],
|
|
|
|
|
["surveyStatus", 2],
|
|
|
|
|
["result-contact", 0],
|
|
|
|
|
["result-interview", 1],
|
|
|
|
|
["mailSendResult", 3],
|
|
|
|
|
["smsSendResult", 4],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return columns.sort((a, b) => (resultColumnOrder.get(a.id ?? "") ?? 0) - (resultColumnOrder.get(b.id ?? "") ?? 0));
|
|
|
|
|
return columns.sort((a, b) => (resultColumnOrder.get(a.id ?? "") ?? 2) - (resultColumnOrder.get(b.id ?? "") ?? 2));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getListColumns = (
|
|
|
|
|
listHeaders: listHeader[],
|
|
|
|
|
resultCodeArray: ResultCode[],
|
|
|
|
|
userRole: number
|
|
|
|
|
userRole: number,
|
|
|
|
|
surveys: ProjectSurvey[]
|
|
|
|
|
): DataTableColumn<ListTableRow>[] => {
|
|
|
|
|
const visibleHeaders = listHeaders
|
|
|
|
|
.filter((header) => isListHeaderVisibleByAccess(header, userRole))
|
|
|
|
|
@@ -139,7 +134,7 @@ export const getListColumns = (
|
|
|
|
|
id: `assign-${header.listHderTy}`,
|
|
|
|
|
header: header.listHderNm,
|
|
|
|
|
accessorFn: (row) => (row.assignList as Record<number, string> | undefined)?.[header.listHderTy] ?? "",
|
|
|
|
|
enableSorting: false,
|
|
|
|
|
enableSorting: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -152,6 +147,18 @@ export const getListColumns = (
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(field === ListHeaderDefaultFieldConst[ListHeaderDefaultConst.MEMO]){
|
|
|
|
|
return {
|
|
|
|
|
id: field,
|
|
|
|
|
header: header.listHderNm,
|
|
|
|
|
accessorFn: (row) => row[field] ?? "",
|
|
|
|
|
meta: {
|
|
|
|
|
maxWidth: 200,
|
|
|
|
|
},
|
|
|
|
|
enableSorting: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (field) {
|
|
|
|
|
return {
|
|
|
|
|
id: field,
|
|
|
|
|
@@ -161,6 +168,16 @@ export const getListColumns = (
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (header.listHderTy === ListHeaderConst.TEL_NUM) {
|
|
|
|
|
return {
|
|
|
|
|
id: String(header.listHderId),
|
|
|
|
|
header: header.listHderNm,
|
|
|
|
|
accessorFn: (row) => row[String(header.listHderId)] ?? "",
|
|
|
|
|
cell: ({ row }) => formatKoreanPhoneNumber(String(row.original[String(header.listHderId)] ?? "")),
|
|
|
|
|
enableSorting: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (header.listHderTy === ListHeaderConst.FILE) {
|
|
|
|
|
return {
|
|
|
|
|
id: `file-${header.listHderId}`,
|
|
|
|
|
@@ -177,7 +194,7 @@ export const getListColumns = (
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const resultColumns = getResultColumns(resultCodeArray);
|
|
|
|
|
const resultColumns = getResultColumns(resultCodeArray, surveys);
|
|
|
|
|
|
|
|
|
|
return [...headerColumns, ...resultColumns];
|
|
|
|
|
};
|
|
|
|
|
|