Last active
May 12, 2018 09:05
-
-
Save fakiolinho/3d5100028183744051d3373865446eb0 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 fileSaver from 'utils/fileSaver'; | |
import { downloadFileRequest } from './api'; | |
import * as types from './actionTypes'; | |
export const downloadFile = id => async dispatch => { | |
try { | |
dispatch({ | |
type: types.DOWNLOAD_FILE_REQUEST, | |
}); | |
const { data } = await downloadFileRequest(id); | |
await fileSaver(data, 'fileName.txt'); | |
dispatch({ | |
type: types.DOWNLOAD_FILE_SUCCESS, | |
}); | |
alert('File downloaded successfully!'); | |
} catch (error) { | |
dispatch({ | |
type: types.DOWNLOAD_FILE_ERROR, | |
}); | |
if (error.response) { | |
alert(error.response.data.message); | |
} else { | |
alert('Something went wrong while downloading this file'); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment