- 프로젝트별 외주사·필드워커 배정 현황 및 미배정 건수 UI 추가 - 현장 면접 진행 여부와 사용자 권한에 따른 배정 탭·필터·컬럼 노출 제어 - 컨택 마지막 이벤트 일자 필터·정렬 및 결과/일자 컬럼 분리 - 컨택·면접·발송 현황의 날짜 범위 선택 optional 처리 - 진행 현황의 미배정 표시 및 일자별 미사용 결과 제외 - 전역 예약 기간 조회·이동 및 5분 단위 예약 알림 추가 - 내부 관리자용 이벤트 이력 단건 삭제 기능 추가 - 리스트 필터 UI 및 일반 헤더 정렬 기준 개선 - 프로젝트 저장 시 선택 프로젝트 정보 동기화
216 lines
7.5 KiB
TypeScript
216 lines
7.5 KiB
TypeScript
import { DataTableColumn } from "@/components/data-table/DataTable.type";
|
|
import {ListContactResult, listHeader, ListIsUse, ListResultBase, ListSendResult, SurveyResult} from "@/types/list";
|
|
import { ListHeaderConst, ListHeaderDefaultConst, ListHeaderDefaultFieldConst } from "@/const/listConst";
|
|
import { formatKst } from "@kri/common";
|
|
import { formatKoreanPhoneNumber } from "@/utils/phone";
|
|
import { ProjectSurvey, ResultCode, ResultCodeType } from "@/types/project";
|
|
import { isListHeaderVisibleByAccess } from "@/utils/listAccess";
|
|
|
|
export type ListTableRow = Record<string, unknown>;
|
|
|
|
const DEFAULT_FIELD_BY_HEADER_TYPE: Record<number, string | undefined> = ListHeaderDefaultFieldConst;
|
|
|
|
export const LIST_IS_USE_LABEL: Record<ListIsUse, string> = {
|
|
[ListIsUse.UNUSABLE]: "불가",
|
|
[ListIsUse.USABLE]: "허용",
|
|
[ListIsUse.TEST]: "테스트",
|
|
};
|
|
|
|
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 formatResult = (
|
|
result?: ListResultBase,
|
|
options?: { resultType?: ResultCodeType; showCount?: boolean; showDate?: boolean },
|
|
) => {
|
|
const lastResultCd = result?.lastResultCd;
|
|
if (lastResultCd === undefined) return "";
|
|
|
|
const fallbackLabel =
|
|
options?.resultType !== undefined ? labelByTypeCode.get(`${options.resultType}:${lastResultCd}`) ?? "" : "";
|
|
const label = result?.lastResultViewLabel || fallbackLabel;
|
|
const showCount = options?.showCount ?? true;
|
|
const showDate = options?.showDate ?? true;
|
|
const count = result?.attemptCount ?? 0;
|
|
const resultText = showCount ? `${lastResultCd}. ${label} (${count}회)` : `${lastResultCd}. ${label}`;
|
|
const dt = result?.lastResultDt ? formatKst(result.lastResultDt, "dateHourMin") : "";
|
|
|
|
return (
|
|
<div className="leading-tight">
|
|
<div>{resultText}</div>
|
|
{showDate && dt && <div>({dt})</div>}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
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>{`${result.lastResultCd}. ${fallbackLabel}`}</div>
|
|
{dt && <div>({dt})</div>}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const columns: DataTableColumn<ListTableRow>[] = [
|
|
{
|
|
id: "result-contact",
|
|
header: "컨택 결과",
|
|
accessorFn: (row) => (row.contactResult as ListContactResult | undefined)?.lastResultCd ?? null,
|
|
cell: ({ row }) =>
|
|
formatResult(row.original.contactResult as ListContactResult | undefined, {
|
|
resultType: ResultCodeType.CONTACT,
|
|
showDate: false,
|
|
}),
|
|
enableSorting: true,
|
|
},
|
|
{
|
|
id: "result-date-contact",
|
|
header: "컨택 일자",
|
|
accessorFn: (row) => (row.contactResult as ListContactResult | undefined)?.lastResultDt ?? null,
|
|
cell: ({ row }) => {
|
|
const lastResultDt = (row.original.contactResult as ListContactResult | undefined)?.lastResultDt;
|
|
return lastResultDt ? formatKst(lastResultDt, "dateHourMin") : "";
|
|
},
|
|
enableSorting: true,
|
|
},
|
|
{
|
|
id: "mailSendResult",
|
|
header: "email 발송 결과",
|
|
cell: ({ row }) =>
|
|
formatResult(row.original.mailSendResult as ListSendResult | undefined),
|
|
enableSorting: false,
|
|
},
|
|
{
|
|
id: "smsSendResult",
|
|
header: "문자 발송 결과",
|
|
cell: ({ row }) =>
|
|
formatResult(row.original.smsSendResult as ListSendResult | undefined),
|
|
enableSorting: false,
|
|
},
|
|
{
|
|
id: "result-interview",
|
|
header: "면접 결과",
|
|
accessorFn: (row) => (row.interviewResult as ListContactResult | undefined)?.lastResultCd ?? null,
|
|
cell: ({ row }) =>
|
|
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([
|
|
["result-contact", 0],
|
|
["result-date-contact", 1],
|
|
["result-interview", 2],
|
|
["mailSendResult", 4],
|
|
["smsSendResult", 5],
|
|
]);
|
|
|
|
return columns.sort((a, b) => (resultColumnOrder.get(a.id ?? "") ?? 2) - (resultColumnOrder.get(b.id ?? "") ?? 2));
|
|
};
|
|
|
|
export const getListColumns = (
|
|
listHeaders: listHeader[],
|
|
resultCodeArray: ResultCode[],
|
|
userRole: number,
|
|
surveys: ProjectSurvey[]
|
|
): DataTableColumn<ListTableRow>[] => {
|
|
const visibleHeaders = listHeaders
|
|
.filter((header) => isListHeaderVisibleByAccess(header, userRole))
|
|
.sort((a, b) => a.listHderOrder - b.listHderOrder);
|
|
|
|
const headerColumns: DataTableColumn<ListTableRow>[] = visibleHeaders.map((header) => {
|
|
const field = DEFAULT_FIELD_BY_HEADER_TYPE[header.listHderTy];
|
|
|
|
if (field === ListHeaderDefaultFieldConst[ListHeaderDefaultConst.OUTSOURCE]) {
|
|
return {
|
|
id: `assign-${header.listHderTy}`,
|
|
header: header.listHderNm,
|
|
accessorFn: (row) => (row.assignList as Record<number, string> | undefined)?.[header.listHderTy] ?? "",
|
|
enableSorting: true,
|
|
};
|
|
}
|
|
|
|
if (field === ListHeaderDefaultFieldConst[ListHeaderDefaultConst.IS_USE]) {
|
|
return {
|
|
id: field,
|
|
header: header.listHderNm,
|
|
accessorFn: (row) => LIST_IS_USE_LABEL[row[field] as ListIsUse] ?? "",
|
|
enableSorting: true,
|
|
};
|
|
}
|
|
|
|
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,
|
|
header: header.listHderNm,
|
|
accessorFn: (row) => row[field] ?? "",
|
|
enableSorting: true,
|
|
};
|
|
}
|
|
|
|
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}`,
|
|
header: header.listHderNm,
|
|
accessorFn: (row) => (row[String(header.listHderId)] ? "업로드O" : ""),
|
|
enableSorting: false,
|
|
};
|
|
}
|
|
|
|
return {
|
|
accessorKey: String(header.listHderId),
|
|
header: header.listHderNm,
|
|
enableSorting: true,
|
|
};
|
|
});
|
|
|
|
const resultColumns = getResultColumns(resultCodeArray, surveys);
|
|
|
|
return [...headerColumns, ...resultColumns];
|
|
};
|