-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CM-983: added downloading template file for upload (#90)
- Loading branch information
1 parent
61bfe4b
commit 481bfde
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { baseApiUrl } from '@openimis/fe-core'; | ||
|
||
export default function downloadTemplate() { | ||
const url = new URL( | ||
`${window.location.origin}${baseApiUrl}/individual/download_template_file/`, | ||
); | ||
|
||
fetch(url) | ||
.then((response) => response.blob()) | ||
.then((blob) => { | ||
const link = document.createElement('a'); | ||
link.href = URL.createObjectURL(blob); | ||
link.download = 'individual_upload_template.csv'; | ||
document.body.appendChild(link); | ||
link.click(); | ||
document.body.removeChild(link); | ||
}) | ||
.catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.error('Export failed, reason: ', error); | ||
}); | ||
} |