import { useEffect, useState } from 'react'; import type { ReactElement } from 'react'; import { Loader2 } from 'lucide-react'; import { Modal, SecondaryButton, StatusBadge } from '@/components/shared'; import type { User } from '@/types/user'; // Helper function to get status badge variant const getStatusVariant = (status: string): 'success' | 'failure' | 'process' => { switch (status.toLowerCase()) { case 'active': return 'success'; case 'blocked': 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', }); }; interface ViewUserModalProps { isOpen: boolean; onClose: () => void; userId: string | null; onLoadUser: (id: string) => Promise; } export const ViewUserModal = ({ isOpen, onClose, userId, onLoadUser, }: ViewUserModalProps): ReactElement | null => { const [user, setUser] = useState(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); // Load user data when modal opens useEffect(() => { if (isOpen && userId) { const loadUser = async (): Promise => { try { setIsLoading(true); setError(null); const data = await onLoadUser(userId); setUser(data); } catch (err: any) { setError(err?.response?.data?.error?.message || 'Failed to load user details'); } finally { setIsLoading(false); } }; loadUser(); } else { setUser(null); setError(null); } }, [isOpen, userId, onLoadUser]); return ( Close } >
{isLoading && (
)} {error && (

{error}

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

Basic Information

{user.email}

{user.first_name} {user.last_name}

{user.status}

{user.auth_provider}

{user.tenant_id && (

{user.tenant_id}

)}
{/* Timestamps */}

Timestamps

{formatDate(user.created_at)}

{formatDate(user.updated_at)}

)}
); };