// ProfileUpdate.js
const handleSubmit = async (e) => {
e.preventDefault();
try {
setLoading(true);
// console.log(username, name, email, company, address, phone, about, photo);
const { data } = await axios.put("/update-profile", {
username,
name,
email,
company,
address,
phone,
about,
photo,
});
if (data?.error) {
toast.error(data.error);
setLoading(false);
} else {
console.log("profile update response => ", data);
setAuth({ ...auth, user: data });
let fromLS = JSON.parse(localStorage.getItem("auth"));
fromLS.user = data;
localStorage.setItem("auth", JSON.stringify(fromLS));
setLoading(false);
toast.success("Profile updated");
}
} catch (err) {
console.log(err);
toast.error("Profile update failed. Try again.");
setLoading(false);
}
};