import React, { useState, useEffect } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { User, Shield, Key, AlertCircle } from "lucide-react"; import { TOTPSetup } from "@/ui/TOTPSetup"; import { getUserInfo } from "@/ui/main-axios"; import { toast } from "sonner"; interface UserProfileProps { isTopbarOpen?: boolean; } export function UserProfile({ isTopbarOpen = true }: UserProfileProps) { const [userInfo, setUserInfo] = useState<{ username: string; is_admin: boolean; is_oidc: boolean; totp_enabled: boolean; } | null>(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { fetchUserInfo(); }, []); const fetchUserInfo = async () => { setLoading(true); setError(null); try { const info = await getUserInfo(); setUserInfo({ username: info.username, is_admin: info.is_admin, is_oidc: info.is_oidc, totp_enabled: info.totp_enabled || false }); } catch (err: any) { setError(err?.response?.data?.error || "Failed to load user information"); } finally { setLoading(false); } }; const handleTOTPStatusChange = (enabled: boolean) => { if (userInfo) { setUserInfo({ ...userInfo, totp_enabled: enabled }); } }; if (loading) { return (
Loading user profile...
); } if (error || !userInfo) { return (
Error {error || "Failed to load user profile"}
); } return (

User Profile

Manage your account settings and security

Profile Security Account Information Your account details and settings

{userInfo.username}

{userInfo.is_admin ? "Administrator" : "User"}

{userInfo.is_oidc ? "External (OIDC)" : "Local"}

{userInfo.totp_enabled ? ( Enabled ) : ( Disabled )}

{!userInfo.is_oidc && ( Password Change your account password

Password change functionality can be implemented here

)}
); }