2024-03-06 08:54:36 +00:00
|
|
|
import { ReactElement, useState } from "react";
|
|
|
|
import { observer } from "mobx-react";
|
2024-03-06 13:09:14 +00:00
|
|
|
import { useRouter } from "next/router";
|
2024-03-06 08:54:36 +00:00
|
|
|
// hooks
|
2024-03-06 13:09:14 +00:00
|
|
|
import { Button } from "@plane/ui";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { UserProfileHeader } from "@/components/headers";
|
|
|
|
import { DownloadActivityButton, WorkspaceActivityListPage } from "@/components/profile";
|
|
|
|
import { EUserWorkspaceRoles } from "@/constants/workspace";
|
|
|
|
import { useUser } from "@/hooks/store";
|
2024-03-06 08:54:36 +00:00
|
|
|
// layouts
|
2024-03-19 14:38:35 +00:00
|
|
|
import { AppLayout } from "@/layouts/app-layout";
|
|
|
|
import { ProfileAuthWrapper } from "@/layouts/user-profile-layout";
|
2024-03-06 08:54:36 +00:00
|
|
|
// components
|
|
|
|
// ui
|
|
|
|
// types
|
2024-03-19 14:38:35 +00:00
|
|
|
import { NextPageWithLayout } from "@/lib/types";
|
2024-03-06 08:54:36 +00:00
|
|
|
// constants
|
|
|
|
|
|
|
|
const PER_PAGE = 100;
|
|
|
|
|
|
|
|
const ProfileActivityPage: NextPageWithLayout = observer(() => {
|
|
|
|
// states
|
|
|
|
const [pageCount, setPageCount] = useState(1);
|
|
|
|
const [totalPages, setTotalPages] = useState(0);
|
|
|
|
const [resultsCount, setResultsCount] = useState(0);
|
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { userId } = router.query;
|
|
|
|
// store hooks
|
2024-05-08 17:31:20 +00:00
|
|
|
const { data: currentUser } = useUser();
|
2024-03-06 08:54:36 +00:00
|
|
|
const {
|
|
|
|
membership: { currentWorkspaceRole },
|
|
|
|
} = useUser();
|
|
|
|
|
|
|
|
const updateTotalPages = (count: number) => setTotalPages(count);
|
|
|
|
|
|
|
|
const updateResultsCount = (count: number) => setResultsCount(count);
|
|
|
|
|
|
|
|
const handleLoadMore = () => setPageCount((prev) => prev + 1);
|
|
|
|
|
|
|
|
const activityPages: JSX.Element[] = [];
|
|
|
|
for (let i = 0; i < pageCount; i++)
|
|
|
|
activityPages.push(
|
|
|
|
<WorkspaceActivityListPage
|
|
|
|
key={i}
|
|
|
|
cursor={`${PER_PAGE}:${i}:0`}
|
|
|
|
perPage={PER_PAGE}
|
|
|
|
updateResultsCount={updateResultsCount}
|
|
|
|
updateTotalPages={updateTotalPages}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const canDownloadActivity =
|
|
|
|
currentUser?.id === userId && !!currentWorkspaceRole && currentWorkspaceRole >= EUserWorkspaceRoles.MEMBER;
|
|
|
|
|
|
|
|
return (
|
2024-05-08 17:31:20 +00:00
|
|
|
<div className="flex h-full w-full flex-col overflow-hidden py-5">
|
2024-03-15 11:59:46 +00:00
|
|
|
<div className="flex items-center justify-between gap-2 px-5 md:px-9">
|
2024-03-06 08:54:36 +00:00
|
|
|
<h3 className="text-lg font-medium">Recent activity</h3>
|
|
|
|
{canDownloadActivity && <DownloadActivityButton />}
|
|
|
|
</div>
|
2024-05-08 17:31:20 +00:00
|
|
|
<div className="vertical-scrollbar scrollbar-md flex h-full flex-col overflow-y-auto px-5 md:px-9">
|
2024-03-06 08:54:36 +00:00
|
|
|
{activityPages}
|
|
|
|
{pageCount < totalPages && resultsCount !== 0 && (
|
2024-05-08 17:31:20 +00:00
|
|
|
<div className="flex w-full items-center justify-center text-xs">
|
2024-03-06 08:54:36 +00:00
|
|
|
<Button variant="accent-primary" size="sm" onClick={handleLoadMore}>
|
|
|
|
Load more
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
ProfileActivityPage.getLayout = function getLayout(page: ReactElement) {
|
|
|
|
return (
|
|
|
|
<AppLayout header={<UserProfileHeader type="Activity" />}>
|
|
|
|
<ProfileAuthWrapper>{page}</ProfileAuthWrapper>
|
|
|
|
</AppLayout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProfileActivityPage;
|