import React, { useState, useEffect } from 'react'; import { District, Employee } from '../../types'; import { backendApi } from '../../services/apiClient'; import { X } from 'lucide-react'; const UNASSIGNED_MANAGER = 'Не назначен'; interface Props { district: District | null; onClose: () => void; onSaved: () => void; employees: Employee[]; } export const EditDistrictModal: React.FC = ({ district, onClose, onSaved, employees }) => { const [name, setName] = useState(''); const [managerName, setManagerName] = useState(UNASSIGNED_MANAGER); const [saving, setSaving] = useState(false); useEffect(() => { if (district) { setName(district.name); setManagerName(district.managerName?.trim() || UNASSIGNED_MANAGER); } }, [district]); const eligibleManagers = employees.filter(emp => { if (emp.status !== 'active') return false; const positionLower = (emp.position || '').toLowerCase(); return positionLower.includes('мастер') || positionLower.includes('начальник участка'); }); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!district || !name.trim()) return; try { setSaving(true); await backendApi.updateDistrict(district.id, { name: name.trim(), managerName: managerName === '' ? UNASSIGNED_MANAGER : managerName.trim(), }); onSaved(); onClose(); } catch (err) { console.error(err); alert('Ошибка сохранения участка'); } finally { setSaving(false); } }; if (!district) return null; return (
e.stopPropagation()} >

Редактировать участок

setName(e.target.value)} className="w-full border border-slate-200 rounded-xl px-3 py-2 text-sm focus:ring-2 focus:ring-primary-500 outline-none" required />
); };