import { useState, useEffect } from "react"; import { useDispatch, useSelector } from "react-redux"; import { updateUser } from "../redux/features/authSlice"; import { useNavigate } from "react-router-dom"; import FileBase from "react-file-base64"; import { toast } from "react-toastify"; const UserProfile = () => { const { user, isLoading } = useSelector((state) => state.auth); const dispatch = useDispatch(); const navigate = useNavigate(); const [formData, setFormData] = useState({ userId: user?.result?.userId || "", title: user?.result?.title || "", firstName: user?.result?.firstName || "", middleName: user?.result?.middleName || "", lastName: user?.result?.lastName || "", email: user?.result?.email || "", aboutme: user?.result?.aboutme || "", city: user?.result?.city || "", state: user?.result?.state || "", county: user?.result?.county || "", zip: user?.result?.zip || "", profileImage: user?.result?.profileImage || "", // For storing the image }); useEffect(() => { if (user) { setFormData({ userId: user.result.userId, title: user.result.title, firstName: user.result.firstName, middleName: user.result.middleName, lastName: user.result.lastName, email: user.result.email, aboutme: user.result.aboutme, city: user.result.city, state: user.result.state, county: user.result.county, zip: user.result.zip, profileImage: user.result.profileImage, }); } }, [user]); const handleChange = (e) => { setFormData({ ...formData, [e.target.name]: e.target.value }); }; const handleImageDelete = () => { setFormData({ ...formData, profileImage: "" }); // Reset the profileImage field }; const handleSubmit = (e) => { e.preventDefault(); dispatch(updateUser({formData, toast, navigate})); // Dispatching updateUser with form data }; return ( <>
> ); }; export default UserProfile;