Fixed error checking on profile upload
This commit is contained in:
parent
afd8c1df21
commit
dba497c854
@ -184,13 +184,32 @@ const CandidateProfile: React.FC<BackstoryPageProps> = (props: BackstoryPageProp
|
|||||||
|
|
||||||
// Handle profile image upload
|
// Handle profile image upload
|
||||||
const handleImageUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleImageUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
if (e.target.files && e.target.files[0]) {
|
if (!e.target.files || !e.target.files[0]) {
|
||||||
if (await apiClient.uploadCandidateProfile(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]));
|
setProfileImage(URL.createObjectURL(e.target.files[0]));
|
||||||
candidate.profileImage = 'profile.' + e.target.files[0].name.replace(/^.*\./, '');
|
candidate.profileImage = 'profile.' + e.target.files[0].name.replace(/^.*\./, '');
|
||||||
console.log(`Set profile image to: ${candidate.profileImage}`);
|
console.log(`Set profile image to: ${candidate.profileImage}`);
|
||||||
updateUserData(candidate);
|
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'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user