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