diff options
Diffstat (limited to 'lib/rfqs/table')
| -rw-r--r-- | lib/rfqs/table/add-rfq-dialog.tsx | 72 | ||||
| -rw-r--r-- | lib/rfqs/table/rfqs-table.tsx | 2 |
2 files changed, 43 insertions, 31 deletions
diff --git a/lib/rfqs/table/add-rfq-dialog.tsx b/lib/rfqs/table/add-rfq-dialog.tsx index 41055608..9d4d7cf0 100644 --- a/lib/rfqs/table/add-rfq-dialog.tsx +++ b/lib/rfqs/table/add-rfq-dialog.tsx @@ -16,6 +16,7 @@ import { createRfq, generateNextRfqCode, getBudgetaryRfqs } from "../service" import { ProjectSelector } from "@/components/ProjectSelector" import { type Project } from "../service" import { ParentRfqSelector } from "./ParentRfqSelector" +import { EstimateProjectSelector } from "@/components/BidProjectSelector" // 부모 RFQ 정보 타입 정의 interface ParentRfq { @@ -43,18 +44,13 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) // Get the user ID safely, ensuring it's a valid number const userId = React.useMemo(() => { const id = session?.user?.id ? Number(session.user.id) : null; - - // Debug logging - remove in production - console.log("Session status:", status); - console.log("Session data:", session); - console.log("User ID:", id); - + return id; }, [session, status]); // RfqType에 따른 타이틀 생성 const getTitle = () => { - switch(rfqType) { + switch (rfqType) { case RfqType.PURCHASE: return "Purchase RFQ"; case RfqType.BUDGETARY: @@ -68,7 +64,7 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) // RfqType 설명 가져오기 const getTypeDescription = () => { - switch(rfqType) { + switch (rfqType) { case RfqType.PURCHASE: return "실제 구매 발주 전에 가격을 요청"; case RfqType.BUDGETARY: @@ -111,12 +107,12 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) try { // 서버 액션 호출 const result = await generateNextRfqCode(rfqType); - + if (result.error) { toast.error(`RFQ 코드 생성 실패: ${result.error}`); return; } - + // 생성된 코드를 폼에 설정 form.setValue("rfqCode", result.code); } catch (error) { @@ -126,14 +122,14 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) setIsLoadingRfqCode(false); } }; - + generateRfqCode(); } }, [open, rfqType, form]); // 현재 RFQ 타입에 따라 선택 가능한 부모 RFQ 타입들 결정 const getParentRfqTypes = (): RfqType[] => { - switch(rfqType) { + switch (rfqType) { case RfqType.PURCHASE: // PURCHASE는 BUDGETARY와 PURCHASE_BUDGETARY를 부모로 가질 수 있음 return [RfqType.BUDGETARY, RfqType.PURCHASE_BUDGETARY]; @@ -153,13 +149,13 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) try { // 현재 RFQ 타입에 따라 선택 가능한, 부모가 될 수 있는 RFQ 타입들 가져오기 const parentTypes = getParentRfqTypes(); - + // 부모 RFQ 타입이 있을 때만 API 호출 if (parentTypes.length > 0) { const result = await getBudgetaryRfqs({ rfqTypes: parentTypes // 서비스에 rfqTypes 파라미터 추가 필요 }); - + if ('rfqs' in result) { setParentRfqs(result.rfqs as unknown as ParentRfq[]); } else if ('error' in result) { @@ -186,6 +182,14 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) form.setValue("projectId", project.id); }; + const handleBidProjectSelect = (project: Project | null) => { + if (project === null) { + return; + } + + form.setValue("bidProjectId", project.id); + }; + // 부모 RFQ 선택 처리 const handleParentRfqSelect = (rfq: ParentRfq | null) => { setSelectedParentRfq(rfq); @@ -212,7 +216,7 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) toast.error(`에러: ${result.error}`); return; } - + toast.success("RFQ가 성공적으로 생성되었습니다."); form.reset(); setSelectedParentRfq(null); @@ -234,7 +238,8 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) // 타입에 따라 부모 RFQ 선택 필드를 보여줄지 결정 const shouldShowParentRfqSelector = rfqType === RfqType.PURCHASE || rfqType === RfqType.PURCHASE_BUDGETARY; - + const shouldShowEstimateSelector = rfqType === RfqType.BUDGETARY; + // 부모 RFQ 선택기 레이블 및 설명 가져오기 const getParentRfqSelectorLabel = () => { if (rfqType === RfqType.PURCHASE) { @@ -294,11 +299,18 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) <FormItem> <FormLabel>Project</FormLabel> <FormControl> - <ProjectSelector - selectedProjectId={field.value} - onProjectSelect={handleProjectSelect} - placeholder="프로젝트 선택..." - /> + + {shouldShowEstimateSelector ? + <EstimateProjectSelector + selectedProjectId={field.value} + onProjectSelect={handleBidProjectSelect} + placeholder="견적 프로젝트 선택..." + /> : + <ProjectSelector + selectedProjectId={field.value} + onProjectSelect={handleProjectSelect} + placeholder="프로젝트 선택..." + />} </FormControl> <FormMessage /> </FormItem> @@ -317,11 +329,11 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) <ParentRfqSelector selectedRfqId={field.value as number | undefined} onRfqSelect={handleParentRfqSelect} - rfqType={rfqType} + rfqType={rfqType} parentRfqTypes={getParentRfqTypes()} placeholder={ - rfqType === RfqType.PURCHASE - ? "BUDGETARY 또는 PURCHASE_BUDGETARY RFQ 선택..." + rfqType === RfqType.PURCHASE + ? "BUDGETARY 또는 PURCHASE_BUDGETARY RFQ 선택..." : "BUDGETARY RFQ 선택..." } /> @@ -344,9 +356,9 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) <FormLabel>RFQ Code</FormLabel> <FormControl> <div className="flex"> - <Input - placeholder="자동으로 생성 중..." - {...field} + <Input + placeholder="자동으로 생성 중..." + {...field} disabled={true} className="bg-muted" /> @@ -416,7 +428,7 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) disabled className="capitalize" {...field} - onChange={() => {}} // Prevent changes + onChange={() => { }} // Prevent changes /> </FormControl> <FormMessage /> @@ -433,8 +445,8 @@ export function AddRfqDialog({ rfqType = RfqType.PURCHASE }: AddRfqDialogProps) > Cancel </Button> - <Button - type="submit" + <Button + type="submit" disabled={form.formState.isSubmitting || status !== "authenticated"} > Create diff --git a/lib/rfqs/table/rfqs-table.tsx b/lib/rfqs/table/rfqs-table.tsx index e4ff47d8..287f1d53 100644 --- a/lib/rfqs/table/rfqs-table.tsx +++ b/lib/rfqs/table/rfqs-table.tsx @@ -216,7 +216,7 @@ export function RfqsTable({ promises, rfqType = RfqType.PURCHASE }: RfqsTablePro <div style={{ maxWidth: '100vw' }}> <DataTable table={table} - floatingBar={<RfqsTableFloatingBar table={table} />} + // floatingBar={<RfqsTableFloatingBar table={table} />} > <DataTableAdvancedToolbar table={table} |
