import React, { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { ShieldAlert, RefreshCw, LogOut, UserCheck, CheckCircle2, AlertTriangle, ArrowLeft, Mail, Building2, Fingerprint, } from 'lucide-react'; import { BrandLogo } from '../ui/BrandLogo'; import { AuthUserProfile, UserClaims } from '../../auth/AuthProvider'; import { cancelSessionExpiration, dismissSubordinateModals } from '../../services/sessionExpiration'; interface AccountActivationModalProps { user: AuthUserProfile | null; claims: UserClaims; sub: string; onSync: (force?: boolean) => Promise<{ success: boolean; isUnauthorized?: boolean; errorMessage?: string }>; onLogout: () => Promise; initialError?: string | null; } export const AccountActivationModal: React.FC = ({ user, claims, sub, onSync, onLogout, initialError, }) => { const navigate = useNavigate(); const [isSyncing, setIsSyncing] = useState(false); const [errorMessage, setErrorMessage] = useState(initialError || null); const [syncAttemptCount, setSyncAttemptCount] = useState(0); // Activation process dismisses all other modals so that it is displayed without overlapping. // By extension, any active session expiration modal is dismissed and its processes cancelled. useEffect(() => { cancelSessionExpiration(); dismissSubordinateModals(); }, []); const displayName = user?.name || (claims.name as string) || (claims.preferred_username as string) || 'Registered User'; const displayEmail = user?.email || (claims.email as string) || (claims['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'] as string) || ''; const tenant = user?.tenant || (claims.tenant as string) || (claims.org as string) || 'Standard Enterprise'; const role = user?.role || (claims.role as string) || 'User'; const handleSyncClick = async () => { if (isSyncing) return; setIsSyncing(true); setErrorMessage(null); try { const result = await onSync(true); if (result.isUnauthorized) { // HTTP 401: Routine process of routing user to landing page await onLogout(); navigate('/', { replace: true }); return; } if (!result.success) { setSyncAttemptCount((prev) => prev + 1); setErrorMessage( result.errorMessage || 'Account is not yet enabled. The administrator has not activated your account in the system directory.' ); } // If result.success is true, AuthProvider updates state, and this modal unmounts automatically! } catch (err: any) { if (err?.response?.status === 401) { await onLogout(); navigate('/', { replace: true }); return; } setErrorMessage( err?.message || 'Account activation check encountered an error. Please confirm with your administrator and try again.' ); } finally { setIsSyncing(false); } }; const handleSignOut = async () => { await onLogout(); navigate('/', { replace: true }); }; const handleNavigateLanding = () => { navigate('/'); }; return (
{/* Non-dismissable Card Container: No X button, no escape dismiss, no backdrop click */}
e.stopPropagation()} > {/* Amber accent top bar */}
{/* Modal Header */}
Access Restricted • Awaiting Enablement

Account Pending Administrator Activation

{/* Modal Body */}
{/* Status notification block */}
Identity Verified & Signed In Successfully

You are a registered user and have successfully authenticated via Enterprise Single Sign-On. However, your account has not yet been enabled in the system directory by a system administrator.

If your administrator informs you that your account has been activated, please click the{' '} Sync Account button below to refresh your status and unlock the system.

{/* User Profile Card */}
Authenticated User Profile Lockout Active
Name {displayName}
Email {displayEmail || 'Not specified'}
Tenant / Role {tenant} ({role})
Subject ID {sub || 'SSO-Principal'}
{/* Sync Attempt Feedback / Error Notice */} {errorMessage && (

Account Not Activated Yet

{errorMessage}

{syncAttemptCount > 0 && (

Attempt #{syncAttemptCount} checked at {new Date().toLocaleTimeString()}

)}
)}
{/* Modal Actions */}
); };