[feat] negodata: 재협상 소유권 게이팅·처리담당자·상세 링크·재생성 타이틀·알림 토스트(읽음API)·재협상요청 표기·커스텀필드 select

This commit is contained in:
minaChoi committed 2026-07-24 14:18:52 +09:00
1 parent d7c4e86f30
commit 51d07bb779
54 files changed
+2002 -58

No files matched your search

@@ -0,0 +1,107 @@
import { useEffect, useRef } from 'react';
import { useNavigate } from 'react-router';
import { toast } from 'sonner';
import { useQueryClient } from '@tanstack/react-query';
import { useListNotifications, useReadOne } from '@/api/generated/notification/notification';
import { useListRequests } from '@/api/generated/renegotiation/renegotiation';
import { NotificationType } from '@/api/generated/model';
import type { NotificationData } from '@/api/generated/model';
// 하단 우측 토스트로 알릴 알림 = 낙찰·결렬·자동재생성·재협상요청. 단순 생성(CREATED)은 제외.
const TOASTED: number[] = [
NotificationType.SUCCESS,
NotificationType.FAILURE,
NotificationType.REGENERATED,
NotificationType.RENEGO_REQUESTED,
];
function messageFor(n: NotificationData): string {
const d = (n.data ?? {}) as Record<string, unknown>;
const qt = String(d.qt_number ?? d.qt_name ?? '견적');
const winner = d.winner_name ? ` · 낙찰 ${String(d.winner_name)}` : '';
switch (n.type) {
case NotificationType.SUCCESS:
return `${qt} 낙찰되었습니다${winner}.`;
case NotificationType.FAILURE:
return `${qt} 결렬로 마감되었습니다.`;
case NotificationType.REGENERATED:
return `${qt} 다음 라운드가 자동 생성되었습니다.`;
case NotificationType.RENEGO_REQUESTED:
return `${d.supplier_name ? String(d.supplier_name) + ' · ' : ''}${qt} 재협상 요청이 접수됐습니다.`;
default:
return `${qt} 알림.`;
}
}
// sonner 색상 함수 — 재협상요청=경고(앰버), 낙찰=성공, 결렬=에러, 자동마감=정보.
function fireOf(type?: number) {
if (type === NotificationType.SUCCESS) return toast.success;
if (type === NotificationType.FAILURE) return toast.error;
if (type === NotificationType.RENEGO_REQUESTED) return toast.warning;
return toast.info;
}
// 알림 처리(레이아웃 상주, 화면 요소는 토스트로만).
// 새로 도착한 알림만 하단 우측 토스트로 띄우고, [보기]/[X] 로 읽음 처리(readOne API — 알림함과 동일).
// 읽으면 서버 read_at 이 박혀서 다시 뜨지 않고, 벨 배지·인박스 수도 함께 줄어든다.
export function ActionBanner() {
const navigate = useNavigate();
const queryClient = useQueryClient();
const readOne = useReadOne();
const { data: notif } = useListNotifications(
{ size: 20 },
{ query: { refetchInterval: 30_000, staleTime: 10_000 } },
);
// 재협상 요청 토스트는 '아직 완료 안 된(대기중)' 것만 — 내가 처리 가능한(can_act) 대기 세션 집합.
const { data: renego } = useListRequests(
{ status: 1, page: 1, size: 50 },
{ query: { refetchInterval: 30_000, staleTime: 10_000 } },
);
const pendingSessions = new Set(
(renego?.requests ?? []).filter((r) => r.can_act !== false).map((r) => r.session_id),
);
// 읽음 처리(서버) 후 알림 목록 무효화 → 벨 배지·인박스 수가 함께 줄어든다.
const markRead = (id: string) => {
readOne.mutate(
{ notificationId: id },
{ onSuccess: () => queryClient.invalidateQueries({ queryKey: ['/v1/notification/list'], exact: false }) },
);
};
// 새로 도착한 건만 토스트(첫 로드 시점의 안읽음 백로그는 벨/인박스가 담당 — 토스트 폭탄 방지).
const seen = useRef<Set<string> | null>(null);
useEffect(() => {
const rows = (notif?.notifications ?? []).filter((n) => !n.read_at && TOASTED.includes(n.type));
if (seen.current === null) {
seen.current = new Set(rows.map((n) => n.notification_id));
return;
}
for (const n of rows) {
if (seen.current.has(n.notification_id)) continue;
const isRenego = n.type === NotificationType.RENEGO_REQUESTED;
// 재협상 요청은 아직 대기중(미완료)인 세션만 토스트 — 이미 승인/반려된 건 건너뛴다.
if (isRenego && !pendingSessions.has(n.ref_session_id ?? '')) continue;
seen.current.add(n.notification_id);
const target = isRenego ? '/renegotiation' : n.ref_qt_id ? `/quotation?detail=${n.ref_qt_id}` : '/notifications';
fireOf(n.type)(messageFor(n), {
id: n.notification_id,
position: 'bottom-right',
duration: Infinity, // 자동으로 안 사라지고, 읽음/닫기로만 사라진다.
closeButton: true, // X = 닫기 = 읽음 처리(onDismiss).
onDismiss: () => markRead(n.notification_id),
action: {
label: isRenego ? '확인하러 가기' : '보기',
onClick: () => {
markRead(n.notification_id); // 알림함과 동일하게 읽음 API 를 찌른다.
toast.dismiss(n.notification_id);
navigate(target);
},
},
});
}
}, [notif]); // eslint-disable-line react-hooks/exhaustive-deps
return null;
}
@@ -11,6 +11,7 @@ const PAGE_TO_PATH: Record<PageType, string> = {
PARTNERS: '/partners',
QUOTATION: '/quotation',
CARDS: '/cards',
RENEGOTIATION: '/renegotiation',
MEMBERS: '/members',
SETTINGS: '/settings',
DESIGN: '/dev/design',
@@ -10,6 +10,7 @@ import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog';
import { useNavigate } from 'react-router';
import { cn } from '@/lib/utils';
import { NotificationBell } from './NotificationBell';
import { ActionBanner } from './ActionBanner';
import { GUIDE_TABS, TAB_LABEL, type GuideTab } from '@/features/onboarding/OnboardingGuideModal';
import { SETTINGS_TABS, SETTINGS_TAB_LABEL, type SettingsTab } from '@/features/settings/SettingsView';
import {
@@ -27,6 +28,7 @@ import {
Moon,
Building,
Palette,
RefreshCw,
ChevronRight,
Menu,
X,
@@ -60,6 +62,7 @@ const menuGroups: { label?: string; items: MenuItem[] }[] = [
{ type: 'PARTNERS', label: '협력사관리', icon: Users, id: 'sidebar-partners' },
{ type: 'QUOTATION', label: '견적관리', icon: FileSpreadsheet, id: 'sidebar-quotation' },
{ type: 'CARDS', label: '협상카드관리', icon: Layers, id: 'sidebar-cards' },
{ type: 'RENEGOTIATION', label: '재협상 요청', icon: RefreshCw, id: 'sidebar-renegotiation' },
],
},
{
@@ -93,6 +96,7 @@ const pageLabelMap: Record<PageType, string> = {
PARTNERS: '협력사관리',
QUOTATION: '견적관리',
CARDS: '협상카드관리',
RENEGOTIATION: '재협상 요청',
MEMBERS: '회원관리',
SETTINGS: '회사 설정',
DESIGN: '디자인 시스템',
@@ -333,12 +337,15 @@ export default function Layout({ children, currentPage, setPage, onLogout }: Lay
<div className="max-w-7xl mx-auto space-y-6">{children}</div>
</main>
{/* Compact Admin footer info */}
{/* Compact Admin footer info — 액션 배너가 뜨면 가려지지 않게 여백을 준다 */}
<footer className="h-10 border-t border-border/60 bg-card flex items-center justify-between px-4 md:px-8">
<Typography variant="mono">Copyright &copy; O2O Inc. All rights reserved</Typography>
</footer>
</div>
{/* 처리해야 사라지는 알림(재협상 심사 대기 등) — 하단 고정 */}
<ActionBanner />
<CommandMenu
open={isCmdOpen}
onOpenChange={setIsCmdOpen}