'use client'; import { BuildingOfficeIcon, ArrowLeftIcon, PaintBrushIcon, MapPinIcon } from '@heroicons/react/24/outline'; import Link from 'next/link'; import { useEffect, useState } from 'react'; import { useParams } from 'next/navigation'; interface AgencyTenant { id: string; name: string; subdomain: string; domain: string; email: string; phone: string; website: string; cnpj: string; razao_social: string; description: string; industry: string; team_size: string; address: string; neighborhood: string; number: string; complement: string; city: string; state: string; zip: string; primary_color: string; secondary_color: string; logo_url: string; logo_horizontal_url: string; is_active: boolean; created_at: string; updated_at: string; } interface AgencyDetails { tenant: AgencyTenant; admin?: { id: string; email: string; name: string; }; access_url: string; } export default function AgencyDetailPage() { const params = useParams(); const [details, setDetails] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { if (params.id) { fetchAgency(params.id as string); } }, [params.id]); const fetchAgency = async (id: string) => { try { const response = await fetch(`/api/admin/agencies/${id}`, { headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}`, }, }); if (response.ok) { const data = await response.json(); // Handle both flat (legacy) and nested (new) responses if (data.tenant) { setDetails(data); } else { // Fallback for legacy flat response setDetails({ tenant: data, access_url: `http://${data.subdomain}.localhost`, // Fallback URL }); } } } catch (error) { console.error('Error fetching agency:', error); } finally { setLoading(false); } }; if (loading) { return (
); } if (!details || !details.tenant) { return (
Erro! Agência não encontrada.
Voltar para Agências
); } const { tenant } = details; return (
Voltar para Agências
{tenant.logo_url ? ( {tenant.name} ) : ( )}

{tenant.name}

{tenant.subdomain}.aggios.app | {tenant.is_active ? 'Ativa' : 'Inativa'}
Editar Dados
{/* Coluna Esquerda (2/3) */}
{/* Informações Básicas */}

Dados da Empresa

Razão Social
{tenant.razao_social || '-'}
CNPJ
{tenant.cnpj || '-'}
Setor
{tenant.industry || '-'}
Tamanho da Equipe
{tenant.team_size || '-'}
Descrição
{tenant.description || '-'}
{/* Endereço */}

Localização

Endereço
{tenant.address ? ( <> {tenant.address} {tenant.number ? `, ${tenant.number}` : ''} {tenant.complement ? ` - ${tenant.complement}` : ''} ) : '-'}
Bairro
{tenant.neighborhood || '-'}
Cidade / UF
{tenant.city && tenant.state ? `${tenant.city} - ${tenant.state}` : '-'}
CEP
{tenant.zip || '-'}
{/* Coluna Direita (1/3) */}
{/* Branding */}

Identidade Visual

Cores da Marca
{tenant.primary_color || '-'}
{tenant.secondary_color || '-'}
{tenant.logo_horizontal_url && (
Logo Horizontal
Logo Horizontal
)}
{/* Contato */}

Contato

Email
{tenant.email || '-'}
Telefone
{tenant.phone || '-'}
Website
{tenant.website ? ( {tenant.website} ) : '-'}
{/* Metadados */}
Criada em
{new Date(tenant.created_at).toLocaleDateString('pt-BR')}
Última atualização
{new Date(tenant.updated_at).toLocaleDateString('pt-BR')}
); }