260812_01_ENH: 배정·진행 현황 개선 및 예약/이벤트 이력 기능 추가

- 프로젝트별 외주사·필드워커 배정 현황 및 미배정 건수 UI 추가
- 현장 면접 진행 여부와 사용자 권한에 따른 배정 탭·필터·컬럼 노출 제어
- 컨택 마지막 이벤트 일자 필터·정렬 및 결과/일자 컬럼 분리
- 컨택·면접·발송 현황의 날짜 범위 선택 optional 처리
- 진행 현황의 미배정 표시 및 일자별 미사용 결과 제외
- 전역 예약 기간 조회·이동 및 5분 단위 예약 알림 추가
- 내부 관리자용 이벤트 이력 단건 삭제 기능 추가
- 리스트 필터 UI 및 일반 헤더 정렬 기준 개선
- 프로젝트 저장 시 선택 프로젝트 정보 동기화
This commit is contained in:
2026-08-12 08:41:27 +09:00
parent e8f3308814
commit 081b53945a
34 changed files with 852 additions and 331 deletions

View File

@@ -0,0 +1,85 @@
"use client";
import { useEffect } from "react";
import { X } from "lucide-react";
import { toast } from "sonner";
import { useAuth } from "@/hooks/useAuth";
import { useDialog } from "@/hooks/useDialog";
import { fetchReserveNotifications } from "@/query/reserve";
const FIVE_MINUTES_MS = 5 * 60_000;
const RESERVE_NOTIFICATION_TOAST_ID = "reserve-notification";
// 예약은 5분 단위로만 등록되므로, 5분 정각(0,5,10,...)에 맞춰 조회해야 창을 놓치지 않는다.
const msUntilNextFiveMinuteMark = (now: Date) => {
const next = new Date(now);
const minutesToNext = 5 - (now.getMinutes() % 5);
next.setMinutes(now.getMinutes() + minutesToNext, 0, 0);
return next.getTime() - now.getTime();
};
export function useReserveNotification() {
const { auth } = useAuth();
const { showDialog } = useDialog();
const userId = auth.user?.userId ?? "";
useEffect(() => {
if (!userId) return;
let intervalId: ReturnType<typeof setInterval> | undefined;
let cancelled = false;
const showNotification = () => {
toast.custom(
(id) => (
<div
className="flex w-[360px] cursor-pointer items-start justify-between gap-3 rounded-lg border border-amber-500 bg-amber-100 p-4 text-amber-900 shadow-md"
onClick={() => {
toast.dismiss(id);
showDialog("reserveSearchDialog");
}}
>
<span className="text-base font-bold">5분 이내에 예약된 내용이 있습니다.</span>
<button
type="button"
aria-label="닫기"
className="shrink-0 cursor-pointer rounded-full p-1 text-amber-900/70 hover:bg-amber-200 hover:text-amber-900"
onClick={(event) => {
event.stopPropagation();
toast.dismiss(id);
}}
>
<X className="size-4" />
</button>
</div>
),
{ id: RESERVE_NOTIFICATION_TOAST_ID, duration: Infinity },
);
};
const poll = async (requestPast: boolean) => {
try {
const reservations = await fetchReserveNotifications(userId, requestPast);
if (cancelled || reservations.length === 0) return;
showNotification();
} catch (error) {
console.error("[reserve-notification] 예약 알림 조회 실패", error);
}
};
void poll(true);
const alignTimeoutId = setTimeout(() => {
if (cancelled) return;
void poll(false);
intervalId = setInterval(() => void poll(false), FIVE_MINUTES_MS);
}, msUntilNextFiveMinuteMark(new Date()));
return () => {
cancelled = true;
clearTimeout(alignTimeoutId);
if (intervalId) clearInterval(intervalId);
};
}, [userId, showDialog]);
}