"use client"; import { useState, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card, CardHeader, CardTitle, CardDescription, CardContent } from "@/components/ui/card"; import { User, Mail, Phone, Save, ArrowLeft, Lock, Eye, EyeOff, Loader2, } from "lucide-react"; import Link from "next/link"; import { useAppTheme } from "@/components/ThemeProvider"; import { getProfile, updateProfile } from "@/lib/actions/auth"; import { toast } from "sonner"; export default function AdminSettingsPage() { const [loading, setLoading] = useState(false); const [fetching, setFetching] = useState(true); const [formData, setFormData] = useState({ firstName: "", lastName: "", email: "", phone: "", }); const [passwordData, setPasswordData] = useState({ currentPassword: "", newPassword: "", confirmPassword: "", }); const [showPasswords, setShowPasswords] = useState({ current: false, new: false, confirm: false, }); const { theme } = useAppTheme(); const isDark = theme === "dark"; // Fetch profile data on mount useEffect(() => { const fetchProfile = async () => { setFetching(true); try { const profile = await getProfile(); setFormData({ firstName: profile.first_name || "", lastName: profile.last_name || "", email: profile.email || "", phone: profile.phone_number || "", }); } catch (error) { console.error("Failed to fetch profile:", error); const errorMessage = error instanceof Error ? error.message : "Failed to load profile"; toast.error(errorMessage); } finally { setFetching(false); } }; fetchProfile(); }, []); const handleInputChange = (field: string, value: string) => { setFormData((prev) => ({ ...prev, [field]: value, })); }; const handlePasswordChange = (field: string, value: string) => { setPasswordData((prev) => ({ ...prev, [field]: value, })); }; const togglePasswordVisibility = (field: "current" | "new" | "confirm") => { setShowPasswords((prev) => ({ ...prev, [field]: !prev[field], })); }; const handleSave = async () => { if (!formData.firstName || !formData.lastName) { toast.error("First name and last name are required"); return; } setLoading(true); try { await updateProfile({ first_name: formData.firstName, last_name: formData.lastName, phone_number: formData.phone || undefined, }); toast.success("Profile updated successfully!"); } catch (error) { console.error("Failed to update profile:", error); const errorMessage = error instanceof Error ? error.message : "Failed to update profile"; toast.error(errorMessage); } finally { setLoading(false); } }; const handlePasswordSave = async () => { if (passwordData.newPassword !== passwordData.confirmPassword) { // In a real app, you would show an error message here alert("New passwords do not match"); return; } if (passwordData.newPassword.length < 8) { // In a real app, you would show an error message here alert("Password must be at least 8 characters long"); return; } setLoading(true); // Simulate API call await new Promise((resolve) => setTimeout(resolve, 1000)); setLoading(false); // Reset password fields setPasswordData({ currentPassword: "", newPassword: "", confirmPassword: "", }); // In a real app, you would show a success message here }; return (
{/* Main Content */}
{/* Header */}

Settings

Manage your account settings and practice information

{/* Profile Information */}
Profile Information
Update your personal information and contact details
{fetching ? (
) : ( <>
handleInputChange("firstName", e.target.value)} className={`pl-10 ${isDark ? "bg-gray-700 border-gray-600 text-white placeholder:text-gray-400" : ""}`} placeholder="Enter your first name" required />
handleInputChange("lastName", e.target.value)} className={`pl-10 ${isDark ? "bg-gray-700 border-gray-600 text-white placeholder:text-gray-400" : ""}`} placeholder="Enter your last name" required />
)}

Email address cannot be changed

handleInputChange("phone", e.target.value)} className={`pl-10 ${isDark ? "bg-gray-700 border-gray-600 text-white placeholder:text-gray-400" : ""}`} placeholder="Enter your phone number" />
{/* Change Password */}
Change Password
Update your password to keep your account secure
handlePasswordChange("currentPassword", e.target.value)} className={`pl-10 pr-10 ${isDark ? "bg-gray-700 border-gray-600 text-white placeholder:text-gray-400" : ""}`} placeholder="Enter your current password" />
handlePasswordChange("newPassword", e.target.value)} className={`pl-10 pr-10 ${isDark ? "bg-gray-700 border-gray-600 text-white placeholder:text-gray-400" : ""}`} placeholder="Enter your new password" />

Password must be at least 8 characters long

handlePasswordChange("confirmPassword", e.target.value)} className={`pl-10 pr-10 ${isDark ? "bg-gray-700 border-gray-600 text-white placeholder:text-gray-400" : ""}`} placeholder="Confirm your new password" />
); }