mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 17:21:41 +10:00
chore: wip
This commit is contained in:
@ -1,67 +0,0 @@
|
|||||||
'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,22 +23,3 @@ export async function search({ search, page, perPage, sortBy, sortOrder }: Searc
|
|||||||
|
|
||||||
return results;
|
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,7 +5,6 @@ import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-
|
|||||||
import { isAdmin } from '@documenso/lib/next-auth/guards/is-admin';
|
import { isAdmin } from '@documenso/lib/next-auth/guards/is-admin';
|
||||||
|
|
||||||
import { LeaderboardTable, type SigningVolume } from './data-table-leaderboard';
|
import { LeaderboardTable, type SigningVolume } from './data-table-leaderboard';
|
||||||
import { DownloadButton } from './download-button';
|
|
||||||
import { search } from './fetch-leaderboard.actions';
|
import { search } from './fetch-leaderboard.actions';
|
||||||
|
|
||||||
type AdminLeaderboardProps = {
|
type AdminLeaderboardProps = {
|
||||||
@ -53,8 +52,6 @@ export default async function Leaderboard({ searchParams = {} }: AdminLeaderboar
|
|||||||
<h2 className="text-4xl font-semibold">
|
<h2 className="text-4xl font-semibold">
|
||||||
<Trans>Signing Volume</Trans>
|
<Trans>Signing Volume</Trans>
|
||||||
</h2>
|
</h2>
|
||||||
{/* TODO: remove */}
|
|
||||||
<DownloadButton />
|
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-8">
|
<div className="mt-8">
|
||||||
<LeaderboardTable
|
<LeaderboardTable
|
||||||
|
|||||||
Reference in New Issue
Block a user