Skip to content

Instantly share code, notes, and snippets.

@fakiolinho
Last active May 12, 2018 09:05
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/3d5100028183744051d3373865446eb0 to your computer and use it in GitHub Desktop.
Save fakiolinho/3d5100028183744051d3373865446eb0 to your computer and use it in GitHub Desktop.
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