Skip to content
Snippets Groups Projects
Commit 75f0e9ed authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

fix(upload): fix remove file issue

parent b6c3a4d7
No related branches found
No related tags found
1 merge request!13Sprint #14
......@@ -34,7 +34,7 @@ const Files = ({
dropSortableFile,
}) => (
<div>
<Error show={error}>Error uploading file, please try again.</Error>
<Error show={error}> File error, please try again.</Error>
<FileSection
addFile={addFile('manuscripts')}
allowedFileExtensions={['pdf', 'doc', 'docx']}
......@@ -97,6 +97,7 @@ export default compose(
lifecycle({
componentDidMount() {
const { version: { files }, setFiles } = this.props
console.log('----------------', files)
setFiles(prev => ({
manuscripts: get(files, 'manuscripts') || [],
coverLetter: get(files, 'coverLetter') || [],
......@@ -149,9 +150,7 @@ export default compose(
[type]: [...files[type], file],
}
setFiles(newFiles)
setTimeout(() => {
changeForm('wizard', 'files', newFiles)
}, 1000)
changeForm('wizard', 'files', newFiles)
})
.catch(e => console.error(`Couldn't upload file.`, e))
},
......@@ -173,13 +172,16 @@ export default compose(
version,
}) => type => id => e => {
e.preventDefault()
deleteFile(id)
const newFiles = {
...files,
[type]: files[type].filter(f => f.id !== id),
}
setFiles(newFiles)
changeForm('wizard', 'files', files)
deleteFile(id, type)
.then(() => {
const newFiles = {
...files,
[type]: files[type].filter(f => f.id !== id),
}
setFiles(newFiles)
changeForm('wizard', 'files', newFiles)
})
.catch(e => console.error(`Couldn't delete file.`, e))
},
}),
withContext(
......
......@@ -80,14 +80,17 @@ export const uploadFile = (file, type, fragmentId) => dispatch => {
)
}
export const deleteFile = fileId => dispatch => {
dispatch(removeRequest())
export const deleteFile = (fileId, type = 'manuscripts') => dispatch => {
dispatch(removeRequest(type))
return remove(`/files/${fileId}`)
.then(r => {
dispatch(removeSuccess())
return r
})
.catch(err => dispatch(removeFailure(err.message)))
.catch(err => {
dispatch(removeFailure(err.message))
throw err
})
}
export const getSignedUrl = fileId => dispatch => get(`/files/${fileId}`)
......@@ -95,6 +98,7 @@ export const getSignedUrl = fileId => dispatch => get(`/files/${fileId}`)
// reducer
export default (state = initialState, action) => {
switch (action.type) {
case REMOVE_REQUEST:
case UPLOAD_REQUEST:
return {
...state,
......@@ -105,12 +109,14 @@ export default (state = initialState, action) => {
},
}
case UPLOAD_FAILURE:
case REMOVE_FAILURE:
return {
...state,
isFetching: initialState.isFetching,
error: action.error,
}
case UPLOAD_SUCCESS:
case REMOVE_SUCCESS:
return {
...state,
isFetching: initialState.isFetching,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment