From 85615a826e42da53570f4d755041d80ac5755acb Mon Sep 17 00:00:00 2001 From: dongsilove Date: Sat, 31 Jan 2026 16:05:21 +0900 Subject: [PATCH] =?UTF-8?q?fo:=20exceldown=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../facilityPrecipitation/page.tsx | 67 ++++++++-------- .../(with-layout)/facilityWaterQlty/page.tsx | 76 +++++++++---------- .../app/pages/(with-layout)/flowRate/page.tsx | 58 ++++++-------- .../pages/(with-layout)/planSewage/page.tsx | 68 ++++++++--------- .../pages/(with-layout)/processArea/page.tsx | 65 +++++++--------- .../(with-layout)/processFacility/page.tsx | 55 ++++++-------- apps/fo/app/pages/(with-layout)/rdi/page.tsx | 68 ++++++++--------- .../pages/(with-layout)/sewageOccur/page.tsx | 70 ++++++++--------- .../(with-layout)/underWaterInput/page.tsx | 67 ++++++++-------- .../src/ui/search_base_form/index.tsx | 6 +- 10 files changed, 267 insertions(+), 333 deletions(-) diff --git a/apps/fo/app/pages/(with-layout)/facilityPrecipitation/page.tsx b/apps/fo/app/pages/(with-layout)/facilityPrecipitation/page.tsx index 42dbb1be1..7fd141694 100644 --- a/apps/fo/app/pages/(with-layout)/facilityPrecipitation/page.tsx +++ b/apps/fo/app/pages/(with-layout)/facilityPrecipitation/page.tsx @@ -5,11 +5,11 @@ */ "use client" -import { useFoStore } from "@/app/store"; +import { StoreContext, useFoStore } from "@/app/store"; import type { TableUpperProps } from "@/app/store/common"; import { ContentsDiv, downloadExcel, MainDiv, SearchBaseForm, SearchInput, SelectBox, Title, UiModal, UiTable, type ReturnType } from "@common/business_components"; import ListDiv from "@common/business_components/ui/list_div"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import PrecipitationModal from "./modal/page"; import LoadingOverlay from "@common/business_components/ui/loadingBar"; import UnderComment from "@/app/components/common/UnderComment"; @@ -22,6 +22,11 @@ export default function FacilityPrecipitation() { ,initializeCommonData ,searchFacilityPrecipitationList } = useFoStore((state) => state) || { processAreaList: { processAreaList: [] }}; + const store = useContext(StoreContext); + + if (!store) { + throw new Error("StoreContext is not available. Ensure StoreProvider is mounted."); + } const { isInit, @@ -50,7 +55,6 @@ export default function FacilityPrecipitation() { upHeadList1, upHeadList2, upHeadList3, - excelList, facilityPrecipitation, facilityPrecipitationCount, isLoading, @@ -98,7 +102,6 @@ export default function FacilityPrecipitation() { const [searchYear, setSearchYear] = useState(defaultSearchYear); // 엑셀다운로드 트리거 const [isExcelDownClick, setIsExcelDownClick] = useState(false); - const excelWaitRef = useRef(false); /** * 페이지 함수 */ @@ -145,32 +148,6 @@ export default function FacilityPrecipitation() { } }, [isInit, initializeCommonData, searchFacilityPrecipitationList, defaultSearchYear]); - useEffect(() => { - if (!isExcelDownClick) return; - - if (isLoading) { - excelWaitRef.current = true; - return; - } - - if (!excelWaitRef.current) { - return; - } - - if (excelList && excelList.length > 0) { - downloadExcel({ - data: excelList as unknown as JSON[], - fileName: '시설별 강수현황', - sheetNameArray: ['시설별 강수현황'], - headerRange: 'A1:N1' - }); - } else { - alert("조회된 결과가 없습니다."); - } - setIsExcelDownClick(false); - excelWaitRef.current = false; - }, [excelList, isExcelDownClick, isLoading]); - useEffect(() => { if (facilityPrecipitation.length > 0) { @@ -181,7 +158,7 @@ export default function FacilityPrecipitation() { * 콜백함수 */ // 조회 - const searchFacilityPrecipitation = useCallback(({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => { + const searchFacilityPrecipitation = useCallback(async ({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => { let nameCd, partStr switch (partValue) { case 'R': @@ -199,9 +176,9 @@ export default function FacilityPrecipitation() { break; } if (partStr.length > 1 || operationValue!== '0' || fcltCpct !== '0' ||nameCd ||(fcltyName.trim() !== "" && fcltyName.trim() !== null)) { - searchFacilityPrecipitationList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); + await searchFacilityPrecipitationList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); } else { - searchFacilityPrecipitationList(pageNo, pageCnt, searchYear); + await searchFacilityPrecipitationList(pageNo, pageCnt, searchYear); } }, [operationValue, fcltyName, searchFacilityPrecipitationList, searchYear, fcltCpct]); @@ -212,7 +189,8 @@ export default function FacilityPrecipitation() { }, [upHeadList1, upHeadList2, upHeadList3]); // 엑셀다운로드 - const excelDownload = useCallback((searchReturn: ReturnType) => { + const excelDownload = useCallback(async (searchReturn: ReturnType) => { + if (isExcelDownClick) return; // if (ref.current.partValue === 'A') { // 행정별 // if (!ref.current.sidoValue || ref.current.sidoValue === '0') { // alert('엑셀 다운로드는 시도 조건을 선택한 후 이용 가능합니다.'); @@ -229,10 +207,24 @@ export default function FacilityPrecipitation() { // return; // } // } - excelWaitRef.current = false; - searchFacilityPrecipitation(searchReturn, 1, 10000); setIsExcelDownClick(true); - }, [searchFacilityPrecipitation]); + try { + await searchFacilityPrecipitation(searchReturn, 1, 10000); + const latestExcelList = store.getState().FacilityPrecipitation.excelList || []; + if (latestExcelList.length > 0) { + downloadExcel({ + data: latestExcelList as unknown as JSON[], + fileName: '시설별 강수현황', + sheetNameArray: ['시설별 강수현황'], + headerRange: 'A1:N1' + }); + } else { + alert("조회된 결과가 없습니다."); + } + } finally { + setIsExcelDownClick(false); + } + }, [isExcelDownClick, searchFacilityPrecipitation, store]); // 페이지 변경 const handlePageChange = useCallback((page: number) => { @@ -267,6 +259,7 @@ export default function FacilityPrecipitation() { btnClass={btnClass} queryClick={chkVal} excelClick={excelDownload} + excelDisabled={isExcelDownClick} initClick={resetVal} ref={ref} isAdmin={false}/> diff --git a/apps/fo/app/pages/(with-layout)/facilityWaterQlty/page.tsx b/apps/fo/app/pages/(with-layout)/facilityWaterQlty/page.tsx index 316ea78a1..265c9788f 100644 --- a/apps/fo/app/pages/(with-layout)/facilityWaterQlty/page.tsx +++ b/apps/fo/app/pages/(with-layout)/facilityWaterQlty/page.tsx @@ -6,13 +6,13 @@ "use client" -import { useFoStore } from "@/app/store"; +import { StoreContext, useFoStore } from "@/app/store"; import type { TableUpperProps } from "@/app/store/common"; import type { FacilityWaterQltyProps } from "@/app/store/facilityWaterQlty"; import { ContentsDiv, downloadExcelFormat, MainDiv, SearchBaseForm, SearchInput, SelectBox, Title, UiModal, UiTable, type ReturnType } from "@common/business_components"; import ListDiv from "@common/business_components/ui/list_div"; import LoadingOverlay from "@common/business_components/ui/loadingBar"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import WaterQualityModal from "./modal/page"; export default function ProcessFacilitySearch() { @@ -21,6 +21,11 @@ export default function ProcessFacilitySearch() { , initializeCommonData , searchFacilityWaterQltyList } = useFoStore((state) => state) || { FacilityWaterQltyList: { facilityWaterQltyList: [], facilityWaterQltyCount: 0 } }; + const store = useContext(StoreContext); + + if (!store) { + throw new Error("StoreContext is not available. Ensure StoreProvider is mounted."); + } const { isInit, @@ -48,7 +53,6 @@ export default function ProcessFacilitySearch() { upHeadList3, facilityWaterQltyList, facilityWaterQltyCount, - excelList, isLoading, } = FacilityWaterQltyMain; @@ -56,7 +60,6 @@ export default function ProcessFacilitySearch() { const [initTrigger, setInitTrigger] = useState(false); // 엑셀다운로드 트리거 const [isExcelDownClick, setIsExcelDownClick] = useState(false); - const excelWaitRef = useRef(false); // 그리드 관련 const [resetPage, setResetPage] = useState(false); const searchInputRef = useRef(null); @@ -73,7 +76,7 @@ export default function ProcessFacilitySearch() { const [fcltyCd, setFcltyCd] = useState(""); const [modalYear, setModalYear] = useState(""); - const searchFcltyQltyList = useCallback(({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt: number = 20) => { + const searchFcltyQltyList = useCallback(async ({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt: number = 20) => { let nameCd, partStr; switch (partValue) { case 'R': @@ -91,9 +94,9 @@ export default function ProcessFacilitySearch() { break; } if (partStr === 'G') { - searchFacilityWaterQltyList(pageNo, pageCnt, searchYearValue); + await searchFacilityWaterQltyList(pageNo, pageCnt, searchYearValue); } else { - searchFacilityWaterQltyList(pageNo, pageCnt, searchYearValue, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); + await searchFacilityWaterQltyList(pageNo, pageCnt, searchYearValue, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); } }, [operationValue, fcltyName, searchFacilityWaterQltyList, searchYearValue, fcltCpct]); @@ -153,43 +156,14 @@ export default function ProcessFacilitySearch() { } }, [isInit, initializeCommonData, searchFacilityWaterQltyList, searchFcltyQltyList, initTrigger]); - useEffect(() => { - if (!isExcelDownClick) return; - - if (isLoading) { - excelWaitRef.current = true; - return; - } - - if (!excelWaitRef.current) { - return; - } - - if (excelList && excelList.length > 0) { - downloadExcelFormat( - { - data: excelList as unknown as JSON[], - fileName: '시설별 수질현황', - sheetNameArray: ['시설별 수질현황'], - headerRange: 'A1:T1', - decimalArray1: [10, 11, 12, 15, 16, 17], - decimalArray3: [13, 14, 18, 19] - } - ); - } else { - alert("조회된 결과가 없습니다."); - } - setIsExcelDownClick(false); - excelWaitRef.current = false; - }, [excelList, isExcelDownClick, isLoading]); - const chkVal = useCallback((returntype: ReturnType) => { // setWidthSize(returntype.partValue=='A' ?"w-[120%]":"w-[130%]") setUpheadList(returntype.partValue == 'R' ? upHeadList2 : returntype.partValue == 'G' ? upHeadList3 : upHeadList1); setResetPage(true); }, [upHeadList1, upHeadList2, upHeadList3]); - const excelDownload = useCallback(() => { + const excelDownload = useCallback(async () => { + if (isExcelDownClick) return; if (ref.current.partValue === 'A') { // 행정별 if (!ref.current.sidoValue || ref.current.sidoValue === '0') { alert('엑셀 다운로드는 시도 조건을 선택한 후 이용 가능합니다.'); @@ -206,11 +180,28 @@ export default function ProcessFacilitySearch() { return; } } - - excelWaitRef.current = false; - searchFcltyQltyList(ref.current, 1, 10000); setIsExcelDownClick(true); - }, [searchFcltyQltyList]); + try { + await searchFcltyQltyList(ref.current, 1, 10000); + const latestExcelList = store.getState().FacilityWaterQltyMain.excelList || []; + if (latestExcelList.length > 0) { + downloadExcelFormat( + { + data: latestExcelList as unknown as JSON[], + fileName: '시설별 수질현황', + sheetNameArray: ['시설별 수질현황'], + headerRange: 'A1:T1', + decimalArray1: [10, 11, 12, 15, 16, 17], + decimalArray3: [13, 14, 18, 19] + } + ); + } else { + alert("조회된 결과가 없습니다."); + } + } finally { + setIsExcelDownClick(false); + } + }, [isExcelDownClick, searchFcltyQltyList, store]); const handlePageChange = useCallback((page: number) => { setResetPage(false); @@ -239,6 +230,7 @@ export default function ProcessFacilitySearch() { btnClass={btnClass} queryClick={chkVal} excelClick={excelDownload} + excelDisabled={isExcelDownClick} initClick={resetVal} ref={ref} isAdmin={false} initSidoValue={"11"} /> diff --git a/apps/fo/app/pages/(with-layout)/flowRate/page.tsx b/apps/fo/app/pages/(with-layout)/flowRate/page.tsx index 527c8d45e..d83386dee 100644 --- a/apps/fo/app/pages/(with-layout)/flowRate/page.tsx +++ b/apps/fo/app/pages/(with-layout)/flowRate/page.tsx @@ -5,13 +5,13 @@ */ "use client" -import { useFoStore } from "@/app/store"; +import { StoreContext, useFoStore } from "@/app/store"; import type { TableUpperProps } from "@/app/store/common"; // import type { ExcelType } from "@/app/store/flowRate"; import { ContentsDiv, downloadExcelFormat, MainDiv, SearchBaseForm, SearchInput, SelectBox, Title, UiModal, UiTable, type ReturnType } from "@common/business_components"; import ListDiv from "@common/business_components/ui/list_div"; import LoadingOverlay from "@common/business_components/ui/loadingBar"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import FlowRateModal from "./modal/page"; export default function ProcessFacilitySearch() { @@ -21,6 +21,11 @@ export default function ProcessFacilitySearch() { ,initializeCommonData ,searchFlowRateList } = useFoStore((state) => state); + const store = useContext(StoreContext); + + if (!store) { + throw new Error("StoreContext is not available. Ensure StoreProvider is mounted."); + } const searchInputRef = useRef(null); @@ -54,7 +59,6 @@ export default function ProcessFacilitySearch() { upHeadList3, flowRateList, flowRateCount, - excelList, isLoading, } = FlowRateList; @@ -73,10 +77,9 @@ export default function ProcessFacilitySearch() { const [fcltyNm, setFcltyNm] = useState(""); const [fcltyCd, setFcltyCd] = useState(""); const [isExcelDownClick, setIsExcelDownClick] = useState(false); - const excelWaitRef = useRef(false); const [initTrigger, setInitTrigger] = useState(false); - const searchFlowRate = useCallback(({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => { + const searchFlowRate = useCallback(async ({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => { let nameCd, partStr; switch (partValue) { @@ -95,9 +98,9 @@ export default function ProcessFacilitySearch() { break; } if(partStr==='G'){ - searchFlowRateList(pageNo, pageCnt, searchYearValue); + await searchFlowRateList(pageNo, pageCnt, searchYearValue); }else{ - searchFlowRateList(pageNo, pageCnt, searchYearValue, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); + await searchFlowRateList(pageNo, pageCnt, searchYearValue, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); } }, [searchFlowRateList, searchYearValue, fcltCpct, operationValue, fcltyName]); @@ -152,27 +155,6 @@ export default function ProcessFacilitySearch() { } }, [isInit, initializeCommonData, searchFlowRateList, selectSearchYear, searchFlowRate, initTrigger]); - useEffect(() => { - if(!isExcelDownClick) return; - - if (isLoading) { - excelWaitRef.current = true; - return; - } - - if (!excelWaitRef.current) { - return; - } - - if (excelList && excelList.length > 0) { - downloadExcelFormat({ data: JSON.parse(JSON.stringify(excelList)), fileName: '시설별 유량현황', sheetNameArray: ['시설별 유량현황'], headerRange: 'A1:O1', decimalArray0: [9,10,11,12,13,14] }); - } else { - alert('조회된 결과가 없습니다.'); - } - setIsExcelDownClick(false); - excelWaitRef.current = false; - }, [excelList, isExcelDownClick, isLoading]); - const ref = useRef({ partValue: '', sidoValue: '11', @@ -191,7 +173,8 @@ export default function ProcessFacilitySearch() { setResetPage(true); }, [upHeadList1, upHeadList2, upHeadList3]); - const excelDownload = useCallback(() => { + const excelDownload = useCallback(async () => { + if (isExcelDownClick) return; if (ref.current.partValue === 'A') { // 행정별 if (!ref.current.sidoValue || ref.current.sidoValue === '0') { alert('엑셀 다운로드는 시도 조건을 선택한 후 이용 가능합니다.'); @@ -208,11 +191,19 @@ export default function ProcessFacilitySearch() { return; } } - - excelWaitRef.current = false; - searchFlowRate(ref.current, 1, 10000); setIsExcelDownClick(true); - }, [searchFlowRate]); + try { + await searchFlowRate(ref.current, 1, 10000); + const latestExcelList = store.getState().FlowRateList.excelList || []; + if (latestExcelList.length > 0) { + downloadExcelFormat({ data: JSON.parse(JSON.stringify(latestExcelList)), fileName: '시설별 유량현황', sheetNameArray: ['시설별 유량현황'], headerRange: 'A1:O1', decimalArray0: [9,10,11,12,13,14] }); + } else { + alert('조회된 결과가 없습니다.'); + } + } finally { + setIsExcelDownClick(false); + } + }, [isExcelDownClick, searchFlowRate, store]); const total = flowRateCount; return ( @@ -237,6 +228,7 @@ export default function ProcessFacilitySearch() { queryClick={chkVal} excelClick={excelDownload} initClick={resetVal} + excelDisabled={isExcelDownClick} ref={ref} isAdmin={false} initSidoValue={'11'}/> diff --git a/apps/fo/app/pages/(with-layout)/planSewage/page.tsx b/apps/fo/app/pages/(with-layout)/planSewage/page.tsx index 3ad19c1bb..8b41524d1 100644 --- a/apps/fo/app/pages/(with-layout)/planSewage/page.tsx +++ b/apps/fo/app/pages/(with-layout)/planSewage/page.tsx @@ -5,11 +5,11 @@ */ "use client" -import { useFoStore } from "@/app/store"; +import { StoreContext, useFoStore } from "@/app/store"; import type { TableUpperProps } from "@/app/store/common"; import { downloadExcel, MainDiv, SearchBaseForm, SearchInput, SelectBox, Title, UiTable, type ReturnType } from "@common/business_components"; import ListDiv from "@common/business_components/ui/list_div"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import LoadingOverlay from "@common/business_components/ui/loadingBar"; import UnderComment from "@/app/components/common/UnderComment"; @@ -26,6 +26,11 @@ export default function PlanSewage() { , initializeCommonData , searchPlanSewageList } = useFoStore((state) => state) || { processAreaList: { processAreaList: [] } }; + const store = useContext(StoreContext); + + if (!store) { + throw new Error("StoreContext is not available. Ensure StoreProvider is mounted."); + } const { isInit, @@ -56,7 +61,6 @@ export default function PlanSewage() { upHeadList3, planSewageList, planSewageCount, - excelList, isLoading, } = PlanSewage; @@ -95,7 +99,6 @@ export default function PlanSewage() { const [initTrigger, setInitTrigger] = useState(false); // 엑셀다운로드 트리거 const [isExcelDownClick, setIsExcelDownClick] = useState(false); - const excelWaitRef = useRef(false); /** * 페이지 함수 @@ -120,37 +123,11 @@ export default function PlanSewage() { searchPlanSewage(ref.current, 1, 10); } - useEffect(() => { - if (!isExcelDownClick) return; - - if (isLoading) { - excelWaitRef.current = true; - return; - } - - if (!excelWaitRef.current) { - return; - } - - if (excelList && excelList.length > 0) { - downloadExcel({ - data: excelList as unknown as JSON[], - fileName: '계획하수량 산정지표 현황', - sheetNameArray: ['계획하수량 산정지표 현황'], - headerRange: 'A1:M1' - }); - } else { - alert("조회된 결과가 없습니다."); - } - setIsExcelDownClick(false); - excelWaitRef.current = false; - }, [excelList, isExcelDownClick, isLoading]); - /** * 콜백함수 */ // 조회 - const searchPlanSewage = useCallback(({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt: number = 20) => { + const searchPlanSewage = useCallback(async ({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt: number = 20) => { let nameCd, partStr switch (partValue) { case 'R': @@ -170,10 +147,10 @@ export default function PlanSewage() { if (partStr === 'G') { partValue = partValue === 'G' ? 'A' : partValue; - searchPlanSewageList(pageNo, pageCnt, searchYear, partValue); + await searchPlanSewageList(pageNo, pageCnt, searchYear, partValue); } else { - searchPlanSewageList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); + await searchPlanSewageList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); } }, [operationValue, fcltyName, searchPlanSewageList, searchYear, fcltCpct]); @@ -197,7 +174,8 @@ export default function PlanSewage() { }, [upHeadList1, upHeadList2, upHeadList3]); // 엑셀다운로드 - const excelDownload = useCallback((searchReturn: ReturnType) => { + const excelDownload = useCallback(async (searchReturn: ReturnType) => { + if (isExcelDownClick) return; if (ref.current.partValue === 'A') { // 행정별 if (!ref.current.sidoValue || ref.current.sidoValue === '0') { alert('엑셀 다운로드는 시도 조건을 선택한 후 이용 가능합니다.'); @@ -214,11 +192,24 @@ export default function PlanSewage() { return; } } - - excelWaitRef.current = false; - searchPlanSewage(searchReturn, 1, 10000); setIsExcelDownClick(true); - }, [searchPlanSewage]); + try { + await searchPlanSewage(searchReturn, 1, 10000); + const latestExcelList = store.getState().PlanSewage.excelList || []; + if (latestExcelList.length > 0) { + downloadExcel({ + data: latestExcelList as unknown as JSON[], + fileName: '계획하수량 산정지표 현황', + sheetNameArray: ['계획하수량 산정지표 현황'], + headerRange: 'A1:M1' + }); + } else { + alert("조회된 결과가 없습니다."); + } + } finally { + setIsExcelDownClick(false); + } + }, [isExcelDownClick, searchPlanSewage, store]); // 페이지 변경 const handlePageChange = useCallback((page: number) => { @@ -249,6 +240,7 @@ export default function PlanSewage() { btnClass={btnClass} queryClick={chkVal} excelClick={excelDownload} + excelDisabled={isExcelDownClick} initClick={resetVal} ref={ref} isAdmin={false} initSidoValue={"11"} /> diff --git a/apps/fo/app/pages/(with-layout)/processArea/page.tsx b/apps/fo/app/pages/(with-layout)/processArea/page.tsx index d4fb0e973..84d8ee8b1 100644 --- a/apps/fo/app/pages/(with-layout)/processArea/page.tsx +++ b/apps/fo/app/pages/(with-layout)/processArea/page.tsx @@ -5,11 +5,11 @@ */ "use client" -import { useFoStore } from "@/app/store"; +import { StoreContext, useFoStore } from "@/app/store"; import { useShallow } from 'zustand/react/shallow'; import { ContentsDiv, downloadExcel, MainDiv, SearchBaseForm, SelectBox, Title, UiModal, UiTable, type ReturnType } from "@common/business_components"; import ListDiv from "@common/business_components/ui/list_div"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import ProcessFacilityInfoModal from "./modal/page"; import LoadingOverlay from "@common/business_components/ui/loadingBar"; @@ -29,6 +29,11 @@ export default function ProcessArea() { searchProcessAreaList: state.searchProcessAreaList, })) ); + const store = useContext(StoreContext); + + if (!store) { + throw new Error("StoreContext is not available. Ensure StoreProvider is mounted."); + } const { isInit, @@ -55,7 +60,6 @@ export default function ProcessArea() { upHeadList1, processAreaList, processAreaCount, - excelList, isLoading, } = ProcessArea; @@ -72,7 +76,6 @@ export default function ProcessArea() { const [searchYearValue, setSearchYearValue] = useState(defaultSearchYear); const [isExcelDownClick, setIsExcelDownClick] = useState(false); - const excelWaitRef = useRef(false); const ref = useRef({ partValue: '', @@ -86,8 +89,8 @@ export default function ProcessArea() { sigunText: '', }); - const searchProcessArea = useCallback(({ sidoText, sigunText }: ReturnType, pageNo: number, pageCnt: number = 20) => { - searchProcessAreaList(pageNo, pageCnt, sidoText, sigunText, searchYearValue); + const searchProcessArea = useCallback(async ({ sidoText, sigunText }: ReturnType, pageNo: number, pageCnt: number = 20) => { + await searchProcessAreaList(pageNo, pageCnt, sidoText, sigunText, searchYearValue); }, [searchProcessAreaList, searchYearValue]); // 조회 @@ -128,33 +131,8 @@ export default function ProcessArea() { } }, [isInit, initializeCommonData, searchProcessAreaList, defaultSearchYear]); - useEffect(() => { - if(!isExcelDownClick) return; - - if (isLoading) { - excelWaitRef.current = true; - return; - } - - if (!excelWaitRef.current) { - return; - } - - if (excelList && excelList.length > 0) { - downloadExcel({ - data: excelList as unknown as JSON[], - fileName: '처리구역정보', - sheetNameArray: ['처리구역정보'], - headerRange: 'A1:W1' - }); - } else { - alert('조회된 결과가 없습니다.'); - } - setIsExcelDownClick(false); - excelWaitRef.current = false; - }, [excelList, isExcelDownClick, isLoading]); - - const excelDownload = useCallback(() => { + const excelDownload = useCallback(async () => { + if (isExcelDownClick) return; // if (ref.current.partValue === 'A') { // 행정별 // if (!ref.current.sidoValue || ref.current.sidoValue === '0') { // alert('엑셀 다운로드는 시도 조건을 선택한 후 이용 가능합니다.'); @@ -172,10 +150,24 @@ export default function ProcessArea() { // } // } - excelWaitRef.current = false; - searchProcessArea(ref.current, 1, 10000); setIsExcelDownClick(true); - }, [searchProcessArea]); + try { + await searchProcessArea(ref.current, 1, 10000); + const latestExcelList = store.getState().ProcessArea.excelList || []; + if (latestExcelList.length > 0) { + downloadExcel({ + data: latestExcelList as unknown as JSON[], + fileName: '처리구역정보', + sheetNameArray: ['처리구역정보'], + headerRange: 'A1:W1' + }); + } else { + alert('조회된 결과가 없습니다.'); + } + } finally { + setIsExcelDownClick(false); + } + }, [isExcelDownClick, searchProcessArea, store]); const handlePageChange = useCallback((pageNo: number) => { setResetPage(false); @@ -201,6 +193,7 @@ export default function ProcessArea() { btnClass={btnClass} queryClick={chkVal} excelClick={excelDownload} + excelDisabled={isExcelDownClick} initClick={resetVal} ref={ref} isAdmin={true} diff --git a/apps/fo/app/pages/(with-layout)/processFacility/page.tsx b/apps/fo/app/pages/(with-layout)/processFacility/page.tsx index 995f2e8e9..e73213bb1 100644 --- a/apps/fo/app/pages/(with-layout)/processFacility/page.tsx +++ b/apps/fo/app/pages/(with-layout)/processFacility/page.tsx @@ -6,11 +6,11 @@ "use client" import UnderComment from "@/app/components/common/UnderComment"; -import { useFoStore } from "@/app/store"; +import { StoreContext, useFoStore } from "@/app/store"; import { ContentsDiv, downloadExcel, MainDiv, SearchBaseForm, SearchInput, SelectBox, Title, UiModal, UiTable, type ReturnType } from "@common/business_components"; import ListDiv from "@common/business_components/ui/list_div"; import LoadingOverlay from "@common/business_components/ui/loadingBar"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import ProcessFacilityInfoModal from "./modal/page"; export default function ProcessFacilitySearch() { @@ -25,6 +25,11 @@ export default function ProcessFacilitySearch() { //시설데이터 수질정보 조회 ,searchProcessFacilityWaterQlty } = useFoStore((state) => state) || { ProcessFacilityList: { processFacilityList: [], processFacilityCount: 0 }}; + const store = useContext(StoreContext); + + if (!store) { + throw new Error("StoreContext is not available. Ensure StoreProvider is mounted."); + } const { isInit, @@ -69,7 +74,6 @@ export default function ProcessFacilitySearch() { upHeadList1, upHeadList2, upHeadList3, - excelList, isLoading, } = ProcessFacilityList; @@ -90,7 +94,6 @@ export default function ProcessFacilitySearch() { // const [widthSize, setWidthSize] = useState("w-[120%]"); const [upHeadList, setUpheadList] = useState(upHeadList1); const [isExcelDownClick, setIsExcelDownClick] = useState(false); - const excelWaitRef = useRef(false); /** * 모달 상태 변수 @@ -151,28 +154,7 @@ export default function ProcessFacilitySearch() { } }, [partValue, upHeadList1, upHeadList2, upHeadList3]); - useEffect(() => { - if (!isExcelDownClick) return; - - if (isLoading) { - excelWaitRef.current = true; - return; - } - - if (!excelWaitRef.current) { - return; - } - - if (excelList && excelList.length > 0) { - downloadExcel({ data: excelList as unknown as JSON[], fileName: '처리시설 시설정보', sheetNameArray: ['처리시설 시설정보'], headerRange: 'A1:P1' }); - } else { - alert('조회된 결과가 없습니다.'); - } - setIsExcelDownClick(false); - excelWaitRef.current = false; - }, [excelList, isExcelDownClick, isLoading]); - - const searchFcltyList = useCallback(({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=10) => { + const searchFcltyList = useCallback(async ({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=10) => { let nameCd, partStr switch (partValue) { case 'R': @@ -189,7 +171,7 @@ export default function ProcessFacilitySearch() { partStr = envPartValue !== '0' ? envPartValue:partValue; break; } - searchProcessFacility(pageNo, pageCnt, partStr, nameCd || '0', fcltCpct, operationValue, facilityPartValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); + await searchProcessFacility(pageNo, pageCnt, partStr, nameCd || '0', fcltCpct, operationValue, facilityPartValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); if(isSearch) { setIsSearch(false); } @@ -252,7 +234,8 @@ export default function ProcessFacilitySearch() { } } - const excelDownload = useCallback(() => { + const excelDownload = useCallback(async () => { + if (isExcelDownClick) return; // if (ref.current.partValue === 'A') { // 행정별 // if (!ref.current.sidoValue || ref.current.sidoValue === '0') { // alert('엑셀 다운로드는 시도 조건을 선택한 후 이용 가능합니다.'); @@ -270,10 +253,19 @@ export default function ProcessFacilitySearch() { // } // } - excelWaitRef.current = false; - searchFcltyList(ref.current, 1, 10000); setIsExcelDownClick(true); - }, [searchFcltyList]); + try { + await searchFcltyList(ref.current, 1, 10000); + const latestExcelList = store.getState().ProcessFacilityList.excelList || []; + if (latestExcelList.length > 0) { + downloadExcel({ data: latestExcelList as unknown as JSON[], fileName: '처리시설 시설정보', sheetNameArray: ['처리시설 시설정보'], headerRange: 'A1:P1' }); + } else { + alert('조회된 결과가 없습니다.'); + } + } finally { + setIsExcelDownClick(false); + } + }, [isExcelDownClick, searchFcltyList, store]); // 모달 닫기 const closeModal = () => { @@ -302,6 +294,7 @@ export default function ProcessFacilitySearch() { btnClass={btnClass} queryClick={chkVal} excelClick={excelDownload} + excelDisabled={isExcelDownClick} initClick={resetVal} ref={ref} isAdmin={false} /> diff --git a/apps/fo/app/pages/(with-layout)/rdi/page.tsx b/apps/fo/app/pages/(with-layout)/rdi/page.tsx index 8f601c299..459cd44ca 100644 --- a/apps/fo/app/pages/(with-layout)/rdi/page.tsx +++ b/apps/fo/app/pages/(with-layout)/rdi/page.tsx @@ -5,11 +5,11 @@ */ "use client" -import { useFoStore } from "@/app/store"; +import { StoreContext, useFoStore } from "@/app/store"; import type { TableUpperProps } from "@/app/store/common"; import { ContentsDiv, downloadExcel, MainDiv, SearchBaseForm, SearchInput, SelectBox, Title, UiTable, type ReturnType } from "@common/business_components"; import ListDiv from "@common/business_components/ui/list_div"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import LoadingOverlay from "@common/business_components/ui/loadingBar"; import UnderComment from "@/app/components/common/UnderComment"; @@ -26,6 +26,11 @@ export default function Rdi() { ,RdiSearch ,searchRdiList } = useFoStore((state) => state) || { processAreaList: { processAreaList: [] }}; + const store = useContext(StoreContext); + + if (!store) { + throw new Error("StoreContext is not available. Ensure StoreProvider is mounted."); + } const { isInit, @@ -56,7 +61,6 @@ export default function Rdi() { upHeadList3, rdiList, rdiCount, - excelList, isLoading, } = Rdi; @@ -91,7 +95,6 @@ export default function Rdi() { const [searchYear, setSearchYear] = useState(defaultSearchYear); // 엑셀 다운로드 트리거 const [isExcelDownClick, setIsExcelDownClick] = useState(false); - const excelWaitRef = useRef(false); const [initTrigger, setInitTrigger] = useState(false); @@ -119,37 +122,11 @@ export default function Rdi() { searchRdi(ref.current, 1, 10); } - useEffect(() => { - if(!isExcelDownClick) return ; - - if (isLoading) { - excelWaitRef.current = true; - return; - } - - if (!excelWaitRef.current) { - return; - } - - if (excelList && excelList.length > 0) { - downloadExcel({ - data: excelList as unknown as JSON[], - fileName: 'RDII추정', - sheetNameArray: ['RDII추정'], - headerRange: 'A1:R1' - }); - } else { - alert("조회된 결과가 없습니다."); - } - setIsExcelDownClick(false); - excelWaitRef.current = false; - }, [excelList, isExcelDownClick, isLoading]); - /** * 콜백함수 */ // 조회 - const searchRdi = useCallback(({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => { + const searchRdi = useCallback(async ({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => { let nameCd, partStr switch (partValue) { case 'R': @@ -168,10 +145,9 @@ export default function Rdi() { } if(partStr === 'G'){ - searchRdiList(pageNo, pageCnt, searchYear); + await searchRdiList(pageNo, pageCnt, searchYear); }else{ - searchRdiList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); - + await searchRdiList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue, fcltyName.trim() !== "" || fcltyName.trim() !== null ? fcltyName : undefined); } }, [operationValue, fcltyName, searchRdiList, searchYear, fcltCpct]); @@ -195,7 +171,8 @@ export default function Rdi() { }, [upHeadList1, upHeadList2, upHeadList3]); // 엑셀다운로드 - const excelDownload = useCallback(() => { + const excelDownload = useCallback(async () => { + if (isExcelDownClick) return; // if (ref.current.partValue === 'A') { // 행정별 // if (!ref.current.sidoValue || ref.current.sidoValue === '0') { // alert('엑셀 다운로드는 시도 조건을 선택한 후 이용 가능합니다.'); @@ -213,10 +190,24 @@ export default function Rdi() { // } // } - excelWaitRef.current = false; - searchRdi(ref.current, 1, 5000); setIsExcelDownClick(true); - }, [searchRdi]); + try { + await searchRdi(ref.current, 1, 5000); + const latestExcelList = store.getState().Rdi.excelList || []; + if (latestExcelList.length > 0) { + downloadExcel({ + data: latestExcelList as unknown as JSON[], + fileName: 'RDII추정', + sheetNameArray: ['RDII추정'], + headerRange: 'A1:R1' + }); + } else { + alert("조회된 결과가 없습니다."); + } + } finally { + setIsExcelDownClick(false); + } + }, [isExcelDownClick, searchRdi, store]); // 페이지 변경 const handlePageChange = useCallback((page: number) => { @@ -248,6 +239,7 @@ export default function Rdi() { btnClass={btnClass} queryClick={chkVal} excelClick={excelDownload} + excelDisabled={isExcelDownClick} initClick={resetVal} ref={ref} isAdmin={false} initSidoValue={"11"}/> diff --git a/apps/fo/app/pages/(with-layout)/sewageOccur/page.tsx b/apps/fo/app/pages/(with-layout)/sewageOccur/page.tsx index a9e990e82..4dc3125d1 100644 --- a/apps/fo/app/pages/(with-layout)/sewageOccur/page.tsx +++ b/apps/fo/app/pages/(with-layout)/sewageOccur/page.tsx @@ -6,13 +6,13 @@ */ "use client" -import { useFoStore } from "@/app/store"; +import { StoreContext, useFoStore } from "@/app/store"; import { type TableUpperProps } from "@/app/store/common"; import type { SewageOccurProps } from "@/app/store/sewageOccur"; import { ContentsDiv, downloadExcel, MainDiv, SearchBaseForm, SearchInput, SelectBox, Title, UiModal, UiTable, type ReturnType } from "@common/business_components"; import ListDiv from "@common/business_components/ui/list_div"; import LoadingOverlay from "@common/business_components/ui/loadingBar"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import SewageOccurModal from "./modal/page"; export default function PlanSewage() { @@ -29,6 +29,11 @@ export default function PlanSewage() { searchSewageOccurList: () => {}, calculateModalDataForAllFacilities: async () => [] }; + const store = useContext(StoreContext); + + if (!store) { + throw new Error("StoreContext is not available. Ensure StoreProvider is mounted."); + } const { isInit, @@ -59,7 +64,6 @@ export default function PlanSewage() { upHeadList3, sewageOccurList, sewageOccurCount, - excelList, isLoading, } = SewageOccur; @@ -99,10 +103,8 @@ export default function PlanSewage() { const [operationValue, setOperationValue] = useState("0"); // 조회기간 const [searchYear, setSearchYear] = useState(defaultSearchYear); - // 엑셀다운로드 트리거 + // 엑셀 조회 중 상태 const [isExcelDownClick, setIsExcelDownClick] = useState(false); - const excelWaitRef = useRef(false); - /** * 페이지 함수 */ @@ -149,37 +151,11 @@ export default function PlanSewage() { } }, [isInit, initializeCommonData, searchSewageOccurList, defaultSearchYear]); - useEffect(() => { - if(!isExcelDownClick) return ; - - if (isLoading) { - excelWaitRef.current = true; - return; - } - - if (!excelWaitRef.current) { - return; - } - - if (excelList && excelList.length > 0) { - downloadExcel({ - data: excelList as unknown as JSON[], - fileName: '오수발생량 추정', - sheetNameArray: ['오수발생량 추정'], - headerRange: 'A1:O1' - }); - } else { - alert("조회된 결과가 없습니다."); - } - setIsExcelDownClick(false); - excelWaitRef.current = false; - }, [excelList, isExcelDownClick, isLoading]); - /** * 콜백함수 */ // 조회 - const searchFacilityPrecipitation = useCallback(({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => { + const searchFacilityPrecipitation = useCallback(async ({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => { let nameCd, partStr switch (partValue) { case 'R': @@ -197,10 +173,10 @@ export default function PlanSewage() { break; } if (partStr.length > 1 || fcltCpct !== '0' || operationValue!== '0' ||nameCd ||(fcltyName.trim() !== "" && fcltyName.trim() !== null)) { - searchSewageOccurList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue + await searchSewageOccurList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue , fcltyName.trim() !== ""? fcltyName : undefined); } else { - searchSewageOccurList(pageNo, pageCnt, searchYear); + await searchSewageOccurList(pageNo, pageCnt, searchYear); } }, [fcltCpct, operationValue, fcltyName, searchSewageOccurList, searchYear]); @@ -211,7 +187,8 @@ export default function PlanSewage() { }, [upHeadList1, upHeadList2, upHeadList3]); // 엑셀다운로드 - const excelDownload = useCallback(() => { + const excelDownload = useCallback(async () => { + if (isExcelDownClick) return; if (ref.current.partValue === 'A') { // if (!ref.current.sidoValue || ref.current.sidoValue === '0') { alert('엑셀 다운로드는 시도 조건을 선택한 후 이용 가능합니다.'); @@ -228,10 +205,24 @@ export default function PlanSewage() { return; } } - excelWaitRef.current = false; - searchFacilityPrecipitation(ref.current, 1, 5000); setIsExcelDownClick(true); - }, [searchFacilityPrecipitation]); + try { + await searchFacilityPrecipitation(ref.current, 1, 5000); + const latestExcelList = store.getState().SewageOccur.excelList || []; + if (latestExcelList.length > 0) { + downloadExcel({ + data: latestExcelList as unknown as JSON[], + fileName: '오수발생량 추정', + sheetNameArray: ['오수발생량 추정'], + headerRange: 'A1:O1' + }); + } else { + alert("조회된 결과가 없습니다."); + } + } finally { + setIsExcelDownClick(false); + } + }, [isExcelDownClick, searchFacilityPrecipitation]); // 페이지 변경 const handlePageChange = useCallback((page: number) => { @@ -263,6 +254,7 @@ export default function PlanSewage() { btnClass={btnClass} queryClick={chkVal} excelClick={excelDownload} + excelDisabled={isExcelDownClick} initClick={resetVal} ref={ref} isAdmin={false} diff --git a/apps/fo/app/pages/(with-layout)/underWaterInput/page.tsx b/apps/fo/app/pages/(with-layout)/underWaterInput/page.tsx index 1b90b4584..4404403e3 100644 --- a/apps/fo/app/pages/(with-layout)/underWaterInput/page.tsx +++ b/apps/fo/app/pages/(with-layout)/underWaterInput/page.tsx @@ -7,11 +7,11 @@ */ "use client" -import { useFoStore } from "@/app/store"; +import { StoreContext, useFoStore } from "@/app/store"; import type { TableUpperProps } from "@/app/store/common"; import { ContentsDiv, downloadExcel, MainDiv, SearchBaseForm, SearchInput, SelectBox, Title, UiModal, UiTable, type ReturnType } from "@common/business_components"; import ListDiv from "@common/business_components/ui/list_div"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useContext, useEffect, useRef, useState } from "react"; import UnderWaterInputModal from "./modal/page"; import type { UnderWaterProps } from "@/app/store/underWaterInput/types"; import LoadingOverlay from "@common/business_components/ui/loadingBar"; @@ -35,6 +35,11 @@ export default function UnderWaterInput() { initializeCommonData: () => {}, searchUnderWaterList: () => {} }; + const store = useContext(StoreContext); + + if (!store) { + throw new Error("StoreContext is not available. Ensure StoreProvider is mounted."); + } const { isInit, @@ -65,7 +70,6 @@ export default function UnderWaterInput() { upHeadList3, underWaterList, underWaterCount, - excelList, isLoading, } = UnderWater; @@ -106,7 +110,6 @@ export default function UnderWaterInput() { const [searchYear, setSearchYear] = useState(defaultSearchYear); // 엑셀다운로드 트리거 const [isExcelDownClick, setIsExcelDownClick] = useState(false); - const excelWaitRef = useRef(false); /** * 페이지 함수 @@ -154,37 +157,11 @@ export default function UnderWaterInput() { } }, [isInit, initializeCommonData, searchUnderWaterList, defaultSearchYear]); - useEffect(() => { - if(!isExcelDownClick) return ; - - if (isLoading) { - excelWaitRef.current = true; - return; - } - - if (!excelWaitRef.current) { - return; - } - - if (excelList && excelList.length > 0) { - downloadExcel({ - data: excelList as unknown as JSON[], - fileName: '지하수유입량 추정', - sheetNameArray: ['지하수유입량 추정'], - headerRange: 'A1:O1' - }); - } else { - alert("조회된 결과가 없습니다."); - } - setIsExcelDownClick(false); - excelWaitRef.current = false; - }, [excelList, isExcelDownClick, isLoading]); - /** * 콜백함수 */ // 조회 - const searchFacilityPrecipitation = useCallback(({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => { + const searchFacilityPrecipitation = useCallback(async ({ partValue, regionValue, unitWaterShedValue, middleRegionValue, envPartValue, sidoValue, sigunValue }: ReturnType, pageNo: number, pageCnt:number=20) => { let nameCd, partStr switch (partValue) { case 'R': @@ -202,10 +179,10 @@ export default function UnderWaterInput() { break; } if (partStr.length > 1 || fcltCpct !== '0' || operationValue!== '0' ||nameCd ||(fcltyName.trim() !== "" && fcltyName.trim() !== null)) { - searchUnderWaterList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue + await searchUnderWaterList(pageNo, pageCnt, searchYear, partStr, nameCd || '0', fcltCpct, operationValue , fcltyName.trim() !== ""? fcltyName : undefined); } else { - searchUnderWaterList(pageNo, pageCnt, searchYear); + await searchUnderWaterList(pageNo, pageCnt, searchYear); } }, [fcltCpct, operationValue, fcltyName, searchUnderWaterList, searchYear]); @@ -216,7 +193,8 @@ export default function UnderWaterInput() { }, [upHeadList1, upHeadList2, upHeadList3]); // 엑셀다운로드 - const excelDownload = useCallback(() => { + const excelDownload = useCallback(async () => { + if (isExcelDownClick) return; if (ref.current.partValue === 'A') { // if (!ref.current.sidoValue || ref.current.sidoValue === '0') { alert('엑셀 다운로드는 시도 조건을 선택한 후 이용 가능합니다.'); @@ -233,10 +211,24 @@ export default function UnderWaterInput() { return; } } - excelWaitRef.current = false; - searchFacilityPrecipitation(ref.current, 1, 5000); setIsExcelDownClick(true); - }, [searchFacilityPrecipitation]); + try { + await searchFacilityPrecipitation(ref.current, 1, 5000); + const latestExcelList = store.getState().UnderWater.excelList || []; + if (latestExcelList.length > 0) { + downloadExcel({ + data: latestExcelList as unknown as JSON[], + fileName: '지하수유입량 추정', + sheetNameArray: ['지하수유입량 추정'], + headerRange: 'A1:O1' + }); + } else { + alert("조회된 결과가 없습니다."); + } + } finally { + setIsExcelDownClick(false); + } + }, [isExcelDownClick, searchFacilityPrecipitation, store]); // 페이지 변경 const handlePageChange = useCallback((page: number) => { @@ -268,6 +260,7 @@ export default function UnderWaterInput() { btnClass={btnClass} queryClick={chkVal} excelClick={excelDownload} + excelDisabled={isExcelDownClick} initClick={resetVal} ref={ref} isAdmin={false} diff --git a/packages/common/business_components/src/ui/search_base_form/index.tsx b/packages/common/business_components/src/ui/search_base_form/index.tsx index 82798db0b..9cef315c3 100644 --- a/packages/common/business_components/src/ui/search_base_form/index.tsx +++ b/packages/common/business_components/src/ui/search_base_form/index.tsx @@ -26,6 +26,7 @@ type SearchBaseType = { leftSelectClassName?: string; buttonOrder?: ("query" | "init" | "excel")[]; initSidoValue?: string | ''; + excelDisabled?: boolean; } export type ReturnType = { partValue: string; @@ -60,6 +61,7 @@ function SearchBaseForm ({ leftSelectClassName, buttonOrder, initSidoValue='', + excelDisabled=false, }: SearchBaseType) { const [partValue, setPartValue] = useState("A"); const [sidoValue, setSidoValue] = useState(initSidoValue?initSidoValue:"0"); @@ -87,7 +89,7 @@ function SearchBaseForm ({ ); case "excel": return ( - ); @@ -191,4 +193,4 @@ function SearchBaseForm ({ } export { SearchBaseForm }; - \ No newline at end of file +