From 4863ba5d336297dddcc8d6d4b414beceb5559742 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Mon, 8 Dec 2025 03:03:26 +0000 Subject: (최겸) 기술영업 rfq eml첨부기능 추가 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/items-tech/table/add-items-dialog.tsx | 65 +++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) (limited to 'lib/items-tech') diff --git a/lib/items-tech/table/add-items-dialog.tsx b/lib/items-tech/table/add-items-dialog.tsx index 01a072da..a4c644b6 100644 --- a/lib/items-tech/table/add-items-dialog.tsx +++ b/lib/items-tech/table/add-items-dialog.tsx @@ -34,7 +34,7 @@ import { } from "@/components/ui/select" import { toast } from "sonner" -import { createShipbuildingItem, createOffshoreTopItem, createOffshoreHullItem } from "../service" +import { createShipbuildingItem, createOffshoreTopItem, createOffshoreHullItem, getShipTypes } from "../service" import { ItemType } from "./delete-items-dialog" // 조선 공종 유형 정의 @@ -88,6 +88,8 @@ export function AddItemDialog({ itemType }: AddItemDialogProps) { const router = useRouter() const [open, setOpen] = React.useState(false) const [isAddPending, startAddTransition] = React.useTransition() + const [shipTypeOptions, setShipTypeOptions] = React.useState([]) + const [isShipTypeLoading, setIsShipTypeLoading] = React.useState(false) // 기본값 설정 const getDefaultValues = () => { @@ -97,7 +99,7 @@ export function AddItemDialog({ itemType }: AddItemDialogProps) { } if (itemType === 'shipbuilding') { - defaults.shipTypes = "OPTION" + defaults.shipTypes = "" } else { defaults.itemList = "" defaults.subItemList = "" @@ -124,6 +126,42 @@ export function AddItemDialog({ itemType }: AddItemDialogProps) { defaultValues: getDefaultValues(), }) + // shipTypes 목록 로드 (조선 아이템 생성 시) + React.useEffect(() => { + if (itemType !== 'shipbuilding' || !open) return + + let isMounted = true + const loadShipTypes = async () => { + try { + setIsShipTypeLoading(true) + const { data, error } = await getShipTypes() + if (!isMounted) return + if (error) { + toast.error("선종 목록을 불러오지 못했습니다") + return + } + const options = (data || []).filter((v): v is string => Boolean(v)) + setShipTypeOptions(options) + // 기본값 자동 설정 + if (options.length > 0 && !form.getValues("shipTypes")) { + form.setValue("shipTypes", options[0]) + } + } catch (err) { + console.error("shipTypes load error:", err) + if (isMounted) { + toast.error("선종 목록 로드 중 오류가 발생했습니다") + } + } finally { + if (isMounted) setIsShipTypeLoading(false) + } + } + + loadShipTypes() + return () => { + isMounted = false + } + }, [itemType, open, form]) + const onSubmit = async (data: ItemFormValues) => { startAddTransition(async () => { try { @@ -276,7 +314,28 @@ export function AddItemDialog({ itemType }: AddItemDialogProps) { 선종 * - + -- cgit v1.2.3