wr: 시도,시군구 전체"0" 2건 조회현상 수정
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
ruseSeCd,
|
||||
yn,
|
||||
} from "./basicCode";
|
||||
import { normalizeSelectData } from "./normalizeSelectData";
|
||||
export const btnClass = "p-4 m-2 rounded-sm text-lg font-medium text-primary-foreground ";
|
||||
|
||||
const laeSecd = "41";
|
||||
@@ -133,11 +134,12 @@ export const getSggCd = async (set: any) => {
|
||||
};
|
||||
export const getCityCd = async (set: any) => {
|
||||
const city = await getFetch("common", "/addr/city");
|
||||
const cityCd = city.map((item: any) => ({
|
||||
val: item.adstDstrCd,
|
||||
text: item.sido,
|
||||
}));
|
||||
cityCd.unshift({ val: "0", text: "전체" });
|
||||
const cityCd = normalizeSelectData(
|
||||
city.map((item: any) => ({
|
||||
val: item.adstDstrCd,
|
||||
text: item.sido,
|
||||
})),
|
||||
);
|
||||
set((state: comCodeState) => ({
|
||||
code: {
|
||||
...state.code,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
type SelectDataInput = {
|
||||
text?: string | null;
|
||||
val?: string | number | null;
|
||||
};
|
||||
|
||||
export type NormalizedSelectData = {
|
||||
text: string;
|
||||
val: string;
|
||||
};
|
||||
|
||||
/** 선택 목록을 값 기준으로 중복 제거하고 프런트 표준 전체 항목을 한 번만 추가한다. */
|
||||
export const normalizeSelectData = (
|
||||
items: readonly SelectDataInput[],
|
||||
): NormalizedSelectData[] => {
|
||||
const uniqueItems = new Map<string, NormalizedSelectData>();
|
||||
|
||||
items.forEach((item) => {
|
||||
const val = String(item.val ?? "").trim();
|
||||
if (!val || val === "0" || uniqueItems.has(val)) return;
|
||||
|
||||
uniqueItems.set(val, {
|
||||
text: String(item.text ?? ""),
|
||||
val,
|
||||
});
|
||||
});
|
||||
|
||||
return [{ text: "전체", val: "0" }, ...uniqueItems.values()];
|
||||
};
|
||||
Reference in New Issue
Block a user