import { useEffect, useState } from 'react'; import type { ReactElement } from 'react'; import { Loader2 } from 'lucide-react'; import { Modal, SecondaryButton, StatusBadge } from '@/components/shared'; import type { Tenant } from '@/types/tenant'; interface ViewTenantModalProps { isOpen: boolean; onClose: () => void; tenantId: string | null; onLoadTenant: (id: string) => Promise; } // Helper function to get status badge variant const getStatusVariant = (status: string): 'success' | 'failure' | 'process' => { switch (status.toLowerCase()) { case 'active': return 'success'; case 'deleted': return 'failure'; case 'suspended': return 'process'; default: return 'success'; } }; // Helper function to format date const formatDate = (dateString: string): string => { const date = new Date(dateString); return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit', }); }; export const ViewTenantModal = ({ isOpen, onClose, tenantId, onLoadTenant, }: ViewTenantModalProps): ReactElement | null => { const [tenant, setTenant] = useState(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); // Load tenant data when modal opens useEffect(() => { if (isOpen && tenantId) { const loadTenant = async (): Promise => { try { setIsLoading(true); setError(null); const data = await onLoadTenant(tenantId); setTenant(data); } catch (err: any) { setError(err?.response?.data?.error?.message || 'Failed to load tenant details'); } finally { setIsLoading(false); } }; loadTenant(); } else { setTenant(null); setError(null); } }, [isOpen, tenantId, onLoadTenant]); return ( Close } >
{isLoading && (
)} {error && (

{error}

)} {!isLoading && !error && tenant && (
{/* Basic Information */}

Basic Information

{tenant.name}

{tenant.slug}

{tenant.status}
{/* Settings */}

Settings

{tenant.settings?.timezone || 'N/A'}

{tenant.subscription_tier ? tenant.subscription_tier.charAt(0).toUpperCase() + tenant.subscription_tier.slice(1) : 'N/A'}

{tenant.max_users ?? 'N/A'}

{tenant.max_modules ?? 'N/A'}

{/* Timestamps */}

Timestamps

{formatDate(tenant.created_at)}

{formatDate(tenant.updated_at)}

)}
); };