From ea6c39b86e14d42270f725040e2aa1a89a3c9cf6 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Wed, 11 Oct 2017 14:51:43 +0300 Subject: [PATCH] Bug fix: Ensure that file exists when showing ImageFromFile component --- .../ProfileSettingsForm/ProfileSettingsForm.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/containers/ProfileSettingsForm/ProfileSettingsForm.js b/src/containers/ProfileSettingsForm/ProfileSettingsForm.js index 471fdd9e..0d41a2a6 100644 --- a/src/containers/ProfileSettingsForm/ProfileSettingsForm.js +++ b/src/containers/ProfileSettingsForm/ProfileSettingsForm.js @@ -44,8 +44,10 @@ const RenderAvatar = props => { name={name} onChange={event => { const file = event.target.files[0]; - const tempId = `${file.name}_${Date.now()}`; - onChange({ id: tempId, file }); + if (file != null) { + const tempId = `${file.name}_${Date.now()}`; + onChange({ id: tempId, file }); + } }} type={type} /> @@ -152,9 +154,11 @@ class ProfileSettingsFormComponent extends Component { const transientUserProfileImage = profileImage.uploadedImage || user.profileImage; const transientUser = { ...user, profileImage: transientUserProfileImage }; - const fileUploadInProgress = uploadInProgress && profileImage.file; + // Ensure that file exists if imageFromFile is used + const fileExists = !!profileImage.file; + const fileUploadInProgress = uploadInProgress && fileExists; const delayAfterUpload = profileImage.imageId && this.state.uploadDelay; - const imageFromFile = fileUploadInProgress || delayAfterUpload + const imageFromFile = fileExists && (fileUploadInProgress || delayAfterUpload) ?