[chore] negodata: enum 주석 영문값 보강 + 견적상태 3종 정리 + 대시보드 정비
- enum DDL 주석에 영문값 보강(status/role/delivery/usage_type/qt_type/supplier_type) - 견적상태 3종(생성/진행중/마감)으로 정리(ON_HOLD 제거), 배송 PARTNER→SUPPLIER - 대시보드 손질, 관련 테스트·negosium 견적유형 주석 동반 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
615167ad41
commit
f19c6f57ea
36 files changed
+758
-247
No files matched your search
@@ -1,199 +1,49 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { PageContainer } from '@/components/layout/PageContainer';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Typography } from '@/components/ui/typography';
|
||||
import { DashboardHero, ScopeSection } from '@/features/dashboard';
|
||||
import { OnboardingGuideModal } from '@/features/onboarding/OnboardingGuideModal';
|
||||
import { useAuth } from '@/features/auth/useAuth';
|
||||
import { useGetDashboardSummary } from '@/api/generated/dashboard/dashboard';
|
||||
import type { DashboardScope } from '@/api/generated/model/dashboardScope';
|
||||
import type { DashboardActionList } from '@/api/generated/model/dashboardActionList';
|
||||
import type { DashboardEmailUnsent } from '@/api/generated/model/dashboardEmailUnsent';
|
||||
|
||||
// 견적 생성~마감~선정을 한눈에 다루는 대시보드. 회사 전체 + 내 견적 두 스코프를 따로 보여주고,
|
||||
// 모든 액션 행은 클릭 시 해당 견적 상세로 딥링크(/quotation?detail=qt_id)된다. 읽기 전용.
|
||||
// 견적 생성~마감~선정을 한눈에 보는 대시보드.
|
||||
// 회사 전체 스코프는 최고관리자만, 일반 사용자는 '내 견적'만 본다. 위젯 행은 클릭 시 견적 상세로 딥링크. 읽기 전용.
|
||||
const ONBOARDING_SEEN_KEY = 'negodata_onboarding_seen';
|
||||
|
||||
export default function DashboardPage() {
|
||||
const navigate = useNavigate();
|
||||
const { user } = useAuth();
|
||||
const isOwner = user?.role === '최고관리자';
|
||||
const { data, isLoading, isError } = useGetDashboardSummary();
|
||||
const [guideOpen, setGuideOpen] = useState(false);
|
||||
|
||||
// 첫 방문 시 1회 자동 노출(localStorage). 이후엔 상단 "이용안내" 버튼으로만 연다.
|
||||
useEffect(() => {
|
||||
if (!localStorage.getItem(ONBOARDING_SEEN_KEY)) {
|
||||
setGuideOpen(true);
|
||||
localStorage.setItem(ONBOARDING_SEEN_KEY, '1');
|
||||
}
|
||||
}, []);
|
||||
|
||||
const openQuotation = (qtId: string) => navigate(`/quotation?detail=${qtId}`);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<PageContainer>
|
||||
<Typography variant="muted">대시보드를 불러오는 중…</Typography>
|
||||
</PageContainer>
|
||||
);
|
||||
}
|
||||
if (isError || !data) {
|
||||
return (
|
||||
<PageContainer>
|
||||
<Typography variant="muted">대시보드를 불러오지 못했습니다.</Typography>
|
||||
</PageContainer>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<ScopeSection title="회사 전체" scope={data.company} onOpen={openQuotation} />
|
||||
<ScopeSection title="내 견적" scope={data.mine} onOpen={openQuotation} />
|
||||
<DashboardHero onOpenGuide={() => setGuideOpen(true)} />
|
||||
|
||||
{isLoading ? (
|
||||
<Typography variant="muted">대시보드를 불러오는 중…</Typography>
|
||||
) : isError || !data ? (
|
||||
<Typography variant="muted">대시보드를 불러오지 못했습니다.</Typography>
|
||||
) : (
|
||||
<>
|
||||
{isOwner && <ScopeSection label="회사 전체 견적" scope={data.company} onOpen={openQuotation} />}
|
||||
<ScopeSection label="내 견적" scope={data.mine} onOpen={openQuotation} />
|
||||
</>
|
||||
)}
|
||||
|
||||
<OnboardingGuideModal open={guideOpen} onOpenChange={setGuideOpen} />
|
||||
</PageContainer>
|
||||
);
|
||||
}
|
||||
|
||||
// ----- 스코프 섹션(회사 전체 / 내 견적 공용) -----
|
||||
function ScopeSection({
|
||||
title,
|
||||
scope,
|
||||
onOpen,
|
||||
}: {
|
||||
title: string;
|
||||
scope?: DashboardScope;
|
||||
onOpen: (qtId: string) => void;
|
||||
}) {
|
||||
const s = scope ?? {};
|
||||
return (
|
||||
<section className="space-y-3">
|
||||
<Typography variant="h3">{title}</Typography>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-6">
|
||||
<StatCard label="진행중 견적" value={s.in_progress ?? 0} />
|
||||
<StatCard label="이번 달 생성" value={s.this_month ?? 0} />
|
||||
<StatCard label="마감 임박" value={s.deadline_soon?.total ?? 0} warn />
|
||||
<StatCard label="메일 미발송" value={s.email_unsent?.total ?? 0} warn />
|
||||
<StatCard label="동가" value={s.equal_bid?.total ?? 0} warn />
|
||||
<StatCard label="결렬" value={s.ruptured?.total ?? 0} warn />
|
||||
</div>
|
||||
|
||||
<div className="grid gap-3 lg:grid-cols-2">
|
||||
<DeadlineWidget data={s.deadline_soon} onOpen={onOpen} />
|
||||
<EmailUnsentWidget data={s.email_unsent} onOpen={onOpen} />
|
||||
<RefWidget title="동가 (수동 결정 필요)" data={s.equal_bid} onOpen={onOpen} />
|
||||
<RefWidget title="결렬 (선정자 없이 마감)" data={s.ruptured} onOpen={onOpen} />
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
// ----- KPI 숫자 카드 -----
|
||||
function StatCard({ label, value, warn }: { label: string; value: number; warn?: boolean }) {
|
||||
const danger = !!warn && value > 0;
|
||||
return (
|
||||
<Card className="gap-1 py-4">
|
||||
<CardContent className="space-y-1 px-4">
|
||||
<Typography variant="caption">{label}</Typography>
|
||||
<Typography variant="h2" className={danger ? 'text-destructive' : undefined}>
|
||||
{value}
|
||||
</Typography>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// ----- 액션 위젯(공용 셸) -----
|
||||
function WidgetCard({
|
||||
title,
|
||||
total,
|
||||
empty,
|
||||
children,
|
||||
}: {
|
||||
title: string;
|
||||
total: number;
|
||||
empty: boolean;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Card className="gap-3 py-4">
|
||||
<CardContent className="space-y-2 px-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<Typography variant="h4">{title}</Typography>
|
||||
<Badge variant="secondary">{total}</Badge>
|
||||
</div>
|
||||
{empty ? (
|
||||
<Typography variant="muted">처리할 항목 없음</Typography>
|
||||
) : (
|
||||
<div className="space-y-1">{children}</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function ActionRow({ name, right, onClick }: { name?: string; right?: ReactNode; onClick: () => void }) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className="flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-muted/50"
|
||||
>
|
||||
<Typography variant="small" className="truncate">
|
||||
{name || '(이름 없음)'}
|
||||
</Typography>
|
||||
{right}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
// ----- 마감 임박: 견적 + 마감 D-n -----
|
||||
function DeadlineWidget({ data, onOpen }: { data?: DashboardActionList; onOpen: (qtId: string) => void }) {
|
||||
const items = data?.items ?? [];
|
||||
return (
|
||||
<WidgetCard title="마감 임박" total={data?.total ?? 0} empty={items.length === 0}>
|
||||
{items.map((it) => (
|
||||
<ActionRow
|
||||
key={it.qt_id}
|
||||
name={it.name}
|
||||
onClick={() => onOpen(it.qt_id)}
|
||||
right={<Badge variant="outline">{fmtDeadline(it.end_time)}</Badge>}
|
||||
/>
|
||||
))}
|
||||
</WidgetCard>
|
||||
);
|
||||
}
|
||||
|
||||
// ----- 메일 미발송: 견적 단위로 묶고 미발송 협력사 수 -----
|
||||
function EmailUnsentWidget({ data, onOpen }: { data?: DashboardEmailUnsent; onOpen: (qtId: string) => void }) {
|
||||
const items = data?.quotations ?? [];
|
||||
return (
|
||||
<WidgetCard title="메일 미발송" total={data?.total ?? 0} empty={items.length === 0}>
|
||||
{items.map((it) => (
|
||||
<ActionRow
|
||||
key={it.qt_id}
|
||||
name={it.name}
|
||||
onClick={() => onOpen(it.qt_id)}
|
||||
right={<Badge variant="destructive">미발송 {it.unsent_count ?? 0}곳</Badge>}
|
||||
/>
|
||||
))}
|
||||
</WidgetCard>
|
||||
);
|
||||
}
|
||||
|
||||
// ----- 동가 / 결렬: 견적명만 -----
|
||||
function RefWidget({
|
||||
title,
|
||||
data,
|
||||
onOpen,
|
||||
}: {
|
||||
title: string;
|
||||
data?: DashboardActionList;
|
||||
onOpen: (qtId: string) => void;
|
||||
}) {
|
||||
const items = data?.items ?? [];
|
||||
return (
|
||||
<WidgetCard title={title} total={data?.total ?? 0} empty={items.length === 0}>
|
||||
{items.map((it) => (
|
||||
<ActionRow key={it.qt_id} name={it.name} onClick={() => onOpen(it.qt_id)} />
|
||||
))}
|
||||
</WidgetCard>
|
||||
);
|
||||
}
|
||||
|
||||
// 백엔드 end_time 은 naive UTC ISO(타임존 표기 없음) → 'Z' 를 붙여 UTC 로 파싱하고 남은 일수로 D-n 표기.
|
||||
function fmtDeadline(s?: string | null): string {
|
||||
if (!s) return '';
|
||||
const due = new Date(s.endsWith('Z') ? s : `${s}Z`);
|
||||
const days = Math.ceil((due.getTime() - Date.now()) / 86_400_000);
|
||||
if (Number.isNaN(days)) return '';
|
||||
if (days < 0) return '지남';
|
||||
if (days === 0) return 'D-DAY';
|
||||
return `D-${days}`;
|
||||
}
|
||||
Reference in new issue
Block a user