diff options
Diffstat (limited to 'components/additional-info/join-form.tsx')
| -rw-r--r-- | components/additional-info/join-form.tsx | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/components/additional-info/join-form.tsx b/components/additional-info/join-form.tsx index afe38841..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> @@ -1960,7 +2009,6 @@ export function InfoForm() { assignedDepartment: registrationData.registration?.assignedDepartment, assignedUser: registrationData.registration?.assignedUser, remarks: registrationData.registration?.remarks, - safetyQualificationContent: registrationData.registration?.safetyQualificationContent || null, gtcSkipped: registrationData.registration?.gtcSkipped || false, additionalInfo: registrationData.additionalInfo, documentSubmissions: registrationData.documentStatus, |
