import { CheckCircle2, CircleAlert } from "lucide-react"; import type React from "react"; import { useEffect, useState } from "react"; import { Navigate, NavLink, Route, Routes } from "react-router-dom"; import { toast } from "sonner"; import { Avatar, AvatarFallback, AvatarImage } from "../components/ui/avatar"; import { Badge } from "../components/ui/badge"; import { Button } from "../components/ui/button"; import { Input } from "../components/ui/input"; import { Label } from "../components/ui/label"; import { authClient, useSession } from "../lib/auth-client"; import { cn } from "../lib/utils"; import { AccountPage } from "./AccountPage"; type SettingsUser = { name?: string | null; email?: string | null; image?: string | null; emailVerified?: boolean; }; const settingsLinks = [ { to: "/settings/profile", label: "Profile" }, { to: "/settings/account", label: "Account" }, ]; function ProfileSettingsPage() { const { data: session, refetch } = useSession(); const user = session?.user as SettingsUser | undefined; const [name, setName] = useState(user?.name ?? ""); const [error, setError] = useState(null); const [isSaving, setIsSaving] = useState(false); useEffect(() => { setName(user?.name ?? ""); }, [user?.name]); const trimmedName = name.trim(); const isDirty = trimmedName !== (user?.name ?? ""); const canSave = isDirty && trimmedName.length > 0 && !isSaving; const fallback = profileInitial(trimmedName || user?.email || "?"); async function handleSubmit(event: React.FormEvent) { event.preventDefault(); if (!canSave) return; setError(null); setIsSaving(true); const { error } = await authClient.updateUser({ name: trimmedName, }); setIsSaving(false); if (error) { setError(error.message || "Failed to save profile"); toast.error("Failed to save profile"); return; } await refetch(); toast.success("Profile saved"); } return (

Profile

Manage the identity shown across VTIT Agent Coding.

{user?.image && } {fallback}
setName(event.target.value)} aria-invalid={trimmedName.length === 0} autoComplete="name" /> {trimmedName.length === 0 &&

Display name is required.

}
{error && (

{error}

)}
{!isDirty &&

No unsaved changes

}
); } function Field({ label, htmlFor, children }: { label: string; htmlFor: string; children: React.ReactNode }) { return (
{children}
); } function EmailVerificationBadge({ verified }: { verified: boolean }) { if (verified) { return ( Verified ); } return ( Unverified ); } function profileInitial(value: string) { return value.trim().charAt(0).toUpperCase() || "?"; } export function AccountSettingsPage() { return (
} /> } /> } /> } />
); }