diff --git a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx index a56b65919..804cd92eb 100644 --- a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx +++ b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx @@ -77,6 +77,7 @@ const ProfilePanel = () => { src: URL.createObjectURL(pic), name: pic.name, size: formatBytes(pic.size), + delete: false, }); //TODO - potentitally remove once image compression functions are implemented @@ -116,13 +117,23 @@ const ProfilePanel = () => { // Resets picture-related states and clears interval const removePicture = () => { errors["picture"] && clearError("picture"); + setFile({ delete: true }); clearInterval(intervalRef.current); // interrupt interval if image upload is canceled prior to completing the process setProgress({ value: 0, isLoading: false }); }; + // Opens the picture update modal + const openPictureModal = () => { + setIsOpen("picture"); + setFile({ delete: localData.deleteProfileImage }); + }; + // Closes the picture update modal and resets related states const closePictureModal = () => { - removePicture(); + errors["picture"] && clearError("picture"); + setFile(); //reset file + clearInterval(intervalRef.current); // interrupt interval if image upload is canceled prior to completing the process + setProgress({ value: 0, isLoading: false }); setIsOpen(""); }; @@ -132,20 +143,27 @@ const ProfilePanel = () => { setLocalData((prev) => ({ ...prev, file: file.src, + deleteProfileImage: false, })); setIsOpen(""); }; + console.log( + localData.deleteProfileImage === false && localData.file === undefined + ); + // Handles form submission to update user profile const handleSaveProfile = (event) => { event.preventDefault(); - // if ( - // localData.firstname === user.firstname && - // localData.lastname === user.lastname - // ) { - // // TODO: Add toast/notification for unchanged profile data - // return; - // } + if ( + localData.firstname === user.firstname && + localData.lastname === user.lastname && + localData.deleteProfileImage === undefined && + localData.file === undefined + ) { + // TODO: Add toast/notification for unchanged profile data + return; + } dispatch(update({ authToken, localData })); // TODO: Add toast/notification for profile update success @@ -153,7 +171,10 @@ const ProfilePanel = () => { // Removes current profile image from UI const handleDeletePicture = () => { - // TODO - implement delete picture function + setLocalData((prev) => ({ + ...prev, + deleteProfileImage: true, + })); }; // Initiates the account deletion process @@ -249,7 +270,16 @@ const ProfilePanel = () => { - +