mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 16:51:38 +10:00
chore: wip
This commit is contained in:
@ -0,0 +1,67 @@
|
||||
'use client';
|
||||
|
||||
// delete
|
||||
import { useState } from 'react';
|
||||
|
||||
import { Trans } from '@lingui/macro';
|
||||
import { Download } from 'lucide-react';
|
||||
|
||||
import { Button } from '@documenso/ui/primitives/button';
|
||||
|
||||
import { downloadLeaderboardData } from './fetch-leaderboard.actions';
|
||||
|
||||
export const DownloadButton = () => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const handleDownload = async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
|
||||
const data = await downloadLeaderboardData();
|
||||
|
||||
// Create a blob with the data
|
||||
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
||||
|
||||
// Create a URL for the blob
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
// Create a temporary anchor element
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `leaderboard-data-${new Date().toISOString().split('T')[0]}.json`;
|
||||
|
||||
// Trigger the download
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Clean up
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (error) {
|
||||
console.error('Error downloading data:', error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleDownload}
|
||||
disabled={isLoading}
|
||||
className="ml-2"
|
||||
>
|
||||
{isLoading ? (
|
||||
<span className="flex items-center gap-x-2">
|
||||
<Trans>Downloading...</Trans>
|
||||
</span>
|
||||
) : (
|
||||
<span className="flex items-center gap-x-2">
|
||||
<Download className="h-4 w-4" />
|
||||
<Trans>Download</Trans>
|
||||
</span>
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
@ -23,3 +23,22 @@ export async function search({ search, page, perPage, sortBy, sortOrder }: Searc
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
// delete
|
||||
export async function downloadLeaderboardData() {
|
||||
const { user } = await getRequiredServerComponentSession();
|
||||
|
||||
if (!isAdmin(user)) {
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
const results = await getSigningVolume({
|
||||
search: '',
|
||||
page: 1,
|
||||
perPage: 1000,
|
||||
sortBy: 'signingVolume',
|
||||
sortOrder: 'desc',
|
||||
});
|
||||
|
||||
return results.leaderboard;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-
|
||||
import { isAdmin } from '@documenso/lib/next-auth/guards/is-admin';
|
||||
|
||||
import { LeaderboardTable, type SigningVolume } from './data-table-leaderboard';
|
||||
import { DownloadButton } from './download-button';
|
||||
import { search } from './fetch-leaderboard.actions';
|
||||
|
||||
type AdminLeaderboardProps = {
|
||||
@ -48,9 +49,13 @@ export default async function Leaderboard({ searchParams = {} }: AdminLeaderboar
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2 className="text-4xl font-semibold">
|
||||
<Trans>Signing Volume</Trans>
|
||||
</h2>
|
||||
<div className="flex items-center">
|
||||
<h2 className="text-4xl font-semibold">
|
||||
<Trans>Signing Volume</Trans>
|
||||
</h2>
|
||||
{/* TODO: remove */}
|
||||
<DownloadButton />
|
||||
</div>
|
||||
<div className="mt-8">
|
||||
<LeaderboardTable
|
||||
signingVolume={typedSigningVolume}
|
||||
|
||||
Reference in New Issue
Block a user