Added toast alerts to profile panel

This commit is contained in:
Daniel Cojocea committed 2024-07-11 18:53:14 -04:00
1 parent 4b9c0b86c4
commit 7e1ccff00d
4 files changed
+28 -10

No files matched your search

@@ -22,7 +22,7 @@ import ImageIcon from "@mui/icons-material/Image";
import ProgressUpload from "../../ProgressBars";
import { formatBytes } from "../../../Utils/fileUtils";
import { clearMonitorState } from "../../../Features/Monitors/monitorsSlice";
import { createToast } from "../../../Utils/toastUtils";
/**
* ProfilePanel component displays a form for editing user profile information
* and allows for actions like updating profile picture, credentials,
@@ -153,12 +153,8 @@ const ProfilePanel = () => {
setIsOpen("");
};
console.log(
localData.deleteProfileImage === false && localData.file === undefined
);
// Handles form submission to update user profile
const handleSaveProfile = (event) => {
const handleSaveProfile = async (event) => {
event.preventDefault();
if (
localData.firstname === user.firstname &&
@@ -166,12 +162,28 @@ const ProfilePanel = () => {
localData.deleteProfileImage === undefined &&
localData.file === undefined
) {
// TODO: Add toast/notification for unchanged profile data
createToast({
variant: "error",
body: "Unable to update profile: No changes detected.",
hasIcon: false,
});
return;
}
dispatch(update({ authToken, localData }));
// TODO: Add toast/notification for profile update success
const action = await dispatch(update({ authToken, localData }));
if (action.payload.success) {
createToast({
variant: "info",
body: "Your profile data was changed successfully.",
hasIcon: false,
});
} else {
createToast({
variant: "error",
body: "There was an error updating your profile data.",
hasIcon: false,
});
}
};
// Removes current profile image from UI