'use client'; /** * 검사 등록 페이지 */ import { useState, useCallback } from 'react'; import { useRouter } from 'next/navigation'; import { ClipboardCheck, ImageIcon } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { PageLayout } from '@/components/organisms/PageLayout'; import { inspectionItemsTemplate, judgeMeasurement } from './mockData'; import type { InspectionItem, QualityCheckItem, MeasurementItem } from './types'; export function InspectionCreate() { const router = useRouter(); // 폼 상태 const [formData, setFormData] = useState({ lotNo: 'WO-251219-05', // 자동 (예시) itemName: '조인트바', // 자동 (예시) processName: '조립 공정', // 자동 (예시) quantity: 50, inspector: '', remarks: '', }); // 검사 항목 상태 const [inspectionItems, setInspectionItems] = useState( inspectionItemsTemplate.map(item => ({ ...item })) ); // validation 에러 상태 const [validationErrors, setValidationErrors] = useState([]); // 폼 입력 핸들러 const handleInputChange = (field: string, value: string | number) => { setFormData(prev => ({ ...prev, [field]: value })); // 입력 시 에러 클리어 if (validationErrors.length > 0) { setValidationErrors([]); } }; // 품질 검사 항목 결과 변경 (양호/불량) const handleQualityResultChange = useCallback((itemId: string, result: '양호' | '불량') => { setInspectionItems(prev => prev.map(item => { if (item.id === itemId && item.type === 'quality') { return { ...item, result, judgment: result === '양호' ? '적합' : '부적합', } as QualityCheckItem; } return item; })); // 입력 시 에러 클리어 setValidationErrors([]); }, []); // 측정 항목 값 변경 const handleMeasurementChange = useCallback((itemId: string, value: string) => { setInspectionItems(prev => prev.map(item => { if (item.id === itemId && item.type === 'measurement') { const measuredValue = parseFloat(value) || 0; const judgment = judgeMeasurement(item.spec, measuredValue); return { ...item, measuredValue, judgment, } as MeasurementItem; } return item; })); // 입력 시 에러 클리어 setValidationErrors([]); }, []); // 취소 const handleCancel = () => { router.push('/quality/inspections'); }; // validation 체크 const validateForm = (): boolean => { const errors: string[] = []; // 필수 필드: 작업자 if (!formData.inspector.trim()) { errors.push('작업자는 필수 입력 항목입니다.'); } // 검사 항목 validation inspectionItems.forEach((item, index) => { if (item.type === 'quality') { const qualityItem = item as QualityCheckItem; if (!qualityItem.result) { errors.push(`${index + 1}. ${item.name}: 결과를 선택해주세요.`); } } else if (item.type === 'measurement') { const measurementItem = item as MeasurementItem; if (measurementItem.measuredValue === undefined || measurementItem.measuredValue === null) { errors.push(`${index + 1}. ${item.name}: 측정값을 입력해주세요.`); } } }); setValidationErrors(errors); return errors.length === 0; }; // 검사완료 const handleSubmit = () => { // validation 체크 if (!validateForm()) { return; } // TODO: API 호출 console.log('Submit:', { ...formData, items: inspectionItems }); router.push('/quality/inspections'); }; return (
{/* 헤더 */}

검사 등록

{/* Validation 에러 표시 */} {validationErrors.length > 0 && (
⚠️
입력 내용을 확인해주세요 ({validationErrors.length}개 오류)
    {validationErrors.map((error, index) => (
  • {error}
  • ))}
)} {/* 검사 개요 */} 검사 개요
handleInputChange('quantity', parseInt(e.target.value) || 0)} placeholder="수량 입력" />
handleInputChange('inspector', e.target.value)} placeholder="작업자 입력" />
handleInputChange('remarks', e.target.value)} placeholder="특이사항 입력" />
{/* 검사 기준 및 도해 */} 검사 기준 및 도해

템플릿에서 설정한 조인트바 표준 도면이 표시됨

{/* 검사 데이터 입력 */} 검사 데이터 입력

* 측정값을 입력하면 판정이 자동 처리됩니다.

{inspectionItems.map((item, index) => (

{index + 1}. {item.name} {item.type === 'measurement' && ` (${(item as MeasurementItem).unit})`}

판정: {item.judgment || '-'}
{item.type === 'quality' ? (
handleQualityResultChange(item.id, value as '양호' | '불량')} className="flex items-center gap-4 h-10" >
) : (
handleMeasurementChange(item.id, e.target.value)} placeholder={`측정값 입력 (${(item as MeasurementItem).unit})`} />
)}
))}
); }