fix: V2 견적 작성자 하드코딩 제거 - currentUser 연동

- INITIAL_FORM_DATA.writer "드미트리" → "" 변경
- useAuth() 훅으로 currentUser.name 사용
- create 모드에서만 자동 설정 (edit/view는 기존 값 유지)
- useEffect로 지연 로딩 처리
This commit is contained in:
2026-01-26 11:22:39 +09:00
parent e8683381d9
commit 49d6e7e271

View File

@@ -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<QuoteFormDataV2>(
initialData || INITIAL_FORM_DATA
);
const [formData, setFormData] = useState<QuoteFormDataV2>(() => {
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<string | null>(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]);
// ---------------------------------------------------------------------------
// 초기 데이터 로드
// ---------------------------------------------------------------------------