Last active
May 12, 2018 08:20
-
-
Save fakiolinho/c2b431b37e97de9cfd16a3b3d49812e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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