'use client'; import { useState, memo, useRef } from 'react'; import { User, Shield, ChevronRight, X, Lock } from 'lucide-react'; import { inventoryApi } from '@/lib/api'; import { toast } from 'react-hot-toast'; interface IdentityCheckOverlayProps { show: boolean; users: any[]; onAuthenticated: (user: any) => void; } const IdentityCheckOverlay = memo(({ show, users, onAuthenticated }: IdentityCheckOverlayProps) => { const [selectedUserForLogin, setSelectedUserForLogin] = useState(null); const [isEnterprise, setIsEnterprise] = useState(false); const enterpriseUserRef = useRef(null); const enterprisePassRef = useRef(null); const localPassRef = useRef(null); if (!show) return null; const handleLogin = async () => { let username = ""; let password = ""; if (isEnterprise) { username = enterpriseUserRef.current?.value || ""; password = enterprisePassRef.current?.value || ""; } else if (selectedUserForLogin) { username = selectedUserForLogin.username; password = localPassRef.current?.value || ""; } if (!username) { toast.error("Username is required"); return; } try { const user = await inventoryApi.login({ username, password }); onAuthenticated(user); setSelectedUserForLogin(null); setIsEnterprise(false); } catch (error) { toast.error(isEnterprise ? "Login failed. Check credentials or group membership." : "Invalid password"); } }; const handleSelectUser = async (user: any) => { if (user.username === 'Admin' || user.id > 1) { setSelectedUserForLogin(user); return; } // Auto-login for passwordless users (if any exist beyond Admin) onAuthenticated(user); }; return (

Identity Check

Select operator profile to continue

{!selectedUserForLogin && !isEnterprise ? ( <> {users.map(user => ( ))}
) : isEnterprise ? (

Enterprise Account

e.key === 'Enter' && handleLogin()} className="w-full bg-slate-800/50 border border-slate-800 focus:border-primary rounded-2xl py-4 pl-12 pr-4 text-white focus:outline-none transition-all placeholder:text-slate-700 font-mono" placeholder="Enter password" />
) : (

Logging in as

{selectedUserForLogin.username}

e.key === 'Enter' && handleLogin()} className="w-full bg-slate-800/50 border border-slate-800 focus:border-primary rounded-2xl py-4 pl-12 pr-4 text-white focus:outline-none transition-all placeholder:text-slate-700 font-mono" placeholder="Enter password" />
)}
{users.length === 0 && (
Initializing users...
)}
); }); export default IdentityCheckOverlay;