wr: 수요처 등록 수정 - selectBox
This commit is contained in:
+6
-6
@@ -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
|
||||
|
||||
@@ -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) => (
|
||||
<Input
|
||||
placeholder="시도"
|
||||
type="text"
|
||||
className={getReadonlyInputClassName(true)}
|
||||
onChange={(e) => {
|
||||
field.onChange(e.target.value);
|
||||
}}
|
||||
value={
|
||||
selectSidoData.find((item) => item.val === field.value?.trim())
|
||||
?.text ?? ""
|
||||
}
|
||||
readOnly={true}
|
||||
/>
|
||||
),
|
||||
component: (field) =>
|
||||
readOnly ? (
|
||||
<Input
|
||||
placeholder="시도"
|
||||
type="text"
|
||||
className={getReadonlyInputClassName(true)}
|
||||
value={
|
||||
selectSidoData.find((item) => item.val === field.value?.trim())
|
||||
?.text ?? ""
|
||||
}
|
||||
readOnly={true}
|
||||
/>
|
||||
) : (
|
||||
<SelectBox
|
||||
label=""
|
||||
selectClass={undefined}
|
||||
className=""
|
||||
selectArray={[
|
||||
{ text: "시도 선택", val: "", hidden: true },
|
||||
// 공통코드의 "전체"(val=0)는 등록 폼에서 선택 대상이 아니므로 제외
|
||||
...selectSidoData.filter((item) => 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) => (
|
||||
<Input
|
||||
placeholder="시군구"
|
||||
type="text"
|
||||
className={getReadonlyInputClassName(true)}
|
||||
onChange={(e) => {
|
||||
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 ? (
|
||||
<Input
|
||||
placeholder="시군구"
|
||||
type="text"
|
||||
className={getReadonlyInputClassName(true)}
|
||||
value={
|
||||
selectSigunData.find((item) => item.val === field.value?.trim())
|
||||
?.text ?? ""
|
||||
}
|
||||
readOnly={true}
|
||||
/>
|
||||
) : (
|
||||
<SelectBox
|
||||
label=""
|
||||
selectClass={undefined}
|
||||
className=""
|
||||
selectArray={[
|
||||
{ text: "시군구 선택", val: "", hidden: true },
|
||||
...sigunList,
|
||||
]}
|
||||
value={field.value?.trim() ?? ""}
|
||||
onSelectValue={(val) => {
|
||||
const next = String(val);
|
||||
// Radix Select의 빈 값/동일 값 동기화 호출은 무시
|
||||
if (!next || next === (field.value ?? "").trim()) return;
|
||||
field.onChange(next);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "telno",
|
||||
|
||||
@@ -94,7 +94,9 @@ const SelectBox = React.forwardRef<
|
||||
}
|
||||
}}
|
||||
onValueChange={onSelectValue}
|
||||
value={currentValue}
|
||||
// value를 넘긴 경우에만 항상 controlled로 유지한다(빈 값은 "" → placeholder 표시).
|
||||
// value 미전달(uncontrolled) 사용처는 기존 동작을 유지한다.
|
||||
value={value !== undefined ? (currentValue ?? "") : currentValue}
|
||||
// disabled={readOnly} //물재이용 감리 지적사항으로 일단 주석처리
|
||||
>
|
||||
<SelectTrigger className={cn("selectbox_trigger", selectClass)}>
|
||||
|
||||
Reference in New Issue
Block a user