diff --git a/apps/dm_new/app/(with-layout)/apply/dmdco/page.tsx b/apps/dm_new/app/(with-layout)/apply/dmdco/page.tsx
index ef219cf2a..9c403c4bd 100644
--- a/apps/dm_new/app/(with-layout)/apply/dmdco/page.tsx
+++ b/apps/dm_new/app/(with-layout)/apply/dmdco/page.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useEffect, useMemo, useState, type ReactNode } from "react";
+import { useEffect, useMemo, useRef, useState, type ReactNode, type RefObject } from "react";
import SubPageHeader from "@/components/SubPageHeader";
import PostcodeModal from "@/components/PostcodeModal";
import type { AddrItem } from "@/app/store/sdmMng/postcode-service";
@@ -29,6 +29,36 @@ const isSameRegionName = (left: string, right: string) => {
const b = normalizeRegionName(right);
return Boolean(a && b && (a === b || a.includes(b) || b.includes(a)));
};
+const formatKoreanPhoneNumber = (value: string) => {
+ const digits = value.replace(/\D/g, "").slice(0, 11); // 숫자만 추출하고 최대 11자리까지만 사용
+ if (!digits) return ""; // 입력이 비어 있으면 빈 문자열 반환
+
+ if (/^1\d{0,7}$/.test(digits)) { // 15xx/16xx/18xx 같은 대표번호 패턴
+ if (digits.length <= 4) return digits; // 아직 뒷자리가 부족하면 원문 유지
+ return `${digits.slice(0, 4)}-${digits.slice(4, 8)}`; // xxxx-xxxx
+ }
+
+ if (digits.startsWith("02")) { // 서울 지역번호(02)
+ const rest = digits.slice(2); // 국번/가입자번호 구간
+ if (!rest) return "02"; // 02만 입력된 상태
+ if (rest.length <= 3) return `02-${rest}`; // 02-xxx
+ if (rest.length <= 7) return `02-${rest.slice(0, 3)}-${rest.slice(3)}`; // 02-xxx-xxxx
+ return `02-${rest.slice(0, 4)}-${rest.slice(4, 8)}`; // 02-xxxx-xxxx
+ }
+
+ if (digits.startsWith("0")) { // 02 제외 일반 지역번호/휴대폰(010 포함)
+ const area = digits.slice(0, 3); // 앞 3자리 식별자
+ const rest = digits.slice(3); // 나머지 번호
+ if (!rest) return area; // 식별자만 입력된 상태
+ if (rest.length <= 3) return `${area}-${rest}`; // 0xx-xxx
+ if (rest.length <= 7) return `${area}-${rest.slice(0, 3)}-${rest.slice(3)}`; // 0xx-xxx-xxxx
+ return `${area}-${rest.slice(0, 4)}-${rest.slice(4, 8)}`; // 0xx-xxxx-xxxx
+ }
+
+ if (digits.length <= 4) return digits; // 예외 입력: 앞 4자리까지
+ if (digits.length <= 8) return `${digits.slice(0, 4)}-${digits.slice(4)}`; // xxxx-xxxx
+ return `${digits.slice(0, 4)}-${digits.slice(4, 8)}-${digits.slice(8, 11)}`; // xxxx-xxxx-xxx
+};
function Divider() {
return
;
@@ -63,6 +93,7 @@ function TextInput({
placeholder,
type = "text",
disabled,
+ inputRef,
className = "",
}: {
value: string;
@@ -70,10 +101,12 @@ function TextInput({
placeholder?: string;
type?: string;
disabled?: boolean;
+ inputRef?: RefObject;
className?: string;
}) {
return (
(null);
const [tel, setTel] = useState("");
const [pw, setPw] = useState("");
@@ -178,7 +213,7 @@ export default function DemandPlaceRegisterPage() {
setCompany(String(user.dmdCoNm ?? ""));
setAddr1(String(user.daddr ?? ""));
setAddr2("");
- setTel(String(user.telno ?? "").replace(/\D/g, ""));
+ setTel(formatKoreanPhoneNumber(String(user.telno ?? "")));
setSido(String(user.ctpvCd ?? ""));
setSigungu(String(user.sggCd ?? ""));
} catch {
@@ -187,6 +222,22 @@ export default function DemandPlaceRegisterPage() {
}
}, []);
+ useEffect(() => {
+ if (!focusDetailAddrOnClose || isPostcodeModalOpen) return;
+
+ if (!addr1.trim()) {
+ setFocusDetailAddrOnClose(false);
+ return;
+ }
+
+ const timer = setTimeout(() => {
+ detailAddrRef.current?.focus();
+ setFocusDetailAddrOnClose(false);
+ }, 0);
+
+ return () => clearTimeout(timer);
+ }, [addr1, focusDetailAddrOnClose, isPostcodeModalOpen]);
+
const sidoOptions = useMemo