summaryrefslogtreecommitdiff
path: root/lib/site-visit/vendor-info-sheet.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/site-visit/vendor-info-sheet.tsx')
-rw-r--r--lib/site-visit/vendor-info-sheet.tsx58
1 files changed, 55 insertions, 3 deletions
diff --git a/lib/site-visit/vendor-info-sheet.tsx b/lib/site-visit/vendor-info-sheet.tsx
index 2a20e212..ad2fa16b 100644
--- a/lib/site-visit/vendor-info-sheet.tsx
+++ b/lib/site-visit/vendor-info-sheet.tsx
@@ -61,6 +61,7 @@ interface VendorInfoSheetProps {
onSubmit: (data: VendorInfoFormValues & { attachments?: File[] }) => Promise<void>
siteVisitRequestId: number
initialData?: VendorInfoFormValues | null
+ vendorCountry?: string
}
export function VendorInfoSheet({
@@ -69,10 +70,12 @@ export function VendorInfoSheet({
onSubmit,
siteVisitRequestId,
initialData,
+ vendorCountry = "",
}: VendorInfoSheetProps) {
const [isPending, setIsPending] = React.useState(false)
const [selectedFiles, setSelectedFiles] = React.useState<File[]>([])
const fileInputRef = React.useRef<HTMLInputElement>(null)
+ const isDomestic = vendorCountry === "KR"
const form = useForm<VendorInfoFormValues>({
resolver: zodResolver(vendorInfoSchema),
@@ -114,6 +117,36 @@ export function VendorInfoSheet({
}
}, [isOpen, form, initialData])
+ // 도로명 주소 검색 결과 수신 (내자만 적용)
+ React.useEffect(() => {
+ if (!isOpen || !isDomestic) return
+
+ const handleMessage = (event: MessageEvent) => {
+ if (!event.data || event.data.type !== "JUSO_SELECTED") return
+ const { roadAddrPart1, roadAddrPart2, addrDetail } = event.data.payload || {}
+ const combinedRoad = [roadAddrPart1, roadAddrPart2].filter(Boolean).join(" ").trim()
+
+ if (combinedRoad) {
+ form.setValue("factoryLocation", combinedRoad, { shouldDirty: true })
+ }
+ if (addrDetail) {
+ form.setValue("factoryAddress", addrDetail, { shouldDirty: true })
+ }
+ }
+
+ window.addEventListener("message", handleMessage)
+ return () => window.removeEventListener("message", handleMessage)
+ }, [isOpen, isDomestic, form])
+
+ const handleJusoSearch = () => {
+ if (!isDomestic) return
+ window.open(
+ "/api/juso",
+ "jusoSearch",
+ "width=570,height=420,scrollbars=yes,resizable=yes"
+ )
+ }
+
// 파일 업로드 핸들러
const handleFileUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
const files = event.target.files
@@ -202,7 +235,25 @@ export function VendorInfoSheet({
<FormItem>
<FormLabel>실사 지역 *</FormLabel>
<FormControl>
- <Input placeholder="국가 또는 지역 (예: Finland, 부산)" {...field} disabled={isPending} />
+ <div className="flex gap-2">
+ <Input
+ placeholder="국가 또는 지역 (예: Finland, 부산)"
+ {...field}
+ disabled={isPending || isDomestic}
+ readOnly={isDomestic}
+ className={isDomestic ? "bg-muted text-muted-foreground" : undefined}
+ />
+ {isDomestic && (
+ <Button
+ type="button"
+ variant="secondary"
+ onClick={handleJusoSearch}
+ disabled={isPending}
+ >
+ 주소 검색
+ </Button>
+ )}
+ </div>
</FormControl>
<FormMessage />
</FormItem>
@@ -220,8 +271,9 @@ export function VendorInfoSheet({
<Textarea
placeholder="상세 주소를 입력하세요"
{...field}
- disabled={isPending}
- className="min-h-[80px]"
+ disabled={isPending || isDomestic}
+ readOnly={isDomestic}
+ className={isDomestic ? "bg-muted text-muted-foreground min-h-[80px]" : "min-h-[80px]"}
/>
</FormControl>
<FormMessage />