Skip to content

Commit 8b12095

Browse files
authored
Merge pull request #141 from kids-first/add-alert-failed-upload
💄 Add "Failed to upload file" alert
2 parents f4f0cf3 + ec25b3e commit 8b12095

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/components/FileUpload/FileUploadTarget.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
55
const FileUploadTarget = props => {
66
const {
77
className,
8+
error,
89
instructions,
910
handleSelectedFile,
1011
handleDragOver,
@@ -47,15 +48,22 @@ const FileUploadTarget = props => {
4748
className="Button Button--default"
4849
onChange={handleSelectedFile}
4950
/>
51+
{error && error.graphQLErrors && (
52+
<h4 className="text-red px-2">
53+
Failed to upload: {error.graphQLErrors.map(err => err.message)}
54+
</h4>
55+
)}
5056
</form>
5157
);
5258
};
5359

5460
FileUploadTarget.propTypes = {
5561
/** any additional classes that should be added to the container */
5662
className: PropTypes.string,
57-
/** if cursor is currently dragging over the component
58-
dragging: PropTypes.boolean,
63+
/** if cursor is currently dragging over the component */
64+
dragging: PropTypes.bool,
65+
/** Errors from graphQL */
66+
errors: PropTypes.object,
5967
/** add helpful instruction about how to drag and drop files */
6068
instructions: PropTypes.string,
6169
/** operation when component is dragged over */

src/containers/UploadContainer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const UploadContainer = props => {
4545
})
4646
.catch(err => {
4747
console.log(err);
48+
alert('Failed to upload file.');
4849
});
4950
};
5051

@@ -74,8 +75,9 @@ const UploadContainer = props => {
7475
},
7576
]}
7677
>
77-
{(createFile, {data}) => (
78+
{(createFile, {data, error}) => (
7879
<FileUploadTarget
80+
error={error}
7981
dragging={dragging}
8082
handleDragOver={handleDragOver}
8183
onDragEnter={handleDragEnter}

0 commit comments

Comments
 (0)