-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #992 from gadyrcdz/fix-#980
Fix: Add reusable component for downloading boost winners using authS…
- Loading branch information
Showing
5 changed files
with
73 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react"; | ||
import Button from "@components/UI/button"; | ||
import { useNotification } from "@context/NotificationProvider"; | ||
import { AdminService } from '@services/authService'; | ||
|
||
type DownloadBoostWinnersButtonProps = { | ||
boostId: string; | ||
}; | ||
|
||
const DownloadBoostWinnersButton: React.FC<DownloadBoostWinnersButtonProps> = ({ boostId }) => { | ||
const { showNotification } = useNotification(); | ||
|
||
const handleDownload = async () => { | ||
try { | ||
const data = await AdminService.getBoostWinnersByBoostId({ id: Number(boostId) }); | ||
|
||
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" }); | ||
const url = URL.createObjectURL(blob); | ||
const a = document.createElement("a"); | ||
a.href = url; | ||
a.download = `boost_${boostId}_winners.json`; | ||
a.click(); | ||
URL.revokeObjectURL(url); | ||
} catch (error) { | ||
console.error("Error downloading boost winners:", error); | ||
showNotification("Failed to download boost winners.", "error"); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button onClick={handleDownload}> | ||
<p>Download boost winners</p> | ||
</Button> | ||
); | ||
}; | ||
|
||
export default DownloadBoostWinnersButton; |
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