summaryrefslogtreecommitdiff
path: root/lib/rfqs/table/add-rfq-dialog.tsx
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-04-28 02:13:30 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-04-28 02:13:30 +0000
commitef4c533ebacc2cdc97e518f30e9a9350004fcdfb (patch)
tree345251a3ed0f4429716fa5edaa31024d8f4cb560 /lib/rfqs/table/add-rfq-dialog.tsx
parent9ceed79cf32c896f8a998399bf1b296506b2cd4a (diff)
~20250428 작업사항
Diffstat (limited to 'lib/rfqs/table/add-rfq-dialog.tsx')
-rw-r--r--lib/rfqs/table/add-rfq-dialog.tsx72
1 files changed, 42 insertions, 30 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