From 6dee2980ed0e6d0d3070787792b99c3b4f5f1d45 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Thu, 13 Jul 2017 15:47:01 +0300 Subject: [PATCH 1/2] EditListingPhotosForm: submit should be disabled when image upload is happening --- .../EditListingPhotosForm/EditListingPhotosForm.js | 14 ++++++++++++-- .../EditListingPhotosForm.test.js.snap | 1 + src/translations/en.json | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/containers/EditListingPhotosForm/EditListingPhotosForm.js b/src/containers/EditListingPhotosForm/EditListingPhotosForm.js index e91d7f2b..449b081b 100644 --- a/src/containers/EditListingPhotosForm/EditListingPhotosForm.js +++ b/src/containers/EditListingPhotosForm/EditListingPhotosForm.js @@ -43,6 +43,7 @@ RenderAddImage.propTypes = { export class EditListingPhotosFormComponent extends Component { constructor(props) { super(props); + this.state = { imageUploadRequested: false }; this.onImageUploadHandler = this.onImageUploadHandler.bind(this); this.onSortEnd = this.onSortEnd.bind(this); } @@ -56,7 +57,14 @@ export class EditListingPhotosFormComponent extends Component { onImageUploadHandler(event) { const file = event.target.files[0]; if (file) { - this.props.onImageUpload({ id: `${file.name}_${Date.now()}`, file }); + this.setState({ imageUploadRequested: true }); + this.props.onImageUpload({ id: `${file.name}_${Date.now()}`, file }) + .then(() => { + this.setState({ imageUploadRequested: false }); + }) + .catch(() => { + this.setState({ imageUploadRequested: false }); + }); } } @@ -117,6 +125,8 @@ export class EditListingPhotosFormComponent extends Component { const classes = classNames(css.root, className); + const disableForm = invalid || submitting || disabled || this.state.imageUploadRequested; + return (
@@ -157,7 +167,7 @@ export class EditListingPhotosFormComponent extends Component { diff --git a/src/containers/EditListingPhotosForm/__snapshots__/EditListingPhotosForm.test.js.snap b/src/containers/EditListingPhotosForm/__snapshots__/EditListingPhotosForm.test.js.snap index e4676034..b99080b0 100644 --- a/src/containers/EditListingPhotosForm/__snapshots__/EditListingPhotosForm.test.js.snap +++ b/src/containers/EditListingPhotosForm/__snapshots__/EditListingPhotosForm.test.js.snap @@ -44,6 +44,7 @@ exports[`EditListingPhotosForm matches snapshot 1`] = `