import React, { useEffect, useState } from 'react'; import { apiClient } from '../../services/apiClient'; import { Building2, Loader2 } from 'lucide-react'; type CompanySettings = { 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; }; const emptyCompany: CompanySettings = { name: '', fullName: '', address: '', phone: '', email: '', website: '', licenseNumber: '', licenseValidUntil: '', logoUrl: '', }; export const CompanySection: React.FC = () => { const [form, setForm] = useState(emptyCompany); const [isLoading, setIsLoading] = useState(true); const [isSaving, setIsSaving] = useState(false); 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) { console.error('Error loading company settings:', err); } finally { setIsLoading(false); } }; useEffect(() => { load(); }, []); const handleChange = (field: keyof CompanySettings, value: string) => { setForm((prev) => ({ ...prev, [field]: value })); }; const handleSave = async () => { if (!form.name) return; 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('Данные управляющей компании сохранены'); } catch (err: any) { console.error('Error saving company settings:', err); alert(`Не удалось сохранить: ${err?.message || 'Неизвестная ошибка'}`); } finally { setIsSaving(false); } }; if (isLoading) { return (
); } return (

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

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

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" />
); };