-
Notifications
You must be signed in to change notification settings - Fork 161
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 #988 from MaiCVCR/fix-978
Fix: New Download quest users button
- Loading branch information
Showing
5 changed files
with
73 additions
and
2 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
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 QuestUsersButtonProps = { | ||
questId: string; | ||
}; | ||
|
||
const DownloadQuestUsersButton: React.FC<QuestUsersButtonProps> = ({ questId }) => { | ||
const { showNotification } = useNotification(); | ||
|
||
const handleDownload = async () => { | ||
try { | ||
const data = await AdminService.getQuestUsersByQuestId({ id: Number(questId) }); | ||
|
||
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 = `quest_${questId}_users.json`; | ||
a.click(); | ||
URL.revokeObjectURL(url); | ||
} catch (error) { | ||
console.error("Error downloading quest users:", error); | ||
showNotification("Failed to download quest users.", "error"); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button onClick={handleDownload}> | ||
<p>Download quest users</p> | ||
</Button> | ||
); | ||
}; | ||
|
||
export default DownloadQuestUsersButton; |
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