| // src/components/admin/AdminExportButton.tsx | |
| import { Download } from "lucide-react"; | |
| import { toast } from "react-toastify"; | |
| import api from "@/lib/api"; | |
| import { useState } from "react"; | |
| export function AdminExportButton() { | |
| const [loading, setLoading] = useState(false); | |
| const handleExport = async () => { | |
| setLoading(true); | |
| try { | |
| const response = await api.get("/admin/export/all", { | |
| responseType: "blob", | |
| }); | |
| const blob = new Blob([response.data], { type: "application/zip" }); | |
| const url = window.URL.createObjectURL(blob); | |
| const a = document.createElement("a"); | |
| a.href = url; | |
| a.download = `admin-all-data-export-${new Date().toISOString().split('T')[0]}.zip`; | |
| a.click(); | |
| window.URL.revokeObjectURL(url); | |
| toast.success("All data exported successfully as ZIP"); | |
| } catch (error) { | |
| console.error(error); | |
| toast.error("Export failed. Please check permissions."); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| return ( | |
| <button | |
| onClick={handleExport} | |
| disabled={loading} | |
| className="inline-flex items-center gap-2 px-4 py-2 bg-gradient-to-r from-primary to-primary/80 hover:from-primary/95 hover:to-primary/75 text-white rounded-lg transition duration-200 shadow-md shadow-primary/20 disabled:opacity-50" | |
| > | |
| <Download className={`w-4 h-4 ${loading ? "animate-bounce" : ""}`} /> | |
| {loading ? "Exporting..." : "Export All"} | |
| </button> | |
| ); | |
| } |
Xet Storage Details
- Size:
- 1.48 kB
- Xet hash:
- 71c3d9cf7323f1f22707853d2671d08f9f0fc3c16283bb580047e4813a017d37
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.