import { useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Button } from "@/components/ui/button"; import { useAuth } from "@/contexts/AuthContext"; import { useToast } from "@/hooks/use-toast"; import { api } from "@/lib/api-client"; import { useMutation } from "@tanstack/react-query"; export default function AdminProfile() { const { user } = useAuth(); const { toast } = useToast(); const [firstName, setFirstName] = useState(user?.name?.split(" ")[0] ?? ""); const [lastName, setLastName] = useState(user?.name?.split(" ").slice(1).join(" ") ?? ""); const [email, setEmail] = useState(user?.email ?? ""); const [currentPw, setCurrentPw] = useState(""); const [newPw, setNewPw] = useState(""); const [confirmPw, setConfirmPw] = useState(""); const saveMutation = useMutation({ mutationFn: () => api.patch("/user", { name: `${firstName} ${lastName}`.trim(), email }), onSuccess: () => toast({ title: "Profile updated" }), onError: (err: Error) => toast({ title: "Error", description: err.message, variant: "destructive" }), }); const pwMutation = useMutation({ mutationFn: () => api.post("/user/change-password", { current_password: currentPw, new_password: newPw }), onSuccess: () => { toast({ title: "Password updated" }); setCurrentPw(""); setNewPw(""); setConfirmPw(""); }, onError: (err: Error) => toast({ title: "Error", description: err.message, variant: "destructive" }), }); return (
Manage your account information.
Passwords do not match
}