feat: [수주관리] 수주 등록 페이지 거래처 API 연동

- SAMPLE_CLIENTS 하드코딩 제거
- useClientList 훅으로 실제 API 데이터 조회
- 로딩 상태 처리 ("불러오는 중...")
- 견적 선택 시 발주처 필드 비활성화
This commit is contained in:
2026-01-09 22:14:38 +09:00
parent b9af603cb7
commit 9b1a1e3dc7

View File

@@ -13,6 +13,7 @@
import { useState, useEffect, useCallback } from "react";
import { useDaumPostcode } from "@/hooks/useDaumPostcode";
import { useClientList } from "@/hooks/useClientList";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
@@ -134,15 +135,6 @@ const SHIPPING_COSTS = [
{ value: "negotiable", label: "협의" },
];
// 샘플 발주처 데이터
const SAMPLE_CLIENTS = [
{ id: "C001", name: "태영건설(주)" },
{ id: "C002", name: "현대건설(주)" },
{ id: "C003", name: "GS건설(주)" },
{ id: "C004", name: "대우건설(주)" },
{ id: "C005", name: "포스코건설" },
];
interface OrderRegistrationProps {
onBack: () => void;
onSave: (formData: OrderFormData) => Promise<void>;
@@ -185,6 +177,14 @@ export function OrderRegistration({
const [isSaving, setIsSaving] = useState(false);
const [fieldErrors, setFieldErrors] = useState<FieldErrors>({});
// 거래처 목록 조회
const { clients, fetchClients, isLoading: isClientsLoading } = useClientList();
// 컴포넌트 마운트 시 거래처 목록 불러오기
useEffect(() => {
fetchClients({ onlyActive: true, size: 100 });
}, [fetchClients]);
// Daum 우편번호 서비스
const { openPostcode } = useDaumPostcode({
onComplete: (result) => {
@@ -231,6 +231,7 @@ export function OrderRegistration({
setForm((prev) => ({
...prev,
selectedQuotation: quotation,
clientId: quotation.clientId || "", // 견적의 발주처 ID 설정
clientName: quotation.client,
siteName: quotation.siteName,
manager: quotation.manager || "",
@@ -238,6 +239,8 @@ export function OrderRegistration({
items,
}));
// 발주처 에러 초기화
clearFieldError("clientName");
toast.success("견적 정보가 불러와졌습니다.");
};
@@ -449,7 +452,7 @@ export function OrderRegistration({
<Select
value={form.clientId}
onValueChange={(value) => {
const client = SAMPLE_CLIENTS.find((c) => c.id === value);
const client = clients.find((c) => c.id === value);
setForm((prev) => ({
...prev,
clientId: value,
@@ -457,14 +460,15 @@ export function OrderRegistration({
}));
clearFieldError("clientName");
}}
disabled={!!form.selectedQuotation || isClientsLoading}
>
<SelectTrigger className={cn(fieldErrors.clientName && "border-red-500")}>
<SelectValue placeholder="발주처 선택">
{form.clientName || "발주처 선택"}
<SelectValue placeholder={isClientsLoading ? "불러오는 중..." : "발주처 선택"}>
{form.clientName || (isClientsLoading ? "불러오는 중..." : "발주처 선택")}
</SelectValue>
</SelectTrigger>
<SelectContent>
{SAMPLE_CLIENTS.map((client) => (
{clients.map((client) => (
<SelectItem key={client.id} value={client.id}>
{client.name}
</SelectItem>