From e7a32905cb2552975a4af65f6e94707b94108131 Mon Sep 17 00:00:00 2001 From: ljpark Date: Mon, 16 Nov 2026 11:09:55 +0900 Subject: [PATCH] =?UTF-8?q?wr:=20=EC=88=98=EC=9A=94=EC=B2=98=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95=20-=20selectBox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wr/.env.local | 12 +- .../src/ui/sdmInsertForm/form.tsx | 176 +++++++++++++----- .../src/ui/select/index.tsx | 4 +- 3 files changed, 143 insertions(+), 49 deletions(-) diff --git a/apps/wr/.env.local b/apps/wr/.env.local index 999335951..ad382980f 100644 --- a/apps/wr/.env.local +++ b/apps/wr/.env.local @@ -7,16 +7,16 @@ NEXT_PUBLIC_REFRESH_TOKEN = refresh-token NEXT_PUBLIC_PROXY_HOST = http://localhost:3001 NEXT_PUBLIC_SUB_DOMAIN = http://localhost:13000 SERVER_API_URL = http://dev.onasys.co.kr:8000 -# FO_SERVER_API_URL = http://con.mind-one.co.kr:11083/operation-service/api/v1 -FO_SERVER_API_URL = http://localhost:8883/operation-service/api/v1 +FO_SERVER_API_URL = http://con.mind-one.co.kr:11083/operation-service/api/v1 +# FO_SERVER_API_URL = http://localhost:8883/operation-service/api/v1 CS_SERVER_API_URL = http://dev.onasys.co.kr:8000 NEXT_PUBLIC_CS_TUS_UPLOAD = /attach-service/api/v1/tus/upload NEXT_PUBLIC_GEOSERVER_URL = https://hasudo.geo.rsonesoft.com/geoserver NEXT_PUBLIC_LX_GEOSERVER_URL = http://con.mind-one.co.kr:11306/geoserver -# WR_SERVER_API_URL = http://con.mind-one.co.kr:11083/reuse-service/api/v1 -WR_SERVER_API_URL = http://localhost:8883/reuse-service/api/v1 -# SEWERAGE_API_URL = http://con.mind-one.co.kr:11083/sewerage-service # 개발 서버 API -SEWERAGE_API_URL=http://localhost:8883/sewerage-service +WR_SERVER_API_URL = http://con.mind-one.co.kr:11083/reuse-service/api/v1 +#WR_SERVER_API_URL = http://localhost:8883/reuse-service/api/v1 +SEWERAGE_API_URL = http://con.mind-one.co.kr:11083/sewerage-service # 개발 서버 API +# SEWERAGE_API_URL=http://localhost:8883/sewerage-service NEXT_PUBLIC_NGII_URL = https://map.ngii.go.kr NEXT_PUBLIC_NGII_PARAM = 04trYP9_xwLAfALjwZ-B8g&service=WMTS&request=GetTile&version=1.0.0&format=image/png&layer=korean_map&style=korean&tilematrixset=korean&tilematrix={z}&tilecol={x}&tilerow={y} # NEXT_PUBLIC_CM_LOGIN_PAGE_URL = http://dev.onasys.co.kr:3000/auth/login diff --git a/packages/common/business_components/src/ui/sdmInsertForm/form.tsx b/packages/common/business_components/src/ui/sdmInsertForm/form.tsx index 17ecc6611..aba0e0040 100644 --- a/packages/common/business_components/src/ui/sdmInsertForm/form.tsx +++ b/packages/common/business_components/src/ui/sdmInsertForm/form.tsx @@ -8,6 +8,25 @@ import { FormField } from "../form"; import { FormUi } from "../form_ui"; import { SdmSearchForm } from "./sdmNameBox"; import { SearchAddressModal } from "../search_address/SearchAddressModal"; +import { SelectBox } from "../select"; + +/** + * 시도명 비교용 정규화 + * "인천광역시"/"인천", "강원특별자치도"/"강원도" 같은 표기 차이를 흡수한다. + * @param value 시도명 + */ +const normalizeSidoName = (value?: string) => + (value?.replace(/\s+/g, "").trim() ?? "").replace( + /(특별자치도|특별자치시|특별시|광역시|도)$/, + "", + ); + +/** + * 시군구명 비교용 정규화 (공백 제거) + * @param value 시군구명 + */ +const normalizeSggName = (value?: string) => + value?.replace(/\s+/g, "").trim() ?? ""; // 수요처 정보 export type DemandCompType = { @@ -212,15 +231,12 @@ export function SdmRegForm({ const applyZipRegion = useCallback( (ctpvNm?: string, sggNm?: string) => { - const normalizeRegionName = (value?: string) => - value?.replace(/\s+/g, "").trim() ?? ""; - - const sidoName = normalizeRegionName(ctpvNm); - const sigunName = normalizeRegionName(sggNm); + const sidoName = normalizeSidoName(ctpvNm); + const sigunName = normalizeSggName(sggNm); if (!sidoName) return; const matchedSido = selectSidoData.find( - (item) => normalizeRegionName(item.text) === sidoName, + (item) => normalizeSidoName(item.text) === sidoName, ); if (!matchedSido) return; @@ -235,16 +251,17 @@ export function SdmRegForm({ const matchedSigun = sigunCandidates.find( - (item) => normalizeRegionName(item.text) === sigunName, + (item) => normalizeSggName(item.text) === sigunName, ) ?? sigunCandidates.find((item) => { - const itemName = normalizeRegionName(item.text); + const itemName = normalizeSggName(item.text); return itemName.includes(sigunName) || sigunName.includes(itemName); }); - if (!matchedSigun) return; - - form.setValue("sggCd", matchedSigun.val, { shouldValidate: true }); + // 못 찾으면 비워 두고 사용자가 직접 선택한다 + if (matchedSigun) { + form.setValue("sggCd", matchedSigun.val, { shouldValidate: true }); + } }, [form, initializeSigunData, selectSidoData, selectSigunData], ); @@ -289,6 +306,12 @@ export function SdmRegForm({ handleCheckboxChange(true); } form.setValue("dmdInfoId", updateList?.dmdInfoId.slice(0, 10)); + // 저장된 시도/시군구 코드를 공백 제거한 문자열로 맞춰 SelectBox 값과 일치시킨다 + const savedSido = String(updateList?.ctpvCd ?? "").trim(); + const savedSigun = String(updateList?.sggCd ?? "").trim(); + // 시도 코드가 비어 있으면 시군구 코드 앞 2자리로 보완한다 + form.setValue("ctpvCd", savedSido || savedSigun.substring(0, 2)); + form.setValue("sggCd", savedSigun); setZoneNo(updateList?.zip || ""); form.setValue("zip", updateList?.zip || ""); setAddress(updateList?.daddr || ""); @@ -305,8 +328,26 @@ export function SdmRegForm({ } }, [updateList, form]); + // 수정 모드: 저장된 시도 코드가 시도 목록에 없으면 시군구 코드 앞 2자리로 보정한다 useEffect(() => { - console.log("form.formState.errors ", form.formState.errors); + if (!updateList?.dmdInfoId || selectSidoData.length === 0) return; + + const savedSido = String(form.getValues("ctpvCd") ?? "").trim(); + const savedSigun = String(form.getValues("sggCd") ?? "").trim(); + const sidoExists = selectSidoData.some((item) => item.val === savedSido); + + if (sidoExists || !savedSigun) return; + const derivedSido = savedSigun.substring(0, 2); + if (selectSidoData.some((item) => item.val === derivedSido)) { + form.setValue("ctpvCd", derivedSido); + } + }, [updateList, selectSidoData, form]); + + useEffect(() => { + // 에러가 있을 때에만 출력한다 + if (Object.keys(form.formState.errors).length > 0) { + console.log("form.formState.errors ", form.formState.errors); + } }, [form.formState.errors]); // 주소와 상세주소를 각각 별도 필드로 유지합니다. @@ -438,40 +479,91 @@ export function SdmRegForm({ { name: "ctpvCd", label: "시도", - component: (field) => ( - { - field.onChange(e.target.value); - }} - value={ - selectSidoData.find((item) => item.val === field.value?.trim()) - ?.text ?? "" - } - readOnly={true} - /> - ), + component: (field) => + readOnly ? ( + item.val === field.value?.trim()) + ?.text ?? "" + } + readOnly={true} + /> + ) : ( + item.val !== "0"), + ]} + value={field.value?.trim() ?? ""} + onSelectValue={(val) => { + const next = String(val); + // Radix Select가 값 동기화 중 빈 값/동일 값으로 호출하는 경우는 무시 + // (무시하지 않으면 수정 모드에서 저장된 시도·시군구가 지워진다) + if (!next || next === (field.value ?? "").trim()) return; + field.onChange(next); + // 시도 변경 시 시군구 초기화 + form.setValue("sggCd", "", { shouldValidate: true }); + }} + /> + ), }, { name: "sggCd", label: "시군구", - component: (field) => ( - { - field.onChange(e.target.value); - }} - value={ - selectSigunData.find((item) => item.val === field.value?.trim()) - ?.text ?? "" - } - readOnly={true} - /> - ), + component: (field) => { + const sidoCd = form.watch("ctpvCd")?.trim() ?? ""; + // 선택된 시도에 속한 시군구만 표시 (코드 앞 2자리 = 시도 코드) + const sigunList = sidoCd + ? selectSigunData.filter( + (item) => + item.val !== "0" && item.val.substring(0, 2) === sidoCd, + ) + : []; + // 수정 모드: 저장된 시군구가 목록에 없더라도 선택된 상태로 보이도록 포함 + const savedSigun = selectSigunData.find( + (item) => item.val === field.value?.trim(), + ); + if (savedSigun && !sigunList.some((i) => i.val === savedSigun.val)) { + sigunList.push(savedSigun); + } + + return readOnly ? ( + item.val === field.value?.trim()) + ?.text ?? "" + } + readOnly={true} + /> + ) : ( + { + const next = String(val); + // Radix Select의 빈 값/동일 값 동기화 호출은 무시 + if (!next || next === (field.value ?? "").trim()) return; + field.onChange(next); + }} + /> + ); + }, }, { name: "telno", diff --git a/packages/common/business_components/src/ui/select/index.tsx b/packages/common/business_components/src/ui/select/index.tsx index 9dbfedb83..9a8bd67ce 100644 --- a/packages/common/business_components/src/ui/select/index.tsx +++ b/packages/common/business_components/src/ui/select/index.tsx @@ -94,7 +94,9 @@ const SelectBox = React.forwardRef< } }} onValueChange={onSelectValue} - value={currentValue} + // value를 넘긴 경우에만 항상 controlled로 유지한다(빈 값은 "" → placeholder 표시). + // value 미전달(uncontrolled) 사용처는 기존 동작을 유지한다. + value={value !== undefined ? (currentValue ?? "") : currentValue} // disabled={readOnly} //물재이용 감리 지적사항으로 일단 주석처리 >