Fixed avatar image not displaying

This commit is contained in:
Daniel Cojocea committed 2024-07-08 16:06:12 -04:00
1 parent 7f7226d6e5
commit 31e4c7b110
3 files changed
+7 -24

No files matched your search

+6 -21
View File
@@ -23,33 +23,18 @@ const Avatar = ({ src, small, sx }) => {
const border = small ? 1 : 3; const border = small ? 1 : 3;
const [image, setImage] = useState(); const [image, setImage] = useState();
// useEffect(() => { useEffect(() => {
// const fetchData = async () => { if (user.avatarImage) {
// try { setImage(`data:image/png;base64,${user.avatarImage}`);
// if (user.profileImage.data && user.profileImage.contentType) { }
// const url = await bufferToUrl(user.profileImage); }, [user?.avatarImage]);
// setImage(url);
// }
// } catch (error) {
// console.error("Error converting buffer to URL: ", error);
// }
// };
// fetchData();
// }, [user]);
return ( return (
<MuiAvatar <MuiAvatar
alt={`${user?.firstname} ${user?.lastname}`} alt={`${user?.firstname} ${user?.lastname}`}
children={`${user.firstname?.charAt(0)}${user.lastname?.charAt(0)}`} children={`${user.firstname?.charAt(0)}${user.lastname?.charAt(0)}`}
src={ src={
src === "placeholder" src ? src : user?.avatarImage ? image : "/static/images/avatar/2.jpg"
? "/static/images/avatar/2.jpg"
: src
? src
: user?.profileImage
? image
: "/static/images/avatar/2.jpg"
} }
sx={{ sx={{
fontSize: small ? "12px" : "20px", fontSize: small ? "12px" : "20px",
@@ -116,7 +116,6 @@ const ProfilePanel = () => {
// Resets picture-related states and clears interval // Resets picture-related states and clears interval
const removePicture = () => { const removePicture = () => {
errors["picture"] && clearError("picture"); errors["picture"] && clearError("picture");
setFile({ src: "placeholder" });
clearInterval(intervalRef.current); // interrupt interval if image upload is canceled prior to completing the process clearInterval(intervalRef.current); // interrupt interval if image upload is canceled prior to completing the process
setProgress({ value: 0, isLoading: false }); setProgress({ value: 0, isLoading: false });
}; };
@@ -154,7 +153,6 @@ const ProfilePanel = () => {
// Removes current profile image from UI // Removes current profile image from UI
const handleDeletePicture = () => { const handleDeletePicture = () => {
setFile({ src: "placeholder" });
// TODO - implement delete picture function // TODO - implement delete picture function
}; };
+1 -1
View File
@@ -48,7 +48,7 @@ export const update = createAsyncThunk(
await new Promise((resolve) => setTimeout(resolve, 1500)); await new Promise((resolve) => setTimeout(resolve, 1500));
const fd = new FormData(); const fd = new FormData();
const imageResult = await axios.get(form.file); const imageResult = await axios.get(form.file, { responseType: "blob" });
fd.append("firstname", form.firstname); fd.append("firstname", form.firstname);
fd.append("lastname", form.lastname); fd.append("lastname", form.lastname);
fd.append("profileImage", imageResult.data); fd.append("profileImage", imageResult.data);