diff --git a/src/components/quotes/QuoteRegistrationV2.tsx b/src/components/quotes/QuoteRegistrationV2.tsx index 871ab062..719e8e1a 100644 --- a/src/components/quotes/QuoteRegistrationV2.tsx +++ b/src/components/quotes/QuoteRegistrationV2.tsx @@ -43,6 +43,7 @@ import { } from "./actions"; import { getClients } from "../accounting/VendorManagement/actions"; import { isNextRedirectError } from "@/lib/utils/redirect-error"; +import { useAuth } from "@/contexts/AuthContext"; import type { Vendor } from "../accounting/VendorManagement"; import type { BomMaterial, CalculationResults } from "./types"; @@ -115,7 +116,7 @@ const createNewLocation = (): LocationItem => ({ // 초기 폼 데이터 const INITIAL_FORM_DATA: QuoteFormDataV2 = { registrationDate: new Date().toISOString().split("T")[0], - writer: "드미트리", // TODO: 로그인 사용자 정보 + writer: "", // useAuth()에서 currentUser.name으로 설정됨 clientId: "", clientName: "", siteName: "", @@ -155,12 +156,22 @@ export function QuoteRegistrationV2({ isLoading = false, hideHeader = false, }: QuoteRegistrationV2Props) { + // --------------------------------------------------------------------------- + // 인증 정보 + // --------------------------------------------------------------------------- + const { currentUser } = useAuth(); + // --------------------------------------------------------------------------- // 상태 // --------------------------------------------------------------------------- - const [formData, setFormData] = useState( - initialData || INITIAL_FORM_DATA - ); + const [formData, setFormData] = useState(() => { + const data = initialData || INITIAL_FORM_DATA; + // create 모드에서 writer가 비어있으면 현재 사용자명으로 설정 + if (mode === "create" && !data.writer && currentUser?.name) { + return { ...data, writer: currentUser.name }; + } + return data; + }); const [selectedLocationId, setSelectedLocationId] = useState(null); const [isSaving, setIsSaving] = useState(false); const [isCalculating, setIsCalculating] = useState(false); @@ -199,6 +210,15 @@ export function QuoteRegistrationV2({ })); }, [formData.locations]); + // --------------------------------------------------------------------------- + // 작성자 자동 설정 (create 모드에서 currentUser 로드 시) + // --------------------------------------------------------------------------- + useEffect(() => { + if (mode === "create" && !formData.writer && currentUser?.name) { + setFormData((prev) => ({ ...prev, writer: currentUser.name })); + } + }, [mode, currentUser?.name, formData.writer]); + // --------------------------------------------------------------------------- // 초기 데이터 로드 // ---------------------------------------------------------------------------