[ST] input 특광역시 로직 수정, 일반검증 엑셀 다운로드 추가, 모든 number 타입 컬럼에 footer 추가
This commit is contained in:
@@ -5,6 +5,11 @@ import { useEffect, useState } from "react";
|
||||
import useSWR from "swr";
|
||||
|
||||
import { useAlertStore, useUserStore } from "@/shared/lib";
|
||||
import {
|
||||
fetchSearchCondition,
|
||||
fetchSearchConditionInput,
|
||||
SEARCH_CONDITION_SWR_KEY,
|
||||
} from "@/shared/lib/use-search-condition-sido-list";
|
||||
import { statisticsApi } from "@/entities/statistics/api/statistics-service";
|
||||
import type {
|
||||
ApiResponse,
|
||||
@@ -23,28 +28,28 @@ import {
|
||||
SelectValue,
|
||||
} from "@common/components";
|
||||
|
||||
import { doList } from "@/components/util/column/input/DoList";
|
||||
|
||||
import {
|
||||
defaultSearchFormProps,
|
||||
type SearchFormClsfCd,
|
||||
type SearchFormProps,
|
||||
type SearchFormValues,
|
||||
} from "../type/SearchForm.type";
|
||||
import { doList } from "../util/column/input/DoList";
|
||||
|
||||
const getSidoListFetcher = async (
|
||||
key: [string, string],
|
||||
): Promise<ApiResponse<SearchCondition>> => {
|
||||
return statisticsApi.getSidoList({ instSeCd: key[1] });
|
||||
};
|
||||
function isDoListBsnm(bsnmCd: string | undefined): boolean {
|
||||
return Boolean(bsnmCd && doList.includes(bsnmCd));
|
||||
}
|
||||
|
||||
const getSggListFetcher = async (
|
||||
key: [string, string, string, string],
|
||||
key: [string, string, string, "Y" | "N"],
|
||||
): Promise<ApiResponse<Sgg[]>> => {
|
||||
const gugunSkipYn = doList.includes(key[3]) ? "N" : "Y";
|
||||
return statisticsApi.getSggList(key[1], {
|
||||
instSeCd: key[2],
|
||||
gugunSkipYn,
|
||||
});
|
||||
const [, sidoName, instSeCd, gugunSkipYn] = key;
|
||||
const params = { instSeCd, gugunSkipYn };
|
||||
if (gugunSkipYn === "N") {
|
||||
return statisticsApi.getSggAllList(sidoName, params);
|
||||
}
|
||||
return statisticsApi.getSggList(sidoName, params);
|
||||
};
|
||||
|
||||
function buildSearchFormValues(
|
||||
@@ -59,9 +64,15 @@ function buildSearchFormValues(
|
||||
: "ALL";
|
||||
|
||||
if (d?.sido) {
|
||||
const sidoItem = sidoList?.data?.sidoList?.find(
|
||||
(item) => item.sido === d.sido,
|
||||
);
|
||||
const gugun =
|
||||
d.gugun ||
|
||||
(sidoItem && !isDoListBsnm(sidoItem.bsnmCd) ? "ALL" : "");
|
||||
return {
|
||||
sido: d.sido,
|
||||
gugun: d.gugun || "",
|
||||
gugun,
|
||||
year: d.year || defaultYear.toString(),
|
||||
order: d.order || "",
|
||||
fctName: d.fctName || "",
|
||||
@@ -93,7 +104,8 @@ function buildSearchFormValues(
|
||||
|
||||
return {
|
||||
sido: useFirstSido ? first.sido : "",
|
||||
gugun: "",
|
||||
gugun:
|
||||
useFirstSido && first && !isDoListBsnm(first.bsnmCd) ? "ALL" : "",
|
||||
year: d?.year || defaultYear.toString(),
|
||||
order: d?.order || "",
|
||||
fctName: d?.fctName || "",
|
||||
@@ -117,10 +129,12 @@ const SearchForm = (props: SearchFormProps = {}) => {
|
||||
|
||||
const currentYear = new Date().getFullYear();
|
||||
const defaultYear = currentYear - 1;
|
||||
const isInput = Boolean(props.isInput);
|
||||
const sidoListKind = isInput ? "input" : "default";
|
||||
|
||||
const { data: sidoList } = useSWR<ApiResponse<SearchCondition>>(
|
||||
["sido-list", instSeCd],
|
||||
getSidoListFetcher,
|
||||
SEARCH_CONDITION_SWR_KEY(instSeCd, sidoListKind),
|
||||
isInput ? fetchSearchConditionInput : fetchSearchCondition,
|
||||
{
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnReconnect: false,
|
||||
@@ -157,7 +171,7 @@ const SearchForm = (props: SearchFormProps = {}) => {
|
||||
: {
|
||||
...prev,
|
||||
sido: first.sido,
|
||||
gugun: "",
|
||||
gugun: isDoListBsnm(first.bsnmCd) ? "" : "ALL",
|
||||
bsnmCd: first.bsnmCd,
|
||||
},
|
||||
);
|
||||
@@ -168,9 +182,18 @@ const SearchForm = (props: SearchFormProps = {}) => {
|
||||
mergedProps.sido,
|
||||
]);
|
||||
|
||||
const sggKey: [string, string, string, string] | null =
|
||||
values.sido && values.sido !== "ALL"
|
||||
? ["sgg-list", values.sido, instSeCd, values.bsnmCd || ""]
|
||||
const selectedSido = sidoList?.data?.sidoList?.find(
|
||||
(item) => item.sido === values.sido,
|
||||
);
|
||||
const gugunSkipYn = selectedSido?.gugunSkipYn ?? "Y";
|
||||
const sggKey: [string, string, string, "Y" | "N"] | null =
|
||||
values.sido && values.sido !== "ALL" && sidoList?.data
|
||||
? [
|
||||
gugunSkipYn === "N" ? "sgg-all" : "sgg-list",
|
||||
values.sido,
|
||||
instSeCd,
|
||||
gugunSkipYn,
|
||||
]
|
||||
: null;
|
||||
const { data: sggList } = useSWR<ApiResponse<Sgg[]>>(
|
||||
sggKey,
|
||||
@@ -195,12 +218,25 @@ const SearchForm = (props: SearchFormProps = {}) => {
|
||||
);
|
||||
const sggOptions = sggList?.data ?? [];
|
||||
|
||||
// 시도 설정 후 시군구 목록이 오면 첫 번째 항목 자동 선택
|
||||
// 도(doList): 시군구 목록 첫 항목. 광역시·세종·제주: 전체
|
||||
useEffect(() => {
|
||||
if (!mergedProps.gugun) return;
|
||||
if (props.defaultRegionAll) return;
|
||||
if (props.defaultValues?.gugun) return;
|
||||
if (!values.sido || values.sido === "ALL") return;
|
||||
if (!selectedSido) return;
|
||||
|
||||
if (!isDoListBsnm(selectedSido.bsnmCd)) {
|
||||
setValues((prev) => {
|
||||
if (prev.gugun) return prev;
|
||||
return {
|
||||
...prev,
|
||||
gugun: "ALL",
|
||||
bsnmCd: selectedSido?.bsnmCd || prev.bsnmCd,
|
||||
};
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const firstSgg = sggList?.data?.[0];
|
||||
if (!firstSgg) return;
|
||||
@@ -216,6 +252,7 @@ const SearchForm = (props: SearchFormProps = {}) => {
|
||||
}, [
|
||||
sggList,
|
||||
values.sido,
|
||||
selectedSido?.bsnmCd,
|
||||
mergedProps.gugun,
|
||||
props.defaultValues?.gugun,
|
||||
props.defaultRegionAll,
|
||||
@@ -237,10 +274,14 @@ const SearchForm = (props: SearchFormProps = {}) => {
|
||||
? ""
|
||||
: sidoList?.data?.sidoList?.find((v) => v.sido === value)
|
||||
?.bsnmCd || "";
|
||||
const gugunAll =
|
||||
props.defaultRegionAll ||
|
||||
value === "ALL" ||
|
||||
!isDoListBsnm(selectedBsnm);
|
||||
setValues((prev) => ({
|
||||
...prev,
|
||||
sido: value,
|
||||
gugun: props.defaultRegionAll || value === "ALL" ? "ALL" : "",
|
||||
gugun: gugunAll ? "ALL" : "",
|
||||
bsnmCd: selectedBsnm,
|
||||
}));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user