import { useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import { User } from "lucide-react"; import { api } from "@/lib/api-client"; import { useMutation } from "@tanstack/react-query"; import { useToast } from "@/hooks/use-toast"; import { useAuth } from "@/contexts/AuthContext"; export default function ProfilePage() { const { user } = useAuth(); const { toast } = useToast(); const nameParts = (user?.name || "Admin User").split(" "); const [first, setFirst] = useState(nameParts[0] || ""); const [last, setLast] = useState(nameParts.slice(1).join(" ") || ""); const [email, setEmail] = useState(user?.email || ""); const [curPw, setCurPw] = useState(""); const [newPw, setNewPw] = useState(""); const [confirmPw, setConfirmPw] = useState(""); const saveMut = useMutation({ mutationFn: () => api.patch("/user", { first_name: first, last_name: last, email }), onSuccess: () => toast({ title: "Profile saved" }), onError: (err: Error) => toast({ title: "Error", description: err.message, variant: "destructive" }), }); const pwMut = useMutation({ mutationFn: () => api.post("/user/change-password", { current_password: curPw, new_password: newPw }), onSuccess: () => { setCurPw(""); setNewPw(""); setConfirmPw(""); toast({ title: "Password updated" }); }, onError: (err: Error) => toast({ title: "Error", description: err.message, variant: "destructive" }), }); return (
Manage your account information.
Passwords do not match.
}