[as] feat: 대시보드 페이지 구현

This commit is contained in:
2026-08-18 16:40:21 +09:00
parent 774144846d
commit 5af4f0f27b
18 changed files with 897 additions and 15 deletions
@@ -0,0 +1,23 @@
import { client } from "@/shared/api";
import { ENDPOINT } from "@/shared/config";
import type {
DashboardMainResponseDto,
DashboardMainSearchDto,
DashboardService,
} from "../model/dashboard-interface";
const BASE = ENDPOINT.AS_SERVICE.DASHBOARD;
async function getMainDashboard(
searchDto: DashboardMainSearchDto,
): Promise<DashboardMainResponseDto> {
const response = await client.get<DashboardMainResponseDto>(`${BASE}/main`, {
params: searchDto,
});
return response.data;
}
export const dashboardService = {
getMainDashboard,
} satisfies DashboardService;
@@ -0,0 +1,18 @@
import { useQuery } from "@tanstack/react-query";
import { ENDPOINT } from "@/shared/config";
import type { DashboardMainSearchDto } from "../model/dashboard-interface";
import { dashboardService } from "./dashboard-service";
export const dashboardBaseKey = [ENDPOINT.AS_SERVICE.DASHBOARD] as const;
const EMPTY_SEARCH: DashboardMainSearchDto = {};
export function useGetMainDashboard(params: DashboardMainSearchDto = EMPTY_SEARCH) {
return useQuery({
queryKey: [...dashboardBaseKey, "getMainDashboard", params],
queryFn: () => dashboardService.getMainDashboard(params),
});
}
+10
View File
@@ -0,0 +1,10 @@
export { dashboardService } from "./api/dashboard-service";
export { dashboardBaseKey, useGetMainDashboard } from "./api/queries";
export type {
DashboardMainResponseDto,
DashboardMainSearchDto,
DashboardService,
DocPrgrsSttsResponseDto,
NotiAsStatResponseDto,
NotiAsUserResponseDto,
} from "./model/dashboard-interface";
@@ -0,0 +1,58 @@
/** 백엔드 DashboardMainSearchDto */
export interface DashboardMainSearchDto {
searchYear?: number;
notiType?: string;
notReadYn?: "Y" | "N";
startDt?: string;
endDt?: string;
docSeComCd?: string;
}
/** 백엔드 DocPrgrsSttsResponseDto */
export interface DocPrgrsSttsResponseDto {
docSeNm: string;
docSeComCd: string;
reqCnt: number;
prgrsCnt: number;
cmptnCnt: number;
totCnt: number;
}
/** 백엔드 NotiAsUserResponseDto */
export interface NotiAsUserResponseDto {
notiId: number;
recvUnqId: string;
senderUnqId: string;
notiType: string;
notiTtl: string;
notiCn?: string;
notReadYn?: "Y" | "N";
regDt?: string;
notiUrl?: string;
notiLnkgUnqNo?: string;
docSeComCd?: string;
docSeComNm?: string;
notiIdntyDt?: string;
notiIdntyYn?: "Y" | "N";
notiPrcsCmptnYn?: "Y" | "N";
notiPrcsCmptnDt?: string;
}
/** 백엔드 NotiAsStatResponseDto */
export interface NotiAsStatResponseDto {
todayCount: number;
delayCount: number;
pendingCount: number;
}
/** 백엔드 DashboardMainResponseDto */
export interface DashboardMainResponseDto {
docPrgrsSttsList: DocPrgrsSttsResponseDto[];
notiList: NotiAsUserResponseDto[];
notiStats: NotiAsStatResponseDto;
}
/** Controller public 메서드명·시그니처와 동일 */
export interface DashboardService {
getMainDashboard(searchDto: DashboardMainSearchDto): Promise<DashboardMainResponseDto>;
}
+1
View File
@@ -21,6 +21,7 @@ export function useReadNoti() {
mutationFn: (notiId: number) => notiService.readNoti(notiId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: notiBaseKey });
queryClient.invalidateQueries({ queryKey: [ENDPOINT.AS_SERVICE.DASHBOARD] });
},
});
}
+1
View File
@@ -0,0 +1 @@
export { DashboardPage as MainPage } from "./ui/dashboard-page";
@@ -0,0 +1,143 @@
"use client";
import { useCallback } from "react";
import { useRouter } from "next/navigation";
import { dayjs } from "@/shared/lib";
import { NoData } from "@/shared/ui/no-data";
import type { NotiAsStatResponseDto, NotiAsUserResponseDto } from "@/entities/dashboard";
import { useReadNoti } from "@/entities/noti";
import { Badge, Button, Skeleton } from "@common/components";
interface DashboardNotiListProps {
notiList: NotiAsUserResponseDto[] | undefined;
notiStats: NotiAsStatResponseDto | undefined;
isPending: boolean;
isError: boolean;
dataUpdatedAt: number;
}
export function DashboardNotiList({
notiList,
notiStats,
isPending,
isError,
dataUpdatedAt,
}: DashboardNotiListProps) {
const router = useRouter();
const { mutateAsync: readNoti, isPending: isReadPending } = useReadNoti();
const handleAction = useCallback(
async (row: NotiAsUserResponseDto) => {
if (row.notReadYn === "N") await readNoti(row.notiId);
const notiUrl = resolveNotiUrl(row);
if (!notiUrl) return;
router.push(notiUrl);
},
[readNoti, router],
);
return (
<section className="card card-border mx-0 bg-background">
<div className="card-header flex items-center justify-between gap-4">
<h3 className="text-2xl font-semibold">
알림이력
{dataUpdatedAt > 0 ? (
<span className="pl-2 text-lg font-medium text-muted-foreground">
(업데이트 일시: {dayjs(dataUpdatedAt).format("YYYY-MM-DD HH:mm")})
</span>
) : null}
</h3>
<div className="flex items-center gap-4">
<Button type="button" size="sm" color="white" onClick={() => router.push("/nti-hstry")}>
전체보기
</Button>
</div>
</div>
<div className="flex flex-col gap-4 p-2">
<div className="flex flex-wrap gap-2 pt-2">
{NOTI_STAT_CHIPS.map((chip) => (
<Badge key={chip.field} color={chip.color}>
{chip.label} {isPending ? "-" : (notiStats?.[chip.field] ?? 0)}건
</Badge>
))}
</div>
{isPending ? (
<div className="flex flex-col gap-2">
<Skeleton className="h-14 w-full" />
<Skeleton className="h-14 w-full" />
<Skeleton className="h-14 w-full" />
</div>
) : null}
{isError ? (
<p className="flex min-h-[12rem] items-center justify-center text-muted-foreground">
알림이력을 불러오지 못했습니다.
</p>
) : null}
{!isPending && !isError && (notiList?.length ?? 0) === 0 ? <NoData /> : null}
<div>
{!isPending && !isError && notiList && notiList.length > 0
? notiList.map((row) => (
<DashboardNotiRow
key={row.notiId}
row={row}
isActionPending={isReadPending}
onAction={() => {
void handleAction(row);
}}
/>
))
: null}
</div>
</div>
</section>
);
}
interface DashboardNotiRowProps {
row: NotiAsUserResponseDto;
isActionPending: boolean;
onAction: () => void;
}
function DashboardNotiRow({ row, isActionPending, onAction }: DashboardNotiRowProps) {
return (
<div className="flex items-center gap-4 border-b px-2 py-4 last:border-b-0">
<span className="shrink-0 text-lg text-muted-foreground">
{row.regDt ? dayjs(row.regDt).format("YYYY-MM-DD") : "-"}
</span>
<p className="min-w-0 flex-1 truncate text-xl">{row.notiTtl}</p>
<Button type="button" size="sm" color="white" disabled={isActionPending} onClick={onAction}>
처리하기
</Button>
</div>
);
}
function resolveNotiUrl(row: NotiAsUserResponseDto) {
const notiUrl = row.notiUrl?.trim();
if (!notiUrl) return null;
if (row.docSeComCd === "SEWER") {
const parts = notiUrl.split("/");
if (parts.length > 1) {
parts.pop();
return parts.join("/");
}
}
return notiUrl;
}
const NOTI_STAT_CHIPS = [
{ field: "todayCount", label: "오늘", color: "green" },
{ field: "delayCount", label: "지연", color: "orange" },
{ field: "pendingCount", label: "완료대기", color: "gray" },
] as const;
@@ -0,0 +1,16 @@
import { Skeleton } from "@common/components";
export function DashboardNoticeTable() {
return (
<section className="card card-border mx-0 bg-background">
<div className="card-header flex items-center justify-between">
<h3 className="text-2xl font-semibold">공지사항</h3>
</div>
<div className="flex flex-col gap-2 p-4">
<Skeleton className="h-10 w-full" />
<Skeleton className="h-10 w-full" />
<Skeleton className="h-10 w-full" />
</div>
</section>
);
}
@@ -0,0 +1,29 @@
"use client";
import { useGetMainDashboard } from "@/entities/dashboard";
import { DashboardNotiList } from "./dashboard-noti-list";
import { DashboardNoticeTable } from "./dashboard-notice-table";
import { DocPrgrsSttsCards } from "./doc-prgrs-stts-cards";
import { NationalAsMap } from "./national-as-map";
export function DashboardPage() {
const { data, isPending, isError, dataUpdatedAt } = useGetMainDashboard();
return (
<div className="grid gap-4 px-[1.8rem] pb-6 lg:grid-cols-2">
<NationalAsMap />
<div className="flex min-h-0 flex-col gap-4">
<DocPrgrsSttsCards items={data?.docPrgrsSttsList} isPending={isPending} isError={isError} />
<DashboardNotiList
notiList={data?.notiList}
notiStats={data?.notiStats}
isPending={isPending}
isError={isError}
dataUpdatedAt={dataUpdatedAt}
/>
<DashboardNoticeTable />
</div>
</div>
);
}
@@ -0,0 +1,128 @@
import Link from "next/link";
import { CircleCheck, FilePlus, type LucideIcon, RefreshCw } from "lucide-react";
import type { DocPrgrsSttsResponseDto } from "@/entities/dashboard";
import { cn, Skeleton } from "@common/components";
interface DocPrgrsSttsCardsProps {
items: DocPrgrsSttsResponseDto[] | undefined;
isPending: boolean;
isError: boolean;
}
export function DocPrgrsSttsCards({ items, isPending, isError }: DocPrgrsSttsCardsProps) {
if (isPending) {
return (
<div className="grid grid-cols-2 gap-4">
{DOC_PRGRS_STTS_SLOTS.map((slot) => (
<Skeleton key={slot.docSeComCd} className="h-[14rem] rounded-xl" />
))}
</div>
);
}
if (isError) {
return (
<div className="card card-border mx-0 flex min-h-[14rem] items-center justify-center bg-background text-muted-foreground">
진행상황을 불러오지 못했습니다.
</div>
);
}
const itemByCd = new Map(items?.map((item) => [item.docSeComCd, item]));
return (
<div className="grid grid-cols-2 gap-4">
{DOC_PRGRS_STTS_SLOTS.map((slot) => {
const item = itemByCd.get(slot.docSeComCd);
return (
<div
key={slot.docSeComCd}
className="card card-border hover:bg-muted/40 mx-0 block bg-background transition-colors"
>
<div className="card-header">
<h3 className="text-2xl font-semibold">{slot.title}</h3>
</div>
<Link key={slot.docSeComCd} href={slot.href}>
<div className="flex items-center justify-between pt-2">
{STAT_METRICS.map((metric) => (
<DocPrgrsSttsMetric
key={metric.field}
label={metric.label}
count={item?.[metric.field] ?? 0}
iconClassName={metric.iconClassName}
bgColor={metric.bgColor}
Icon={metric.Icon}
/>
))}
</div>
</Link>
</div>
);
})}
</div>
);
}
interface DocPrgrsSttsMetricProps {
label: string;
count: number;
iconClassName: string;
bgColor: string;
Icon: LucideIcon;
}
function DocPrgrsSttsMetric({
label,
count,
iconClassName,
bgColor,
Icon,
}: DocPrgrsSttsMetricProps) {
return (
<div className={cn("card flex flex-1 flex-col items-center gap-2 rounded-2xl p-4", bgColor)}>
<span
className={cn(
"flex size-12 items-center justify-center rounded-full text-white",
iconClassName,
)}
>
<Icon className="size-6" />
</span>
<span className="text-xl text-muted-foreground">{label}</span>
<span className="text-3xl font-semibold tabular-nums">{count}</span>
</div>
);
}
const DOC_PRGRS_STTS_SLOTS = [
{ docSeComCd: "FNRS", title: "재원협의 진행상황", href: "/fnrs-cnsltn" },
{ docSeComCd: "INSTL", title: "설치인가 진행상황", href: "/instl-sncn" },
{ docSeComCd: "CNFM", title: "설계자문 진행상황", href: "/design-cnstn" },
{ docSeComCd: "SEWER", title: "기본계획 진행상황", href: "/sewer-bsc-plan" },
] as const;
const STAT_METRICS = [
{
field: "reqCnt",
label: "신청",
iconClassName: "bg-blue-500",
bgColor: "bg-blue-100",
Icon: FilePlus,
},
{
field: "prgrsCnt",
label: "진행",
iconClassName: "bg-emerald-500",
bgColor: "bg-emerald-100",
Icon: RefreshCw,
},
{
field: "cmptnCnt",
label: "완료",
iconClassName: "bg-orange-500",
bgColor: "bg-orange-100",
Icon: CircleCheck,
},
] as const;
@@ -0,0 +1,14 @@
import { Skeleton } from "@common/components";
export function NationalAsMap() {
return (
<section className="card card-border mx-0 flex h-full min-h-[40rem] flex-col bg-background">
<div className="card-header">
<h3 className="text-2xl font-semibold">전국 행정지원 지도</h3>
</div>
<div className="flex-1 p-4">
<Skeleton className="h-full min-h-[36rem] w-full rounded-xl" />
</div>
</section>
);
}
-1
View File
@@ -1 +0,0 @@
export { MainPage } from "./ui/main-page";
-9
View File
@@ -1,9 +0,0 @@
"use client";
export function MainPage() {
return (
<div className="flex h-full flex-col items-center justify-center py-10">
<h1 className="mb-4 text-3xl font-bold">Home</h1>
</div>
);
}
+1
View File
@@ -23,6 +23,7 @@ export const ENDPOINT = {
DESIGN_CNSTN_ESNTL_ATCH_FILE: "/as-service/api/v1/design-cnstn-esntl-atch-file",
DESIGN_CNSTN_RVW_OPNN: "/as-service/api/v1/design-cnstn-rvw-opnn",
SEWER_BSC_PLAN: "/as-service/api/v1/sewer-bsc-plans",
DASHBOARD: "/as-service/api/v1/dashboard",
},
USER_SERVICE: {
LOGIN: "/user-service/login",