Fixed error checking on profile upload

This commit is contained in:
James Ketr 2025-06-13 10:32:12 -07:00
parent afd8c1df21
commit dba497c854

View File

@ -184,13 +184,32 @@ const CandidateProfile: React.FC<BackstoryPageProps> = (props: BackstoryPageProp
// Handle profile image upload
const handleImageUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
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'
});
}
};