260617_01_ENH: 배정 테스트를 위해 개발 중도 커밋

This commit is contained in:
2026-06-17 15:56:38 +09:00
parent fcb2c7a270
commit 28da30b865
61 changed files with 5136 additions and 510 deletions

View File

@@ -0,0 +1,220 @@
"use client";
import {useMemo, useRef, useState} from "react";
import {Search} from "lucide-react";
import {Button} from "@/components/ui/button";
import {Input} from "@/components/ui/input";
import {MultiFilterSelect} from "@/components/gwcf/MultiFilterSelect";
import {PagePanel} from "@/components/gwcf/PagePanel";
import {DataTable} from "@/components/data-table/DataTable";
import {DataTableColumn} from "@/components/data-table/DataTable.type";
import {SmsSendDialog} from "@/components/dialog/SmsSendDialog";
import {AssignMonitoringDialog} from "@/components/dialog/AssignMonitoringDialog";
import {useCodesQuery} from "@/query/code";
import {usePerformanceListQuery} from "@/query/performance";
import {
useMonitoringApplyUserCountsQuery,
useMonitoringApplyUsersQuery,
useSaveMonitoringAssignMutation,
} from "@/query/assign";
import {filterPerformance, getCodeLabel} from "@/lib/gwcf/view";
import {MONITORING_ASSIGN_TYPE} from "@/lib/gwcf/performance-status";
import {PerformanceAssign, PerformanceFull} from "@/types/gwcf";
import {useDialog} from "@/hooks/useDialog";
import {useMounted} from "@/hooks/useMounted";
import {LoadingOverlay} from "@/components/common/LoadingOverlay";
import {SMS_TEMPLATE_IDS} from "@/query/notification";
const toParamValue = (value: unknown) => value == null ? "" : String(value);
const buildPerformanceSmsParams = (performance: PerformanceFull): Record<string, string> => ({
businessType: toParamValue(performance.businessType),
performanceGenre: toParamValue(performance.performanceGenre),
performanceArea: toParamValue(performance.performanceArea),
artistName: toParamValue(performance.artistName),
performanceName: toParamValue(performance.performanceName),
performanceStartMonth: toParamValue(performance.performanceStartMonth),
performanceDtInfo: toParamValue(performance.performanceDtInfo),
performanceTimeInfo: toParamValue(performance.performanceTimeInfo),
ticketReservationStatus: toParamValue(performance.ticketReservationStatus),
ticketReservationMemo: toParamValue(performance.ticketReservationMemo),
performanceMemo: toParamValue(performance.performanceMemo),
...Object.fromEntries(
Object.entries(performance.performanceDetail ?? {}).map(([key, value]) => [key, toParamValue(value)])
),
...Object.fromEntries(
Object.entries(performance.performanceMonitoringSchedule ?? {}).map(([key, value]) => [key, toParamValue(value)])
),
performanceId: toParamValue(performance.id),
});
const AssignPage = () => {
const mounted = useMounted();
const {data: codes} = useCodesQuery();
const {isDialogOpen, showDialog, hideDialog} = useDialog();
const {data = [], refetch: refetchPerformanceList} = usePerformanceListQuery();
const {data: applyCounts = [], refetch: refetchApplyCounts} = useMonitoringApplyUserCountsQuery();
const saveAssignMutation = useSaveMonitoringAssignMutation();
const suppressAssignCloseRef = useRef(false);
const [filters, setFilters] = useState({
businessType: [] as string[],
area: [] as string[],
monitoringDate: "",
keyword: "",
});
const [selected, setSelected] = useState<PerformanceFull | null>(null);
const smsAddParam = useMemo(() => selected ? buildPerformanceSmsParams(selected) : {}, [selected]);
const [smsTargetIds, setSmsTargetIds] = useState<string[]>([]);
const refreshAssignList = () => {
void refetchPerformanceList();
void refetchApplyCounts();
};
const updateFilters = (updater: (prev: typeof filters) => typeof filters) => {
setFilters(updater);
refreshAssignList();
};
const assignOpen = isDialogOpen("assignMonitoringDialog");
const smsOpen = isDialogOpen("assignSmsSendDialog");
const selectedPerformanceId = selected?.id ?? 0;
const {data: applyUsers = []} = useMonitoringApplyUsersQuery(selectedPerformanceId, assignOpen && selectedPerformanceId > 0);
const smsTargetUsers = useMemo(
() => applyUsers
.filter((applyUser) => smsTargetIds.includes(applyUser.userId))
.map((applyUser) => applyUser.user),
[applyUsers, smsTargetIds]
);
const applyCountMap = useMemo(() => {
return new Map(applyCounts.map((item) => [String(item.performanceId), item.applyCnt]));
}, [applyCounts]);
const filteredData = useMemo(() => {
return data
.filter((item) => filterPerformance(item, filters))
.sort((a, b) => {
const aDate = a.performanceMonitoringSchedule?.monitoringDate ?? "";
const bDate = b.performanceMonitoringSchedule?.monitoringDate ?? "";
return bDate.localeCompare(aDate);
});
}, [data, filters]);
const openAssign = (performance: PerformanceFull) => {
suppressAssignCloseRef.current = false;
setSelected(performance);
showDialog("assignMonitoringDialog");
};
const applySavedAssignsToSelected = (performanceId: number, monitoringAssigns: PerformanceAssign[]) => {
setSelected((prev) => {
if (!prev || prev.id !== performanceId) return prev;
return {
...prev,
performanceAssignList: [
...(prev.performanceAssignList ?? []).filter((assign) => assign.assignType !== MONITORING_ASSIGN_TYPE),
...monitoringAssigns,
],
};
});
};
const getMonitoringAssigns = (performance: PerformanceFull) => {
return (performance.performanceAssignList ?? []).filter((assign) => assign.assignType === MONITORING_ASSIGN_TYPE);
};
const columns = useMemo<DataTableColumn<PerformanceFull>[]>(() => [
{accessorKey: "id", header: "연번", cell: ({row}) => row.original.id, enableSorting: true},
{accessorKey: "performanceName", header: "사업명", enableSorting: true},
{id: "area", header: "지역", cell: ({row}) => getCodeLabel(codes, "area", row.original.performanceArea)},
{accessorKey: "performanceDtInfo", header: "사업 일정"},
{accessorKey: "performanceTimeInfo", header: "운영 시간"},
{id: "monitoringDate", header: "모니터링 일정", cell: ({row}) => row.original.performanceMonitoringSchedule?.monitoringDate ?? "", enableSorting: true},
{id: "monitoringTime", header: "모니터링 시간", cell: ({row}) => row.original.performanceMonitoringSchedule?.monitoringTimeInfo ?? ""},
{id: "applyCount", header: "신청자 수", cell: ({row}) => applyCountMap.get(String(row.original.id)) ?? 0, enableSorting: true},
{id: "requestCount", header: "확정요청 수", cell: ({row}) => getMonitoringAssigns(row.original).length},
{id: "confirmedCount", header: "확정인원 수", cell: ({row}) => getMonitoringAssigns(row.original).filter((assign) => assign.assignConfirm).length},
], [applyCountMap, codes]);
if(!mounted) return <LoadingOverlay force={true} />
return (
<div className="space-y-4">
<PagePanel>
<div className="grid gap-2 md:grid-cols-[160px_160px_180px_1fr_auto]">
<MultiFilterSelect value={filters.businessType} onChange={(value) => updateFilters((prev) => ({...prev, businessType: value}))} options={codes.business_type} placeholder="사업 유형" />
<MultiFilterSelect value={filters.area} onChange={(value) => updateFilters((prev) => ({...prev, area: value}))} options={codes.area} placeholder="지역" />
<Input type="date" value={filters.monitoringDate} onChange={(event) => updateFilters((prev) => ({...prev, monitoringDate: event.target.value}))} />
<Input value={filters.keyword} onChange={(event) => updateFilters((prev) => ({...prev, keyword: event.target.value}))} placeholder="연번 or 사업명" />
<Button type="button" variant="outline" onClick={refreshAssignList}>
<Search className="h-4 w-4" />
검색
</Button>
</div>
</PagePanel>
<PagePanel className="overflow-x-auto">
<DataTable columns={columns} data={filteredData} getRowId={(row) => String(row.id)} selectMode="click-event" onRowClick={openAssign} defaultPageSize={10} />
</PagePanel>
<AssignMonitoringDialog
open={assignOpen}
onOpenChange={(open) => {
if (open) {
showDialog("assignMonitoringDialog");
return;
}
if (suppressAssignCloseRef.current) return;
hideDialog("assignMonitoringDialog");
refreshAssignList();
}}
selected={selected}
codes={codes}
applyUsers={applyUsers}
isSavingAssign={saveAssignMutation.isPending}
onSaveAssign={(performanceId, userIds) =>
saveAssignMutation.mutate(
{performanceId, userIds},
{onSuccess: (monitoringAssigns) => applySavedAssignsToSelected(performanceId, monitoringAssigns)}
)
}
onOpenSms={(userIds) => {
suppressAssignCloseRef.current = true;
setSmsTargetIds(userIds);
showDialog("assignSmsSendDialog", false);
}}
/>
<SmsSendDialog
open={smsOpen}
onOpenChange={(open) => {
if (open) {
suppressAssignCloseRef.current = true;
showDialog("assignSmsSendDialog", false);
return;
}
hideDialog("assignSmsSendDialog");
refreshAssignList();
window.setTimeout(() => {
suppressAssignCloseRef.current = false;
}, 0);
}}
title="확정 문자 발송"
templateIdx={SMS_TEMPLATE_IDS.ASSIGN_CONFIRM}
newMessageTemplateIdx={SMS_TEMPLATE_IDS.CUSTOM}
selectedUsers={smsTargetUsers}
addParams={smsAddParam}
onSent={refreshAssignList}
/>
</div>
);
};
export default AssignPage;