From cf3f7cf0efa2753a401b36f6eb3a49cb9697ddce Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 9 Dec 2025 06:09:09 +0000
Subject: (최겸) 구매 rfq, 기술영업 rfq drm 해제 시 결재 상신에 첨부파일 포함
 로직 적용
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 components/additional-info/join-form.tsx | 59 +++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 5 deletions(-)

(limited to 'components/additional-info/join-form.tsx')

diff --git a/components/additional-info/join-form.tsx b/components/additional-info/join-form.tsx
index fe5698d8..1642962f 100644
--- a/components/additional-info/join-form.tsx
+++ b/components/additional-info/join-form.tsx
@@ -223,6 +223,8 @@ export function InfoForm() {
   })
 
   const isFormValid = form.formState.isValid
+  const watchedCountry = form.watch("country")
+  const isDomesticVendor = watchedCountry === "KR"
 
   // Field array for contacts
   const { fields: contactFields, append: addContact, remove: removeContact, replace: replaceContacts } =
@@ -369,6 +371,29 @@ export function InfoForm() {
     fetchVendorData()
   }, [companyId, form, replaceContacts])
 
+  // 도로명주소 검색 결과 수신 (내자 벤더만)
+  React.useEffect(() => {
+    if (!isDomesticVendor) return
+
+    const handleMessage = (event: MessageEvent) => {
+      if (!event.data || event.data.type !== "JUSO_SELECTED") return
+      const { zipNo, roadAddrPart1, roadAddrPart2, addrDetail } = event.data.payload || {}
+      const road = [roadAddrPart1, roadAddrPart2].filter(Boolean).join(" ").trim()
+
+      form.setValue("postalCode", zipNo || form.getValues("postalCode") || "", { shouldDirty: true })
+      form.setValue("address", road || form.getValues("address") || "", { shouldDirty: true })
+      form.setValue("addressDetail", addrDetail || form.getValues("addressDetail") || "", { shouldDirty: true })
+    }
+
+    window.addEventListener("message", handleMessage)
+    return () => window.removeEventListener("message", handleMessage)
+  }, [isDomesticVendor, form])
+
+  const handleJusoSearch = () => {
+    if (!isDomesticVendor) return
+    window.open("/api/juso", "jusoSearch", "width=570,height=420,scrollbars=yes,resizable=yes")
+  }
+
   // 컴포넌트 언마운트 시 미리보기 URL 정리 (blob URL만)
   React.useEffect(() => {
     return () => {
@@ -1224,11 +1249,29 @@ export function InfoForm() {
                     name="address"
                     render={({ field }) => (
                       <FormItem>
-                        <FormLabel className="after:content-['*'] after:ml-0.5 after:text-red-500">
-                          주소
-                        </FormLabel>
+                        <div className="flex items-center justify-between gap-2">
+                          <FormLabel className="after:content-['*'] after:ml-0.5 after:text-red-500">
+                            주소
+                          </FormLabel>
+                          {isDomesticVendor && (
+                            <Button
+                              type="button"
+                              variant="secondary"
+                              size="sm"
+                              onClick={handleJusoSearch}
+                              disabled={isSubmitting}
+                            >
+                              주소 검색
+                            </Button>
+                          )}
+                        </div>
                         <FormControl>
-                          <Input {...field} disabled={isSubmitting} />
+                          <Input
+                            {...field}
+                            disabled={isSubmitting}
+                            readOnly={isDomesticVendor}
+                            className={cn(isDomesticVendor && "bg-muted text-muted-foreground")}
+                          />
                         </FormControl>
                         <FormMessage />
                       </FormItem>
@@ -1258,7 +1301,13 @@ export function InfoForm() {
                       <FormItem>
                         <FormLabel>우편번호</FormLabel>
                         <FormControl>
-                          <Input {...field} disabled={isSubmitting} placeholder="우편번호를 입력해주세요" />
+                          <Input
+                            {...field}
+                            disabled={isSubmitting}
+                            readOnly={isDomesticVendor}
+                            className={cn(isDomesticVendor && "bg-muted text-muted-foreground")}
+                            placeholder="우편번호를 입력해주세요"
+                          />
                         </FormControl>
                         <FormMessage />
                       </FormItem>
-- 
cgit v1.2.3

