From dba497c854ed812e443b9bb856bd42065b1d6af6 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Fri, 13 Jun 2025 10:32:12 -0700 Subject: [PATCH] Fixed error checking on profile upload --- frontend/src/pages/candidate/Profile.tsx | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/candidate/Profile.tsx b/frontend/src/pages/candidate/Profile.tsx index 363676c..8058780 100644 --- a/frontend/src/pages/candidate/Profile.tsx +++ b/frontend/src/pages/candidate/Profile.tsx @@ -184,13 +184,32 @@ const CandidateProfile: React.FC = (props: BackstoryPageProp // Handle profile image upload const handleImageUpload = async (e: React.ChangeEvent) => { - if (e.target.files && e.target.files[0]) { - if (await apiClient.uploadCandidateProfile(e.target.files[0])) { + if (!e.target.files || !e.target.files[0]) { + return; + } + + try { + console.log('Uploading profile image:', e.target.files[0]); + const success = await apiClient.uploadCandidateProfile(e.target.files[0]); + if (success) { setProfileImage(URL.createObjectURL(e.target.files[0])); candidate.profileImage = 'profile.' + e.target.files[0].name.replace(/^.*\./, ''); console.log(`Set profile image to: ${candidate.profileImage}`); updateUserData(candidate); + } else { + setSnackbar({ + open: true, + message: 'Failed to upload profile image. Please try again.', + severity: 'error' + }); } + } catch (error) { + console.error('Error uploading profile image:', error); + setSnackbar({ + open: true, + message: 'Failed to upload profile image. Please try again.', + severity: 'error' + }); } };