import React, { useEffect, useState } from 'react'; import { X, Building2, Loader2 } from 'lucide-react'; import { apiClient } from '../../services/apiClient'; interface CompanySettings { id?: number; name: string; fullName?: string | null; address?: string | null; phone?: string | null; email?: string | null; website?: string | null; licenseNumber?: string | null; licenseValidUntil?: string | null; logoUrl?: string | null; } interface CompanySettingsModalProps { onClose: () => void; } export const CompanySettingsModal: React.FC = ({ onClose }) => { const [form, setForm] = useState({ name: '', fullName: '', address: '', phone: '', email: '', website: '', licenseNumber: '', licenseValidUntil: '', logoUrl: '', }); const [isLoading, setIsLoading] = useState(false); const [isSaving, setIsSaving] = useState(false); useEffect(() => { const load = async () => { try { setIsLoading(true); const data = await apiClient.get('/settings/company'); setForm({ name: data.name || '', fullName: data.fullName || '', address: data.address || '', phone: data.phone || '', email: data.email || '', website: data.website || '', licenseNumber: data.licenseNumber || '', licenseValidUntil: data.licenseValidUntil ? String(data.licenseValidUntil).substring(0, 10) : '', logoUrl: data.logoUrl || '', }); } catch (err: any) { console.error('Error loading company settings:', err); alert(`Не удалось загрузить данные компании: ${err.message || 'Неизвестная ошибка'}`); } finally { setIsLoading(false); } }; load(); }, []); const handleChange = (field: keyof CompanySettings, value: string) => { setForm(prev => ({ ...prev, [field]: value })); }; const handleSave = async () => { try { setIsSaving(true); await apiClient.put('/settings/company', { name: form.name, fullName: form.fullName || null, address: form.address || null, phone: form.phone || null, email: form.email || null, website: form.website || null, licenseNumber: form.licenseNumber || null, licenseValidUntil: form.licenseValidUntil || null, logoUrl: form.logoUrl || null, }); alert('Данные управляющей компании сохранены'); onClose(); } catch (err: any) { console.error('Error saving company settings:', err); alert(`Не удалось сохранить данные компании: ${err.message || 'Неизвестная ошибка'}`); } finally { setIsSaving(false); } }; return (

Управляющая компания

Эти данные используются в отчетах жителям и PR-отчетах

{isLoading ? (
) : (
handleChange('name', e.target.value)} className="w-full px-3 py-2 rounded-xl border border-slate-200 text-sm" placeholder='Например: УК "Дружба"' />
handleChange('fullName', e.target.value)} className="w-full px-3 py-2 rounded-xl border border-slate-200 text-sm" placeholder='Например: ООО "Управляющая компания Дружба"' />
handleChange('address', e.target.value)} className="w-full px-3 py-2 rounded-xl border border-slate-200 text-sm" placeholder="Юридический / фактический адрес" />
handleChange('phone', e.target.value)} className="w-full px-3 py-2 rounded-xl border border-slate-200 text-sm" placeholder="+7 (___) ___-__-__" />
handleChange('email', e.target.value)} className="w-full px-3 py-2 rounded-xl border border-slate-200 text-sm" placeholder="info@company.ru" />
handleChange('website', e.target.value)} className="w-full px-3 py-2 rounded-xl border border-slate-200 text-sm" placeholder="https://..." />
handleChange('licenseNumber', e.target.value)} className="w-full px-3 py-2 rounded-xl border border-slate-200 text-sm" placeholder="Лицензия №..." />
handleChange('licenseValidUntil', e.target.value)} className="w-full px-3 py-2 rounded-xl border border-slate-200 text-sm" />
handleChange('logoUrl', e.target.value)} className="w-full px-3 py-2 rounded-xl border border-slate-200 text-sm" placeholder="https://.../logo.png" />
)}
); };