From 8994d1b3b14d6a997930662284c90bd1e4b64967 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Thu, 29 Aug 2024 16:38:38 +0600 Subject: [PATCH] wip: team activity --- src/components/Dashboard/DashboardPage.tsx | 2 + .../Dashboard/PersonalDashboard.tsx | 1 + src/components/Dashboard/TeamDashboard.tsx | 177 ++++++++++++++++++ .../TeamActivity/TeamActivityPage.tsx | 9 +- 4 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 src/components/Dashboard/TeamDashboard.tsx diff --git a/src/components/Dashboard/DashboardPage.tsx b/src/components/Dashboard/DashboardPage.tsx index c1cc27a1c..11f100cf3 100644 --- a/src/components/Dashboard/DashboardPage.tsx +++ b/src/components/Dashboard/DashboardPage.tsx @@ -6,6 +6,7 @@ import { $teamList } from '../../stores/team'; import type { TeamListResponse } from '../TeamDropdown/TeamDropdown'; import { DashboardTab } from './DashboardTab'; import { PersonalDashboard } from './PersonalDashboard'; +import { TeamDashboard } from './TeamDashboard'; type DashboardPageProps = {}; @@ -73,6 +74,7 @@ export function DashboardPage(props: DashboardPageProps) { {!selectedTeamId && } + {selectedTeamId && } ); } diff --git a/src/components/Dashboard/PersonalDashboard.tsx b/src/components/Dashboard/PersonalDashboard.tsx index 4457005c3..f8f100aa6 100644 --- a/src/components/Dashboard/PersonalDashboard.tsx +++ b/src/components/Dashboard/PersonalDashboard.tsx @@ -119,6 +119,7 @@ export function PersonalDashboard(props: PersonalDashboardProps) { updatedAt={roadmap.updatedAt} title={roadmap.resourceTitle} showActions={false} + roadmapSlug={roadmap.roadmapSlug} /> ); })} diff --git a/src/components/Dashboard/TeamDashboard.tsx b/src/components/Dashboard/TeamDashboard.tsx new file mode 100644 index 000000000..4c36c51e9 --- /dev/null +++ b/src/components/Dashboard/TeamDashboard.tsx @@ -0,0 +1,177 @@ +import { useEffect, useState } from 'react'; +import type { TeamMember } from '../TeamProgress/TeamProgressPage'; +import { httpGet } from '../../lib/http'; +import { useToast } from '../../hooks/use-toast'; +import { getUser } from '../../lib/jwt'; +import { LoadingProgress } from './LoadingProgress'; +import { ResourceProgress } from '../Activity/ResourceProgress'; +import { Plus, Minus } from 'lucide-react'; +import { TeamActivityPage } from '../TeamActivity/TeamActivityPage'; +import { cn } from '../../lib/classname'; + +type TeamDashboardProps = { + teamId: string; +}; + +export function TeamDashboard(props: TeamDashboardProps) { + const { teamId } = props; + + const toast = useToast(); + const currentUser = getUser(); + + const [isLoading, setIsLoading] = useState(true); + const [teamMembers, setTeamMembers] = useState([]); + const [showAllMembers, setShowAllMembers] = useState(false); + + async function getTeamProgress() { + const { response, error } = await httpGet( + `${import.meta.env.PUBLIC_API_URL}/v1-get-team-progress/${teamId}`, + ); + if (error || !response) { + toast.error(error?.message || 'Failed to get team progress'); + return; + } + + setTeamMembers( + response.sort((a, b) => { + if (a.email === currentUser?.email) { + return -1; + } + if (b.email === currentUser?.email) { + return 1; + } + return 0; + }), + ); + } + + useEffect(() => { + if (!teamId) { + return; + } + + getTeamProgress().finally(() => setIsLoading(false)); + }, [teamId]); + + if (!currentUser) { + return null; + } + + const currentMember = teamMembers.find( + (member) => member.email === currentUser.email, + ); + const learningRoadmapsToShow = + currentMember?.progress?.filter( + (progress) => progress.resourceType === 'roadmap', + ) || []; + + const allMembersWithoutCurrentUser = teamMembers + .sort((a, b) => { + if (a.email === currentUser.email) { + return -1; + } + + if (b.email === currentUser.email) { + return 1; + } + + return 0; + }) + .slice(0, showAllMembers ? teamMembers.length : 15); + + return ( +
+

Roadmaps

+ {isLoading && } + {!isLoading && learningRoadmapsToShow.length > 0 && ( +
+ {learningRoadmapsToShow.map((roadmap) => { + const learningCount = roadmap.learning || 0; + const doneCount = roadmap.done || 0; + const totalCount = roadmap.total || 0; + const skippedCount = roadmap.skipped || 0; + + return ( + totalCount ? totalCount : doneCount} + learningCount={ + learningCount > totalCount ? totalCount : learningCount + } + totalCount={totalCount} + skippedCount={skippedCount} + resourceId={roadmap.resourceId} + resourceType="roadmap" + updatedAt={roadmap.updatedAt} + title={roadmap.resourceTitle} + showActions={false} + roadmapSlug={roadmap.roadmapSlug} + /> + ); + })} +
+ )} + +

+ Team Members +

+ {isLoading && } + {!isLoading && ( +
+ {allMembersWithoutCurrentUser.map((member) => { + const avatar = member?.avatar + ? `${import.meta.env.PUBLIC_AVATAR_BASE_URL}/${member.avatar}` + : '/images/default-avatar.png'; + return ( +
+ {member.name +
{member.name}
+
+ ); + })} + {teamMembers.length > 0 && ( + + )} +
+ )} + + +
+ ); +} + +type TeamMemberLoadingProps = { + className?: string; +}; + +function TeamMemberLoading(props: TeamMemberLoadingProps) { + const { className } = props; + + return ( +
+ {Array.from({ length: 8 }).map((_, index) => ( +
+ ))} +
+ ); +} diff --git a/src/components/TeamActivity/TeamActivityPage.tsx b/src/components/TeamActivity/TeamActivityPage.tsx index b8d6b9657..de97a7b6d 100644 --- a/src/components/TeamActivity/TeamActivityPage.tsx +++ b/src/components/TeamActivity/TeamActivityPage.tsx @@ -49,8 +49,13 @@ type GetTeamActivityResponse = { perPage: number; }; -export function TeamActivityPage() { - const { t: teamId } = getUrlParams(); +type TeamActivityPageProps = { + teamId?: string; +}; + +export function TeamActivityPage(props: TeamActivityPageProps) { + const { teamId: defaultTeamId } = props; + const { t: teamId = defaultTeamId } = getUrlParams(); const toast = useToast();