[st] - feat: 입력 04 작업 중 & 수정 요청 사항 적용
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import {
|
||||
type InfiniteData,
|
||||
keepPreviousData,
|
||||
@@ -9,12 +9,12 @@ import {
|
||||
} from "@tanstack/react-query";
|
||||
import { useTabStore as useGridTabStore } from "@rsone/components";
|
||||
|
||||
import { statisticsApi } from "@/entities/statistics/api/statistics-service";
|
||||
import { verificationInputReportApi } from "@/entities/statistics/api/verification-input-report-service";
|
||||
import type {
|
||||
VerificationResultListRequest,
|
||||
VerificationResultListResponse,
|
||||
VerificationResultReportItem,
|
||||
} from "@/entities/statistics/model/statistics-interface";
|
||||
VerificationInputReportItem,
|
||||
VerificationInputReportResponse,
|
||||
VerificationInputReportTypeCountingInfo,
|
||||
} from "@/entities/statistics/model/verification-input-report-interface";
|
||||
import { useAlertStore, useMenuStore } from "@/shared/lib";
|
||||
import {
|
||||
findMenuItemByUrlPath,
|
||||
@@ -59,8 +59,8 @@ const TYPE_CODE_NAME_MAP: Record<string, string> = {
|
||||
const PAGE_SIZE = 100;
|
||||
const SCROLL_LOAD_THRESHOLD_PX = 120;
|
||||
|
||||
function getNextVerificationResultPage(
|
||||
lastPage: VerificationResultListResponse,
|
||||
function getNextVerificationInputReportPage(
|
||||
lastPage: VerificationInputReportResponse,
|
||||
): number | undefined {
|
||||
const pageInfo = lastPage?.data?.pageInfo;
|
||||
if (!pageInfo) return undefined;
|
||||
@@ -69,19 +69,29 @@ function getNextVerificationResultPage(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function flattenVerificationResults(
|
||||
data: InfiniteData<VerificationResultListResponse> | undefined,
|
||||
): VerificationResultReportItem[] {
|
||||
function flattenVerificationInputReportResults(
|
||||
data: InfiniteData<VerificationInputReportResponse> | undefined,
|
||||
): VerificationInputReportItem[] {
|
||||
return (
|
||||
data?.pages.flatMap((page) => page?.data?.verifyResultList ?? []) ?? []
|
||||
);
|
||||
}
|
||||
|
||||
function getVerificationResultTotalCount(
|
||||
data: InfiniteData<VerificationResultListResponse> | undefined,
|
||||
loadedCount: number,
|
||||
): number {
|
||||
return data?.pages[0]?.data?.pageInfo?.totalElements ?? loadedCount;
|
||||
function getVerifyTypeCountingInfo(
|
||||
data: InfiniteData<VerificationInputReportResponse> | undefined,
|
||||
): VerificationInputReportTypeCountingInfo | null {
|
||||
return data?.pages[0]?.data?.verifyTypeCountingInfo ?? null;
|
||||
}
|
||||
|
||||
function formatReportItemTitle(item: VerificationInputReportItem): string {
|
||||
return item.statsNm?.trim() || item.vrfcTrgtNm?.trim() || item.statsCd;
|
||||
}
|
||||
|
||||
function formatReportItemRegion(item: VerificationInputReportItem): string {
|
||||
const parts = [item.ctpvNm, item.sggNm].filter(
|
||||
(v): v is string => Boolean(v?.trim()),
|
||||
);
|
||||
return parts.length > 0 ? parts.join(" ") : "-";
|
||||
}
|
||||
|
||||
function useVerificationReportList(
|
||||
@@ -89,28 +99,31 @@ function useVerificationReportList(
|
||||
statsCdQueryKey: string,
|
||||
vrfcMthdCd: VerificationReportTabKey,
|
||||
statsCd: string,
|
||||
enabled: boolean,
|
||||
) {
|
||||
return useInfiniteQuery({
|
||||
queryKey: [
|
||||
"verificationResultList",
|
||||
"verificationInputReport",
|
||||
statsYr,
|
||||
vrfcMthdCd,
|
||||
statsCdQueryKey,
|
||||
],
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam }) =>
|
||||
statisticsApi.getVerificationResultList({
|
||||
verificationInputReportApi.getVerificationInputReport({
|
||||
statsYr,
|
||||
pbcpAprvYn: "N",
|
||||
vrfcMthdCd,
|
||||
page: pageParam,
|
||||
size: PAGE_SIZE,
|
||||
prcsYnList: "0",
|
||||
vrfcMthdCd,
|
||||
...(!(statsCd === "" || statsCd === "ALL") && { statsCd }),
|
||||
} satisfies VerificationResultListRequest),
|
||||
getNextPageParam: getNextVerificationResultPage,
|
||||
}),
|
||||
getNextPageParam: getNextVerificationInputReportPage,
|
||||
placeholderData: keepPreviousData,
|
||||
refetchOnWindowFocus: false,
|
||||
// 탭 전환만으로는 재조회하지 않음(명시적 새로고침/조건 변경 시만 조회)
|
||||
staleTime: Infinity,
|
||||
refetchOnMount: false,
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -132,28 +145,46 @@ const VerificationSelectionReport = ({
|
||||
const alert = useAlertStore((s) => s.setMessage);
|
||||
const [activeTab, setActiveTab] = useState<VerificationReportTabKey>("NV");
|
||||
const [statsCd, setStatsCd] = useState<string>("ALL");
|
||||
const [isFullReloading, setIsFullReloading] = useState(false);
|
||||
|
||||
const statsYr = String(dayjs().year() - 1);
|
||||
const statsCdQueryKey =
|
||||
statsCd === "" || statsCd === "ALL" ? "" : statsCd;
|
||||
|
||||
const handleStatsCdChange = useCallback(
|
||||
(nextStatsCd: string) => {
|
||||
setStatsCd(nextStatsCd);
|
||||
setActiveTab("NV");
|
||||
setIsFullReloading(true);
|
||||
|
||||
// 통계항목 변경 시 모든 탭 캐시 제거 후 NV부터 다시 조회
|
||||
void queryClient.removeQueries({
|
||||
queryKey: ["verificationInputReport", statsYr],
|
||||
});
|
||||
},
|
||||
[queryClient, statsYr],
|
||||
);
|
||||
|
||||
const nvQuery = useVerificationReportList(
|
||||
statsYr,
|
||||
statsCdQueryKey,
|
||||
"NV",
|
||||
statsCd,
|
||||
activeTab === "NV",
|
||||
);
|
||||
const imrQuery = useVerificationReportList(
|
||||
statsYr,
|
||||
statsCdQueryKey,
|
||||
"IMR",
|
||||
statsCd,
|
||||
activeTab === "IMR",
|
||||
);
|
||||
const hbQuery = useVerificationReportList(
|
||||
statsYr,
|
||||
statsCdQueryKey,
|
||||
"HB",
|
||||
statsCd,
|
||||
activeTab === "HB",
|
||||
);
|
||||
|
||||
const queryByTab = {
|
||||
@@ -162,44 +193,51 @@ const VerificationSelectionReport = ({
|
||||
HB: hbQuery,
|
||||
} as const;
|
||||
|
||||
const isInitialLoading =
|
||||
nvQuery.isPending || imrQuery.isPending || hbQuery.isPending;
|
||||
const isRefreshing =
|
||||
(nvQuery.isFetching && !nvQuery.isPending) ||
|
||||
(imrQuery.isFetching && !imrQuery.isPending) ||
|
||||
(hbQuery.isFetching && !hbQuery.isPending);
|
||||
const error = nvQuery.error ?? imrQuery.error ?? hbQuery.error;
|
||||
const activeQuery = queryByTab[activeTab];
|
||||
const isRefreshing = activeQuery.isFetching && !activeQuery.isPending;
|
||||
const error = activeQuery.error;
|
||||
|
||||
/** 통계항목 변경·최초 진입: 탭 영역 숨기고 카드 전체 로딩만 표시 */
|
||||
const hideTabsSection =
|
||||
isFullReloading ||
|
||||
(activeTab === "NV" && !nvQuery.data && (nvQuery.isPending || nvQuery.isFetching));
|
||||
|
||||
useEffect(() => {
|
||||
if (!isFullReloading) return;
|
||||
if (nvQuery.isFetching) return;
|
||||
if (nvQuery.isSuccess || nvQuery.isError) {
|
||||
setIsFullReloading(false);
|
||||
}
|
||||
}, [isFullReloading, nvQuery.isFetching, nvQuery.isSuccess, nvQuery.isError]);
|
||||
|
||||
const handleRefresh = useCallback(() => {
|
||||
const tabCodes: VerificationReportTabKey[] = ["NV", "IMR", "HB"];
|
||||
void Promise.all(
|
||||
tabCodes.map((code) =>
|
||||
queryClient.resetQueries({
|
||||
queryKey: [
|
||||
"verificationResultList",
|
||||
statsYr,
|
||||
code,
|
||||
statsCdQueryKey,
|
||||
],
|
||||
}),
|
||||
),
|
||||
);
|
||||
}, [queryClient, statsYr, statsCdQueryKey]);
|
||||
setStatsCd("ALL");
|
||||
setActiveTab("NV");
|
||||
setIsFullReloading(true);
|
||||
void queryClient.removeQueries({
|
||||
queryKey: ["verificationInputReport", statsYr],
|
||||
});
|
||||
}, [queryClient, statsYr]);
|
||||
|
||||
const listsByTab: Record<VerificationReportTabKey, VerificationResultReportItem[]> = {
|
||||
NV: flattenVerificationResults(nvQuery.data),
|
||||
IMR: flattenVerificationResults(imrQuery.data),
|
||||
HB: flattenVerificationResults(hbQuery.data),
|
||||
const listsByTab: Record<VerificationReportTabKey, VerificationInputReportItem[]> = {
|
||||
NV: flattenVerificationInputReportResults(nvQuery.data),
|
||||
IMR: flattenVerificationInputReportResults(imrQuery.data),
|
||||
HB: flattenVerificationInputReportResults(hbQuery.data),
|
||||
};
|
||||
|
||||
const typeCountingInfo =
|
||||
getVerifyTypeCountingInfo(nvQuery.data) ??
|
||||
getVerifyTypeCountingInfo(imrQuery.data) ??
|
||||
getVerifyTypeCountingInfo(hbQuery.data);
|
||||
|
||||
const totalCountByTab: Record<VerificationReportTabKey, number> = {
|
||||
NV: getVerificationResultTotalCount(nvQuery.data, listsByTab.NV.length),
|
||||
IMR: getVerificationResultTotalCount(imrQuery.data, listsByTab.IMR.length),
|
||||
HB: getVerificationResultTotalCount(hbQuery.data, listsByTab.HB.length),
|
||||
NV: typeCountingInfo?.nvCount ?? listsByTab.NV.length,
|
||||
IMR: typeCountingInfo?.imrCount ?? listsByTab.IMR.length,
|
||||
HB: typeCountingInfo?.hbCount ?? listsByTab.HB.length,
|
||||
};
|
||||
|
||||
const openInputFromStatsCd = useCallback(
|
||||
(item: VerificationResultReportItem) => {
|
||||
(item: VerificationInputReportItem) => {
|
||||
const nav = resolveInputPageNavigationFromStatsCd(item.statsCd);
|
||||
if (!nav) {
|
||||
alert(
|
||||
@@ -263,9 +301,21 @@ const VerificationSelectionReport = ({
|
||||
[],
|
||||
);
|
||||
|
||||
const isTabContentLoading = (tab: VerificationReportTabKey) => {
|
||||
const query = queryByTab[tab];
|
||||
return (
|
||||
activeTab === tab &&
|
||||
!hideTabsSection &&
|
||||
(query.isPending ||
|
||||
(query.isFetching && !query.isFetchingNextPage) ||
|
||||
(!query.data && !query.error))
|
||||
);
|
||||
};
|
||||
|
||||
const renderResultList = (
|
||||
typeCode: VerificationReportTabKey,
|
||||
items: VerificationResultReportItem[],
|
||||
items: VerificationInputReportItem[],
|
||||
isTabLoading: boolean,
|
||||
hasNextPage: boolean,
|
||||
isFetchingNextPage: boolean,
|
||||
fetchNextPage: () => void,
|
||||
@@ -281,7 +331,13 @@ const VerificationSelectionReport = ({
|
||||
)
|
||||
}
|
||||
>
|
||||
{items.length === 0 && !isFetchingNextPage ? (
|
||||
{isTabLoading ? (
|
||||
<div className="flex h-full min-h-[8rem] items-center justify-center">
|
||||
<div className="relative size-[5rem]">
|
||||
<LoadingWithAnimation color="primary" />
|
||||
</div>
|
||||
</div>
|
||||
) : items.length === 0 && !isFetchingNextPage ? (
|
||||
<div className="flex h-full min-h-[8rem] items-center justify-center text-lg text-muted-foreground">
|
||||
항목이 없습니다.
|
||||
</div>
|
||||
@@ -303,7 +359,7 @@ const VerificationSelectionReport = ({
|
||||
>
|
||||
<div className="mb-2 flex items-center justify-between">
|
||||
<span className="font-medium">
|
||||
{item.statsNm}
|
||||
{formatReportItemTitle(item)}
|
||||
</span>
|
||||
<Badge
|
||||
color={
|
||||
@@ -320,7 +376,7 @@ const VerificationSelectionReport = ({
|
||||
{item.rsnExpln}
|
||||
</p>
|
||||
<div className="flex justify-between text-lg text-muted-foreground">
|
||||
<span>{item.admdstNm}</span>
|
||||
<span>{formatReportItemRegion(item)}</span>
|
||||
<span>
|
||||
현재: {item.nowVlCn ?? "-"} / 비교:{" "}
|
||||
{item.compVlCn ?? "-"}
|
||||
@@ -383,25 +439,25 @@ const VerificationSelectionReport = ({
|
||||
<CodeSelectWithAll
|
||||
upCd="STITEM"
|
||||
value={statsCd}
|
||||
onValueChange={setStatsCd}
|
||||
onValueChange={handleStatsCdChange}
|
||||
placeholder="전체"
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
<div className="card-body p-2.5 flex-1 flex flex-col overflow-hidden relative min-h-0">
|
||||
{isInitialLoading && (
|
||||
{hideTabsSection && (
|
||||
<div className="absolute inset-0 z-50 [data-theme='black']:bg-transparent rounded-lg p-10 flex justify-center items-center">
|
||||
<div className="relative size-[5rem]">
|
||||
<LoadingWithAnimation color="primary" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{error && (
|
||||
{!hideTabsSection && error && (
|
||||
<div className="absolute inset-0 z-50 [data-theme='black']:bg-transparent rounded-lg p-10 flex justify-center items-center">
|
||||
데이터를 불러올 수 없습니다.
|
||||
</div>
|
||||
)}
|
||||
{!isInitialLoading && !error && (
|
||||
{!hideTabsSection && !error && (
|
||||
<section className="flex min-h-0 flex-1 flex-col">
|
||||
<Tabs
|
||||
value={activeTab}
|
||||
@@ -428,18 +484,14 @@ const VerificationSelectionReport = ({
|
||||
value={tab.value}
|
||||
className="mt-0 flex min-h-0 flex-1 flex-col p-0 data-[state=inactive]:hidden"
|
||||
>
|
||||
{activeTab === tab.value
|
||||
? renderResultList(
|
||||
tab.value,
|
||||
listsByTab[tab.value],
|
||||
queryByTab[tab.value]
|
||||
.hasNextPage ?? false,
|
||||
queryByTab[tab.value]
|
||||
.isFetchingNextPage,
|
||||
queryByTab[tab.value]
|
||||
.fetchNextPage,
|
||||
)
|
||||
: null}
|
||||
{renderResultList(
|
||||
tab.value,
|
||||
listsByTab[tab.value],
|
||||
isTabContentLoading(tab.value),
|
||||
queryByTab[tab.value].hasNextPage ?? false,
|
||||
queryByTab[tab.value].isFetchingNextPage,
|
||||
queryByTab[tab.value].fetchNextPage,
|
||||
)}
|
||||
</TabsContent>
|
||||
))}
|
||||
</Tabs>
|
||||
|
||||
Reference in New Issue
Block a user