import React, { useState, useEffect } from 'react'; import { Incident, Building } from '../../types'; import { apiClient } from '../../services/apiClient'; import { backendApi } from '../../services/apiClient'; import { ShieldAlert, AlertCircle, MessageCircle, CheckCircle2, Phone, Search, Filter, Trash2, ChevronRight, Plus, Loader2, X } from 'lucide-react'; export const NegativeResolution: React.FC = () => { const [incidents, setIncidents] = useState([]); const [isLoading, setIsLoading] = useState(true); const [filterStatus, setFilterStatus] = useState(''); const [filterType, setFilterType] = useState(''); const [search, setSearch] = useState(''); const [showCreateForm, setShowCreateForm] = useState(false); useEffect(() => { loadIncidents(); }, [filterStatus, filterType]); const loadIncidents = async () => { try { setIsLoading(true); const params = new URLSearchParams(); if (filterStatus) params.append('status', filterStatus); if (filterType) params.append('type', filterType); const queryString = params.toString(); const path = `/pr/incidents${queryString ? `?${queryString}` : ''}`; const data = await apiClient.get(path); setIncidents(data); } catch (err) { console.error('Error loading incidents:', err); setIncidents([]); } finally { setIsLoading(false); } }; const handleResolve = async (id: number, resolutionNotes?: string) => { try { await apiClient.put(`/pr/incidents/${id}/resolve`, { resolution_notes: resolutionNotes }); await loadIncidents(); } catch (err) { console.error('Error resolving incident:', err); alert('Ошибка разрешения инцидента'); } }; const handleStatusChange = async (id: number, status: Incident['status']) => { try { await apiClient.put(`/pr/incidents/${id}`, { status }); await loadIncidents(); } catch (err) { console.error('Error updating incident status:', err); alert('Ошибка обновления статуса'); } }; const filteredIncidents = incidents.filter(incident => { const matchesSearch = !search || incident.title.toLowerCase().includes(search.toLowerCase()) || incident.description.toLowerCase().includes(search.toLowerCase()) || (incident.address && incident.address.toLowerCase().includes(search.toLowerCase())); return matchesSearch; }); const newIncidents = filteredIncidents.filter(i => i.status === 'new'); const inProgressIncidents = filteredIncidents.filter(i => i.status === 'in_progress'); return (
{/* Header Alert */}

Работа с инцидентами

{newIncidents.length} новых инцидентов • {inProgressIncidents.length} в работе

{/* Filters */}
setSearch(e.target.value)} className="w-full pl-11 pr-4 py-3 bg-white border border-slate-200 rounded-2xl text-sm outline-none focus:ring-2 focus:ring-primary-500 shadow-sm" />
{/* Create Form Modal */} {showCreateForm && ( setShowCreateForm(false)} onSuccess={() => { setShowCreateForm(false); loadIncidents(); }} /> )} {/* Incidents List */} {isLoading ? (
) : filteredIncidents.length === 0 ? (

Инциденты не найдены

) : (
{filteredIncidents.map(incident => ( ))}
)}
); }; interface IncidentCardProps { incident: Incident; onResolve: (id: number, notes?: string) => void; onStatusChange: (id: number, status: Incident['status']) => void; } const IncidentCard: React.FC = ({ incident, onResolve, onStatusChange }) => { const [showResolveForm, setShowResolveForm] = useState(false); const [resolutionNotes, setResolutionNotes] = useState(''); const typeLabels = { property_damage: 'Повреждение имущества', debtor_complaint: 'Жалоба должника', service_quality: 'Качество услуг', other: 'Другое' }; const statusColors = { new: 'bg-red-50 text-red-600 border-red-100', in_progress: 'bg-amber-50 text-amber-600 border-amber-100', resolved: 'bg-emerald-50 text-emerald-600 border-emerald-100', closed: 'bg-slate-50 text-slate-600 border-slate-100' }; const priorityColors = { low: 'bg-slate-100 text-slate-600', medium: 'bg-blue-100 text-blue-600', high: 'bg-orange-100 text-orange-600', urgent: 'bg-red-100 text-red-600' }; return (

{incident.title}

{incident.status === 'new' ? 'Новый' : incident.status === 'in_progress' ? 'В работе' : incident.status === 'resolved' ? 'Разрешен' : 'Закрыт'} {incident.priority === 'urgent' ? 'Срочно' : incident.priority === 'high' ? 'Высокий' : incident.priority === 'medium' ? 'Средний' : 'Низкий'} {typeLabels[incident.type]} {incident.address && ( {incident.address} )}
{incident.description}
{incident.review && (
Связанный отзыв: «{incident.review.text}» (Рейтинг: {incident.review.rating}/10)
)} {/* Actions */} {!showResolveForm ? (
{incident.status === 'new' && ( )} {incident.status === 'in_progress' && ( )} {incident.status === 'resolved' && ( )}
) : (