refactor(WEB): 견적관리 목록 페이지 V2 URL 패턴 적용
- 목록 페이지에서 V1 등록 로직 제거 - ?mode=new → /new 리다이렉트 처리 (V1 호환) - QuoteManagementClient 링크 V2 패턴으로 변경 - 견적 등록: ?mode=new → /new - 상세 보기: ?mode=view 제거 (기본 view) - DevToolbar test URL → V2 URL로 업데이트
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
'use client';
|
||||
|
||||
/**
|
||||
* 견적관리 페이지 (Client Component)
|
||||
* 견적관리 목록 페이지
|
||||
*
|
||||
* V2 URL 패턴:
|
||||
* - 목록: /sales/quote-management
|
||||
* - 등록: /sales/quote-management/new
|
||||
* - 상세: /sales/quote-management/[id]
|
||||
* - 수정: /sales/quote-management/[id]?mode=edit
|
||||
*/
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useSearchParams, useRouter } from 'next/navigation';
|
||||
import { QuoteManagementClient } from '@/components/quotes/QuoteManagementClient';
|
||||
import { QuoteRegistration, QuoteFormData } from '@/components/quotes/QuoteRegistration';
|
||||
import { getQuotes, createQuote, transformFormDataToApi } from '@/components/quotes';
|
||||
import { toast } from 'sonner';
|
||||
import { getQuotes } from '@/components/quotes';
|
||||
|
||||
const DEFAULT_PAGINATION = {
|
||||
currentPage: 1,
|
||||
@@ -26,48 +30,29 @@ export default function QuoteManagementPage() {
|
||||
const [data, setData] = useState<Awaited<ReturnType<typeof getQuotes>>['data']>([]);
|
||||
const [pagination, setPagination] = useState(DEFAULT_PAGINATION);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
// V1 호환: ?mode=new → /new 리다이렉트
|
||||
useEffect(() => {
|
||||
if (mode !== 'new') {
|
||||
getQuotes({ perPage: 100 })
|
||||
.then(result => {
|
||||
setData(result.data);
|
||||
setPagination(result.pagination);
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
if (mode === 'new') {
|
||||
router.replace('/sales/quote-management/new');
|
||||
return;
|
||||
}
|
||||
}, [mode]);
|
||||
|
||||
getQuotes({ perPage: 100 })
|
||||
.then(result => {
|
||||
setData(result.data);
|
||||
setPagination(result.pagination);
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
}, [mode, router]);
|
||||
|
||||
// 리다이렉트 중이면 로딩 표시
|
||||
if (mode === 'new') {
|
||||
const handleBack = () => {
|
||||
router.push('/sales/quote-management');
|
||||
};
|
||||
|
||||
const handleSave = async (formData: QuoteFormData): Promise<{ success: boolean; error?: string }> => {
|
||||
if (isSaving) return { success: false, error: '저장 중입니다.' };
|
||||
setIsSaving(true);
|
||||
|
||||
try {
|
||||
const apiData = transformFormDataToApi(formData);
|
||||
const result = await createQuote(apiData as any);
|
||||
|
||||
if (result.success && result.data) {
|
||||
router.push(`/sales/quote-management/${result.data.id}`);
|
||||
return { success: true };
|
||||
} else {
|
||||
return { success: false, error: result.error || '견적 등록에 실패했습니다.' };
|
||||
}
|
||||
} catch (error) {
|
||||
return { success: false, error: '견적 등록에 실패했습니다.' };
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return <QuoteRegistration onBack={handleBack} onSave={handleSave} />;
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<div className="text-muted-foreground">리다이렉트 중...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
|
||||
Reference in New Issue
Block a user