Settings
Manage your account settings and preferences
Email address cannot be changed
Password must be at least 8 characters long
"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 { Navbar } from "@/components/Navbar"; import { useAppTheme } from "@/components/ThemeProvider"; import { getProfile, updateProfile } from "@/lib/actions/auth"; import { useAuth } from "@/hooks/useAuth"; import { toast } from "sonner"; export default function SettingsPage() { const { theme } = useAppTheme(); const isDark = theme === "dark"; const { user } = useAuth(); 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, }); // 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.currentPassword) { toast.error("Please enter your current password"); return; } if (passwordData.newPassword !== passwordData.confirmPassword) { toast.error("New passwords do not match"); return; } if (passwordData.newPassword.length < 8) { toast.error("Password must be at least 8 characters long"); return; } setLoading(true); try { // Note: The API might not have a change password endpoint for authenticated users // This would need to be implemented on the backend // For now, we'll show a message that this feature is coming soon toast.error("Password change feature is not yet available. Please use the forgot password flow."); // Reset password fields setPasswordData({ currentPassword: "", newPassword: "", confirmPassword: "", }); } catch (error) { console.error("Failed to update password:", error); const errorMessage = error instanceof Error ? error.message : "Failed to update password"; toast.error(errorMessage); } finally { setLoading(false); } }; return (
Manage your account settings and preferences
Email address cannot be changed
Password must be at least 8 characters long