From 298698e42cb42cff9f28e45af272aa144e9c8053 Mon Sep 17 00:00:00 2001 From: Ashish4n8 Date: Wed, 13 Nov 2024 16:35:11 -0600 Subject: [PATCH] update rehireable status if response is 200 --- src/actions/userManagement.js | 14 +++++++------- src/components/UserProfile/UserProfile.jsx | 14 +++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/actions/userManagement.js b/src/actions/userManagement.js index c43d7414bd..cc5885ba2a 100644 --- a/src/actions/userManagement.js +++ b/src/actions/userManagement.js @@ -85,15 +85,15 @@ export const updateUserStatus = (user, status, reactivationDate) => { * @param{boolean} isRehireable - the new rehireable status */ export const updateRehireableStatus = (user, isRehireable) => { - const userProfile = { ...user }; - userProfile.isRehireable = isRehireable - const requestData = { isRehireable }; - - const updateProfilePromise = axios.patch(ENDPOINTS.UPDATE_REHIREABLE_STATUS(user._id), requestData) return async dispatch => { - updateProfilePromise.then(res => { + const userProfile = { ...user, isRehireable }; + const requestData = { isRehireable }; + try { + await axios.patch(ENDPOINTS.UPDATE_REHIREABLE_STATUS(user._id), requestData); dispatch(userProfileUpdateAction(userProfile)); - }); + } catch (err) { + throw err; + } }; }; diff --git a/src/components/UserProfile/UserProfile.jsx b/src/components/UserProfile/UserProfile.jsx index 6bc6ed2d8c..1872f113cf 100644 --- a/src/components/UserProfile/UserProfile.jsx +++ b/src/components/UserProfile/UserProfile.jsx @@ -695,16 +695,20 @@ function UserProfile(props) { setShowConfirmDialog(true); }; - const handleConfirmChange = () => { + const handleConfirmChange = async () => { setShowConfirmDialog(false); const updatedUserProfile = { ...userProfile, isRehireable: pendingRehireableStatus, }; - updateRehireableStatus(updatedUserProfile, pendingRehireableStatus); - setIsRehireable(pendingRehireableStatus); - setUserProfile(updatedUserProfile); - setOriginalUserProfile(updatedUserProfile); + try{ + await dispatch(updateRehireableStatus(updatedUserProfile, pendingRehireableStatus)); + setIsRehireable(pendingRehireableStatus); + setUserProfile(updatedUserProfile); + setOriginalUserProfile(updatedUserProfile); + }catch(error){ + toast.error('Unable change rehireable status'); + } }; const handleCancelChange = () => {