feat: DevFill 후 자동 견적 산출 로직 추가 (WIP)

- pendingAutoCalculate 상태로 자동 산출 트리거
- calculateRef로 handleCalculate 참조
- DevFill 완료 후 100ms 딜레이 후 산출 실행
- 아직 금액 표시 안되는 이슈 있음
This commit is contained in:
2026-01-26 13:54:14 +09:00
parent 22d16bbb91
commit 80f5ed426c

View File

@@ -9,7 +9,7 @@
"use client";
import { useState, useEffect, useMemo, useCallback } from "react";
import { useState, useEffect, useMemo, useCallback, useRef } from "react";
import { FileText, Calculator, Download, Save, Check } from "lucide-react";
import { toast } from "sonner";
@@ -167,6 +167,7 @@ export function QuoteRegistrationV2({
const [isSaving, setIsSaving] = useState(false);
const [isCalculating, setIsCalculating] = useState(false);
const [previewModalOpen, setPreviewModalOpen] = useState(false);
const [pendingAutoCalculate, setPendingAutoCalculate] = useState(false);
// API 데이터
const [clients, setClients] = useState<Vendor[]>([]);
@@ -175,6 +176,9 @@ export function QuoteRegistrationV2({
const [isLoadingClients, setIsLoadingClients] = useState(false);
const [isLoadingProducts, setIsLoadingProducts] = useState(false);
// handleCalculate 참조 (DevFill에서 사용)
const calculateRef = useRef<(() => Promise<void>) | null>(null);
// ---------------------------------------------------------------------------
// DevFill (개발/테스트용 자동 채우기)
// ---------------------------------------------------------------------------
@@ -246,6 +250,9 @@ export function QuoteRegistrationV2({
setFormData(testData);
setSelectedLocationId(testLocations[0].id);
toast.success(`[DevFill] 테스트 데이터가 채워졌습니다. (${locationCount}개 개소)`);
// 자동 견적 산출 트리거
setPendingAutoCalculate(true);
}, [clients, finishedGoods]));
// ---------------------------------------------------------------------------
@@ -480,6 +487,23 @@ export function QuoteRegistrationV2({
}
}, [formData.locations]);
// handleCalculate 참조 업데이트
useEffect(() => {
calculateRef.current = handleCalculate;
}, [handleCalculate]);
// DevFill 후 자동 견적 산출
useEffect(() => {
if (pendingAutoCalculate && formData.locations.length > 0 && calculateRef.current) {
setPendingAutoCalculate(false);
// 약간의 딜레이 후 산출 실행 (상태 업데이트 완료 대기)
const timer = setTimeout(() => {
calculateRef.current?.();
}, 100);
return () => clearTimeout(timer);
}
}, [pendingAutoCalculate, formData.locations.length]);
// 저장 (임시/최종)
const handleSave = useCallback(async (saveType: "temporary" | "final") => {
if (!onSave) return;