Skip to content

Commit

Permalink
fixed issue with uploading attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
bologer committed Mar 28, 2020
1 parent 820292c commit efa07d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions reactjs/src/core/comment/CommentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export function uploadAttachment(attachments, entropy) {
};
},
failure: {type: COMMENT_ATTACHMENT_UPLOAD_FAILURE, payload: {entropy}},
always: {type: COMMENT_ATTACHMENT_UPLOAD_INVALIDATE, payload: {entropy}},
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion reactjs/src/core/comment/commentReducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default function (state = DEFAULT_STATE, action) {
...state,
attachmentUpload: {
...state.attachmentUpload,
[action.payload.entropy]: {isFetching: true}
[action.payload.entropy]: {isFetching: true},
},
};
case COMMENT_ATTACHMENT_UPLOAD_SUCCESS:
Expand Down
26 changes: 13 additions & 13 deletions reactjs/src/core/comment/form/SendCommentFormBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ export default function SendCommentFormBody({
const attachmentEntropy = comment && comment.id || 'default';

useEffect(() => {
manageReducer({
reducer: attachmentUpload[attachmentEntropy],
onSuccess: (response) => {
if (response) {
const files = response.files;

const attachmentReducer = attachmentUpload[attachmentEntropy] || undefined;

if (attachmentReducer && !attachmentReducer.isFetching) {
const {payload: response} = attachmentReducer;
if (response) {
const files = response.files || undefined;

if (files) {
if (!attachments || !attachments.length) {
handleAttachmentChange(files);
} else {
let newAttachments: [] = attachments;
response.files.forEach(item => {
files.forEach(item => {
newAttachments.push(item);
});
handleAttachmentChange(newAttachments);
}

batch(() => {
dispatch(invalidateAttachmentUpload(attachmentEntropy))
dispatch(successSnackbar(settings.i18.file_uploaded));
});
}
},
});

dispatch(successSnackbar(settings.i18.file_uploaded));
}
}
}, [attachmentUpload[attachmentEntropy]]);

/**
Expand Down

0 comments on commit efa07d0

Please sign in to comment.