260617_01_ENH: 배정 테스트를 위해 개발 중도 커밋
This commit is contained in:
218
src/components/dialog/AssignMonitoringDialog.tsx
Normal file
218
src/components/dialog/AssignMonitoringDialog.tsx
Normal file
@@ -0,0 +1,218 @@
|
||||
"use client";
|
||||
|
||||
import {useEffect, useMemo, useState} from "react";
|
||||
import {Send} from "lucide-react";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {Checkbox} from "@/components/ui/checkbox";
|
||||
import {Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle} from "@/components/ui/dialog";
|
||||
import {DataTable} from "@/components/data-table/DataTable";
|
||||
import {DataTableColumn} from "@/components/data-table/DataTable.type";
|
||||
import {StatusPill} from "@/components/gwcf/StatusPill";
|
||||
import {Code, MonitoringApplyUser, PerformanceFull} from "@/types/gwcf";
|
||||
import {CodeGroup} from "@/query/code";
|
||||
import {getCodeLabel, getDetailValue} from "@/lib/gwcf/view";
|
||||
import {getAssignStatusDisplay, MONITORING_ASSIGN_TYPE} from "@/lib/gwcf/performance-status";
|
||||
|
||||
type CodeMap = Partial<Record<CodeGroup, Code[]>>;
|
||||
|
||||
export function AssignMonitoringDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
selected,
|
||||
codes,
|
||||
applyUsers,
|
||||
isSavingAssign,
|
||||
onSaveAssign,
|
||||
onOpenSms,
|
||||
}: Readonly<{
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
selected: PerformanceFull | null;
|
||||
codes: CodeMap;
|
||||
applyUsers: MonitoringApplyUser[];
|
||||
isSavingAssign?: boolean;
|
||||
onSaveAssign: (performanceId: number, userIds: string[]) => void;
|
||||
onOpenSms: (userIds: string[]) => void;
|
||||
}>) {
|
||||
const monitoringAssigns = useMemo(
|
||||
() => (selected?.performanceAssignList ?? []).filter((item) => item.assignType === MONITORING_ASSIGN_TYPE),
|
||||
[selected]
|
||||
);
|
||||
const [checkedIds, setCheckedIds] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) {
|
||||
setCheckedIds([]);
|
||||
return;
|
||||
}
|
||||
|
||||
setCheckedIds(monitoringAssigns.map((item) => item.assignUser));
|
||||
}, [monitoringAssigns, open, selected?.id]);
|
||||
|
||||
const confirmRequestCount = monitoringAssigns.length;
|
||||
const confirmedCount = monitoringAssigns.filter((item) => item.assignConfirm).length;
|
||||
const smsTargetIds = checkedIds.filter(
|
||||
(userId) => !monitoringAssigns.some((assign) => assign.assignUser === userId && assign.assignConfirm)
|
||||
);
|
||||
|
||||
const updateChecked = (applyUser: MonitoringApplyUser, checked: boolean) => {
|
||||
if (!selected || isSavingAssign) return;
|
||||
|
||||
const currentAssign = monitoringAssigns.find((assign) => assign.assignUser === applyUser.userId);
|
||||
|
||||
if (checked) {
|
||||
if (!checkedIds.includes(applyUser.userId) && checkedIds.length >= 2) {
|
||||
alert("모니터링 배정은 최대 2명까지 선택할 수 있습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
const next = Array.from(new Set([...checkedIds, applyUser.userId]));
|
||||
setCheckedIds(next);
|
||||
onSaveAssign(selected.id, next);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentAssign?.assignConfirm) {
|
||||
if (!confirm("이미 승인된 상태입니다. 정말로 취소 하시 겠습니까?")) return;
|
||||
} else if (currentAssign) {
|
||||
if (!confirm("이미 문자 발송된 상태입니다. 정말로 취소 하시 겠습니까?")) return;
|
||||
}
|
||||
|
||||
const next = checkedIds.filter((userId) => userId !== applyUser.userId);
|
||||
setCheckedIds(next);
|
||||
onSaveAssign(selected.id, next);
|
||||
};
|
||||
|
||||
const toggleApplyUser = (applyUser: MonitoringApplyUser) => {
|
||||
updateChecked(applyUser, !checkedIds.includes(applyUser.userId));
|
||||
};
|
||||
|
||||
const columns = useMemo<DataTableColumn<MonitoringApplyUser>[]>(() => [
|
||||
{
|
||||
id: "select",
|
||||
header: "선택",
|
||||
cell: ({row}) => {
|
||||
const applyUser = row.original;
|
||||
const checked = checkedIds.includes(applyUser.userId);
|
||||
const disabled = (!checked && checkedIds.length >= 2) || isSavingAssign;
|
||||
|
||||
return (
|
||||
<Checkbox
|
||||
checked={checked}
|
||||
tabIndex={-1}
|
||||
aria-label="배정 선택 상태"
|
||||
aria-disabled={disabled}
|
||||
className={disabled ? "pointer-events-none opacity-50" : "pointer-events-none"}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "user",
|
||||
header: "신청자",
|
||||
cell: ({row}) => (
|
||||
<div>
|
||||
<div className="font-semibold">{row.original.user?.userName || row.original.userId}</div>
|
||||
<div className="text-xs text-muted-foreground">{row.original.userId}</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "area",
|
||||
header: "지역",
|
||||
cell: ({row}) =>
|
||||
getCodeLabel(codes, "area", getDetailValue(row.original.user?.userDetail, ["area", "userArea", "region"])) || "-",
|
||||
},
|
||||
{
|
||||
id: "tel",
|
||||
header: "연락처",
|
||||
cell: ({row}) => getDetailValue(row.original.user?.userDetail, ["tel", "phone", "userTel"], "-"),
|
||||
},
|
||||
{
|
||||
id: "status",
|
||||
header: "상태",
|
||||
cell: ({row}) => {
|
||||
const assigned = monitoringAssigns.find((item) => item.assignUser === row.original.userId);
|
||||
if (!assigned) return null;
|
||||
|
||||
const display = getAssignStatusDisplay(assigned.assignConfirm);
|
||||
return <StatusPill variant={display.variant}>{display.label}</StatusPill>;
|
||||
},
|
||||
},
|
||||
], [checkedIds, codes, isSavingAssign, monitoringAssigns]);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-h-[90vh] overflow-y-auto sm:max-w-5xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>모니터링 요원 배정</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="grid gap-4 lg:grid-cols-[1fr_1.2fr]">
|
||||
<section className="rounded-md border">
|
||||
<div className="border-b bg-muted px-3 py-2 font-semibold">공연 기본 정보</div>
|
||||
<table className="w-full border-collapse text-sm">
|
||||
<tbody>
|
||||
{[
|
||||
["연번", selected?.id],
|
||||
["사업유형", getCodeLabel(codes, "business_type", selected?.businessType)],
|
||||
["분야(장르)", getCodeLabel(codes, "genre", selected?.performanceGenre)],
|
||||
["지역", getCodeLabel(codes, "area", selected?.performanceArea)],
|
||||
["단체(팀)명", selected?.artistName],
|
||||
["사업명", selected?.performanceName],
|
||||
["사업 일정", selected?.performanceDtInfo],
|
||||
["운영 시간", selected?.performanceTimeInfo],
|
||||
["모니터링 일정", selected?.performanceMonitoringSchedule?.monitoringDate],
|
||||
["모니터링 시간", selected?.performanceMonitoringSchedule?.monitoringTimeInfo],
|
||||
["방문 장소", selected?.performanceMonitoringSchedule?.monitoringAddress],
|
||||
["예매 예약", getCodeLabel(codes, "ticket_reservation_status", selected?.ticketReservationStatus)],
|
||||
["예매 비고", selected?.ticketReservationMemo],
|
||||
].map(([label, value]) => (
|
||||
<tr key={String(label)}>
|
||||
<th className="w-32 border bg-muted p-2 text-left">{label}</th>
|
||||
<td className="border p-2">{value || "-"}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section className="space-y-3 rounded-md border p-3">
|
||||
<div className="grid grid-cols-3 rounded-md border text-center text-sm">
|
||||
<div className="p-2">
|
||||
<div className="text-muted-foreground">신청자</div>
|
||||
<div className="font-semibold">{applyUsers.length}</div>
|
||||
</div>
|
||||
<div className="border-x p-2">
|
||||
<div className="text-muted-foreground">확정요청</div>
|
||||
<div className="font-semibold">{confirmRequestCount}</div>
|
||||
</div>
|
||||
<div className="p-2">
|
||||
<div className="text-muted-foreground">확정</div>
|
||||
<div className="font-semibold">{confirmedCount}</div>
|
||||
</div>
|
||||
</div>
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={applyUsers}
|
||||
getRowId={(row) => row.userId}
|
||||
defaultPageSize={applyUsers.length || 10}
|
||||
pageSizeOptions={[applyUsers.length || 10]}
|
||||
showPagination={false}
|
||||
selectMode="click-event"
|
||||
onRowClick={toggleApplyUser}
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" disabled={smsTargetIds.length === 0} onClick={() => onOpenSms(smsTargetIds)}>
|
||||
<Send className="h-4 w-4" />
|
||||
확정 문자 발송
|
||||
</Button>
|
||||
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>닫기</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user