This commit is contained in:
유병철
2026-01-27 19:50:35 +09:00
9 changed files with 184 additions and 16 deletions

View File

@@ -48,19 +48,23 @@ export default function EmployeeDetailPage() {
router.push(`/ko/hr/employee-management/${params.id}?mode=edit`);
};
const handleSave = async (data: EmployeeFormData) => {
const handleSave = async (data: EmployeeFormData): Promise<{ success: boolean; error?: string }> => {
const id = params.id as string;
if (!id) return;
if (!id) return { success: false, error: 'ID가 없습니다.' };
try {
const result = await updateEmployee(id, data);
if (result.success) {
router.push(`/ko/hr/employee-management/${id}?mode=view`);
// 데이터 갱신
await fetchEmployee();
return { success: true };
} else {
console.error('[EmployeeDetailPage] Update failed:', result.error);
return { success: false, error: result.error };
}
} catch (error) {
console.error('[EmployeeDetailPage] Update error:', error);
return { success: false, error: '저장 중 오류가 발생했습니다.' };
}
};

View File

@@ -3,14 +3,52 @@
/**
* 수주 등록 페이지
* API 연동 완료 (2025-01-08)
*
* quoteId 파라미터 지원 (2026-01-27)
* - /sales/order-management-sales/new?quoteId=123 형태로 접근 시
* - 해당 견적 정보를 자동으로 불러와 폼에 채움
*/
import { useRouter } from "next/navigation";
import { OrderRegistration, OrderFormData, createOrder } from "@/components/orders";
import { useRouter, useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
import { OrderRegistration, OrderFormData, createOrder, getQuoteByIdForSelect } from "@/components/orders";
import type { QuotationForSelect, QuotationItem } from "@/components/orders/actions";
import { toast } from "sonner";
import { Loader2 } from "lucide-react";
export default function OrderNewPage() {
const router = useRouter();
const searchParams = useSearchParams();
const quoteId = searchParams.get("quoteId");
const [initialQuotation, setInitialQuotation] = useState<QuotationForSelect | undefined>();
const [isLoading, setIsLoading] = useState(!!quoteId);
// quoteId가 있으면 견적 데이터 로드
useEffect(() => {
const loadQuoteData = async () => {
if (!quoteId) return;
setIsLoading(true);
try {
const result = await getQuoteByIdForSelect(quoteId);
if (result.success && result.data) {
setInitialQuotation(result.data);
toast.success("견적 정보가 불러와졌습니다.");
} else {
toast.error(result.error || "견적 정보를 불러오는데 실패했습니다.");
}
} catch (error) {
console.error("Error loading quote:", error);
toast.error("견적 정보를 불러오는데 실패했습니다.");
} finally {
setIsLoading(false);
}
};
loadQuoteData();
}, [quoteId]);
const handleBack = () => {
router.push("/sales/order-management-sales");
@@ -32,5 +70,50 @@ export default function OrderNewPage() {
}
};
return <OrderRegistration onBack={handleBack} onSave={handleSave} />;
// 로딩 중일 때 로딩 표시
if (isLoading) {
return (
<div className="flex items-center justify-center min-h-[400px]">
<div className="flex flex-col items-center gap-4">
<Loader2 className="h-8 w-8 animate-spin text-blue-600" />
<p className="text-gray-600"> ...</p>
</div>
</div>
);
}
// initialData 생성 - 견적 데이터가 있으면 변환하여 전달
const initialData: Partial<OrderFormData> | undefined = initialQuotation
? {
selectedQuotation: initialQuotation,
clientId: initialQuotation.clientId || "",
clientName: initialQuotation.client,
siteName: initialQuotation.siteName,
manager: initialQuotation.manager || "",
contact: initialQuotation.contact || "",
items: (initialQuotation.items || []).map((qi: QuotationItem) => ({
id: qi.id,
itemCode: qi.itemCode,
itemName: qi.itemName,
type: qi.type,
symbol: qi.symbol,
spec: qi.spec,
width: 0,
height: 0,
quantity: qi.quantity,
unit: qi.unit,
unitPrice: qi.unitPrice,
amount: qi.amount,
isFromQuotation: true,
})),
}
: undefined;
return (
<OrderRegistration
onBack={handleBack}
onSave={handleSave}
initialData={initialData}
/>
);
}