feat: [재고생산] 복사 버튼 추가 + STOCK LOT 번호 개선
This commit is contained in:
@@ -5,17 +5,64 @@
|
||||
*
|
||||
* - 기본: 목록 (StockProductionList)
|
||||
* - ?mode=new: 등록 (BendingLotForm — 절곡품 LOT 방식)
|
||||
* - ?mode=new©From={id}: 복사 등록 (기존 데이터 기반)
|
||||
*/
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { StockProductionList } from '@/components/stocks/StockProductionList';
|
||||
import { BendingLotForm } from '@/components/stocks/BendingLotForm';
|
||||
import { getStockOrderById, type StockOrder } from '@/components/stocks/actions';
|
||||
|
||||
function CopyStockContent({ copyFromId }: { copyFromId: string }) {
|
||||
const [order, setOrder] = useState<StockOrder | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
async function load() {
|
||||
try {
|
||||
const result = await getStockOrderById(copyFromId);
|
||||
if (result.__authError) {
|
||||
toast.error('인증이 만료되었습니다.');
|
||||
return;
|
||||
}
|
||||
if (result.success && result.data) {
|
||||
setOrder(result.data);
|
||||
} else {
|
||||
toast.error(result.error || '복사할 데이터를 불러오는데 실패했습니다.');
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
load();
|
||||
}, [copyFromId]);
|
||||
|
||||
if (loading) {
|
||||
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-muted-foreground">데이터를 불러오는 중...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <BendingLotForm initialData={order ?? undefined} />;
|
||||
}
|
||||
|
||||
export default function StocksPage() {
|
||||
const searchParams = useSearchParams();
|
||||
const mode = searchParams.get('mode');
|
||||
const copyFrom = searchParams.get('copyFrom');
|
||||
|
||||
if (mode === 'new') {
|
||||
if (copyFrom) {
|
||||
return <CopyStockContent copyFromId={copyFrom} />;
|
||||
}
|
||||
return <BendingLotForm />;
|
||||
}
|
||||
|
||||
|
||||
@@ -240,11 +240,13 @@ export function BendingLotForm({ initialData, isEditMode = false }: BendingLotFo
|
||||
const locale = (params.locale as string) || 'ko';
|
||||
const basePath = `/${locale}/sales/stocks`;
|
||||
|
||||
const isCopyMode = !isEditMode && !!initialData;
|
||||
|
||||
const [form, setForm] = useState<BendingFormState>(() => {
|
||||
if (initialData?.bendingLot) {
|
||||
const bl = initialData.bendingLot;
|
||||
return {
|
||||
regDate: initialData.regDate || getInitialForm().regDate,
|
||||
regDate: isCopyMode ? getInitialForm().regDate : (initialData.regDate || getInitialForm().regDate),
|
||||
prodCode: bl.prodCode || '',
|
||||
specCode: bl.specCode || '',
|
||||
lengthCode: bl.lengthCode || '',
|
||||
@@ -264,7 +266,11 @@ export function BendingLotForm({ initialData, isEditMode = false }: BendingLotFo
|
||||
const [rawLotModalOpen, setRawLotModalOpen] = useState(false);
|
||||
const [fabricLotModalOpen, setFabricLotModalOpen] = useState(false);
|
||||
|
||||
const config = isEditMode ? bendingEditConfig : bendingCreateConfig;
|
||||
const config = isEditMode
|
||||
? bendingEditConfig
|
||||
: isCopyMode
|
||||
? { ...bendingCreateConfig, description: '기존 재고생산을 복사하여 등록합니다' }
|
||||
: bendingCreateConfig;
|
||||
|
||||
// 코드맵 로드 + edit mode 시 초기 품목 매핑 조회
|
||||
useEffect(() => {
|
||||
|
||||
@@ -18,8 +18,10 @@ import {
|
||||
MessageSquare,
|
||||
Tag,
|
||||
Layers,
|
||||
Copy,
|
||||
} from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { IntegratedDetailTemplate } from '@/components/templates/IntegratedDetailTemplate';
|
||||
import { FormSection } from '@/components/organisms/FormSection';
|
||||
import {
|
||||
@@ -257,7 +259,16 @@ export function StockProductionDetail({ orderId }: StockProductionDetailProps) {
|
||||
}
|
||||
return { success: result.success, error: result.error };
|
||||
}}
|
||||
headerActions={null}
|
||||
headerActions={
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => router.push(`${basePath}?mode=new©From=${orderId}`)}
|
||||
>
|
||||
<Copy className="h-4 w-4 mr-1" />
|
||||
복사
|
||||
</Button>
|
||||
}
|
||||
renderView={(data) => renderViewContent(data as unknown as StockOrder)}
|
||||
/>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user