forked from github/plane
5a32d10f96
* chore: replaced marimekko graph with a bar graph * chore: add bar onClick handler * chore: custom date filter for widgets * style: priority graph * chore: workspace profile activity pagination * chore: profile activity pagination * chore: user profile activity pagination * chore: workspace user activity csv download * chore: download activity button added * chore: workspace user pagination * chore: collabrator pagination * chore: field change * chore: recent collaborators pagination * chore: changed the collabrators * chore: collabrators list changed * fix: distinct users * chore: search filter in collaborators * fix: import error * chore: update priority graph x-axis values * chore: admin and member request validation * chore: update csv download request method * chore: search implementation for the collaborators widget * refactor: priority distribution card * chore: add enum for duration filters * chore: update inbox types * chore: add todos for refactoring --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { useState } from "react";
|
|
import { useRouter } from "next/router";
|
|
// services
|
|
import { UserService } from "services/user.service";
|
|
// ui
|
|
import { Button } from "@plane/ui";
|
|
// helpers
|
|
import { renderFormattedPayloadDate } from "helpers/date-time.helper";
|
|
|
|
const userService = new UserService();
|
|
|
|
export const DownloadActivityButton = () => {
|
|
// states
|
|
const [isDownloading, setIsDownloading] = useState(false);
|
|
// router
|
|
const router = useRouter();
|
|
const { workspaceSlug, userId } = router.query;
|
|
|
|
const handleDownload = async () => {
|
|
const today = renderFormattedPayloadDate(new Date());
|
|
|
|
if (!workspaceSlug || !userId || !today) return;
|
|
|
|
setIsDownloading(true);
|
|
|
|
const csv = await userService
|
|
.downloadProfileActivity(workspaceSlug.toString(), userId.toString(), {
|
|
date: today,
|
|
})
|
|
.finally(() => setIsDownloading(false));
|
|
|
|
// create a Blob object
|
|
const blob = new Blob([csv], { type: "text/csv" });
|
|
|
|
// create URL for the Blob object
|
|
const url = window.URL.createObjectURL(blob);
|
|
|
|
// create a link element
|
|
const a = document.createElement("a");
|
|
a.href = url;
|
|
a.download = `profile-activity-${Date.now()}.csv`;
|
|
document.body.appendChild(a);
|
|
|
|
// simulate click on the link element to trigger download
|
|
a.click();
|
|
|
|
// cleanup
|
|
window.URL.revokeObjectURL(url);
|
|
document.body.removeChild(a);
|
|
};
|
|
|
|
return (
|
|
<Button onClick={handleDownload} loading={isDownloading}>
|
|
{isDownloading ? "Downloading" : "Download today's activity"}
|
|
</Button>
|
|
);
|
|
};
|