Skip to content

Instantly share code, notes, and snippets.

@fakiolinho
Last active May 12, 2018 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakiolinho/c2b431b37e97de9cfd16a3b3d49812e9 to your computer and use it in GitHub Desktop.
Save fakiolinho/c2b431b37e97de9cfd16a3b3d49812e9 to your computer and use it in GitHub Desktop.
import { uploadFileRequest } from './api';
import * as types from './actionTypes';
export const uploadFile = data => async dispatch => {
try {
dispatch({
type: types.UPLOAD_FILE_REQUEST,
});
await uploadFileRequest(data);
dispatch({
type: types.UPLOAD_FILE_SUCCESS,
});
alert('File uploaded successfully!');
} catch (error) {
dispatch({
type: types.UPLOAD_FILE_ERROR,
});
if (error.response) {
alert(error.response.data.message);
} else {
alert('Something went wrong while uploading this file');
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment