'use client'; import { useState, useEffect } from 'react'; import { Modal } from '@/components/ui'; import FormField from '@/components/ui/FormField'; interface Props { isOpen: boolean; onClose: () => void; audit: any; onSave: (id: string, data: any) => void; } const STATUS_OPTIONS = [ { value: 'draft', label: 'Запланирован' }, { value: 'in_progress', label: 'В процессе' }, { value: 'completed', label: 'Завершён' }, ]; const TYPE_OPTIONS = ['Внутренний', 'Внешний', 'Надзорный', 'По типу ВС']; export default function AuditEditModal({ isOpen, onClose, audit, onSave }: Props) { const [form, setForm] = useState({ name: '', audit_type: 'Внутренний', planned_at: '', auditor: '', status: 'draft', remarks: '', corrective_actions: '', }); const [findings, setFindings] = useState<{ id: string; text: string; closed: boolean }[]>([]); const [newFinding, setNewFinding] = useState(''); useEffect(() => { if (audit) { setForm({ name: audit.name || `Аудит #${audit.id?.slice(0, 8) || ''}`, audit_type: audit.audit_type || 'Внутренний', planned_at: audit.planned_at ? new Date(audit.planned_at).toISOString().slice(0, 10) : '', auditor: audit.auditor || '', status: audit.status || 'draft', remarks: audit.remarks || '', corrective_actions: audit.corrective_actions || '', }); setFindings(Array.isArray(audit.findings) ? audit.findings : [ { id: '1', text: 'Документация по ТО не обновлена', closed: false }, { id: '2', text: 'Отсутствует подпись в журнале учёта', closed: true }, ]); } }, [audit]); const set = (k: string, v: string) => setForm(f => ({ ...f, [k]: v })); const handleSave = () => { if (!audit?.id) return; onSave(audit.id, { ...form, findings }); onClose(); }; const addFinding = () => { if (!newFinding.trim()) return; setFindings(prev => [...prev, { id: String(Date.now()), text: newFinding.trim(), closed: false }]); setNewFinding(''); }; const toggleFinding = (id: string) => { setFindings(prev => prev.map(f => f.id === id ? { ...f, closed: !f.closed } : f)); }; if (!audit) return null; return ( } >
set('name', e.target.value)} className="input-field" /> set('planned_at', e.target.value)} className="input-field" /> set('auditor', e.target.value)} className="input-field" placeholder="ФИО" />