feat: separate team dashboard page

feat/team-dashboard
Arik Chakma 5 months ago
parent b605de005f
commit 56a038363e
  1. 4
      src/components/CreateTeam/SelectRoadmapModal.tsx
  2. 29
      src/components/Dashboard/DashboardPage.tsx
  3. 4
      src/components/Dashboard/DashboardTeamRoadmaps.tsx
  4. 20
      src/components/Dashboard/TeamDashboard.tsx
  5. 77
      src/pages/team/index.astro

@ -26,10 +26,6 @@ export function SelectRoadmapModal(props: SelectRoadmapModalProps) {
const popupBodyEl = useRef<HTMLDivElement>(null); const popupBodyEl = useRef<HTMLDivElement>(null);
const searchInputEl = useRef<HTMLInputElement>(null); const searchInputEl = useRef<HTMLInputElement>(null);
console.log('-'.repeat(20));
console.log(allRoadmaps);
console.log('-'.repeat(20));
const [searchResults, setSearchResults] = useState<PageType[]>(allRoadmaps); const [searchResults, setSearchResults] = useState<PageType[]>(allRoadmaps);
const [searchText, setSearchText] = useState(''); const [searchText, setSearchText] = useState('');

@ -8,18 +8,22 @@ import { DashboardTab } from './DashboardTab';
import { PersonalDashboard, type BuiltInRoadmap } from './PersonalDashboard'; import { PersonalDashboard, type BuiltInRoadmap } from './PersonalDashboard';
import { TeamDashboard } from './TeamDashboard'; import { TeamDashboard } from './TeamDashboard';
import { getUser } from '../../lib/jwt'; import { getUser } from '../../lib/jwt';
import { deleteUrlParam, getUrlParams, setUrlParams } from '../../lib/browser';
import { useParams } from '../../hooks/use-params'; import { useParams } from '../../hooks/use-params';
type DashboardPageProps = { type DashboardPageProps = {
builtInRoleRoadmaps?: BuiltInRoadmap[]; builtInRoleRoadmaps?: BuiltInRoadmap[];
builtInSkillRoadmaps?: BuiltInRoadmap[]; builtInSkillRoadmaps?: BuiltInRoadmap[];
builtInBestPractices?: BuiltInRoadmap[]; builtInBestPractices?: BuiltInRoadmap[];
isTeamPage?: boolean;
}; };
export function DashboardPage(props: DashboardPageProps) { export function DashboardPage(props: DashboardPageProps) {
const { builtInRoleRoadmaps, builtInBestPractices, builtInSkillRoadmaps } = const {
props; builtInRoleRoadmaps,
builtInBestPractices,
builtInSkillRoadmaps,
isTeamPage = false,
} = props;
const currentUser = getUser(); const currentUser = getUser();
const toast = useToast(); const toast = useToast();
@ -67,11 +71,8 @@ export function DashboardPage(props: DashboardPageProps) {
<div className="mb-6 flex flex-wrap items-center gap-1.5 sm:mb-8"> <div className="mb-6 flex flex-wrap items-center gap-1.5 sm:mb-8">
<DashboardTab <DashboardTab
label="Personal" label="Personal"
isActive={!selectedTeamId} isActive={!selectedTeamId && !isTeamPage}
onClick={() => { href="/dashboard"
setSelectedTeamId(undefined);
deleteUrlParam('t');
}}
avatar={userAvatar} avatar={userAvatar}
/> />
@ -99,10 +100,7 @@ export function DashboardPage(props: DashboardPageProps) {
href: `/respond-invite?i=${team.memberId}`, href: `/respond-invite?i=${team.memberId}`,
} }
: { : {
onClick: () => { href: `/team?t=${team._id}`,
setSelectedTeamId(team._id);
setUrlParams({ t: team._id });
},
})} })}
avatar={avatarUrl} avatar={avatarUrl}
/> />
@ -118,18 +116,19 @@ export function DashboardPage(props: DashboardPageProps) {
)} )}
</div> </div>
{!selectedTeamId && ( {!selectedTeamId && !isTeamPage && (
<PersonalDashboard <PersonalDashboard
builtInRoleRoadmaps={builtInRoleRoadmaps} builtInRoleRoadmaps={builtInRoleRoadmaps}
builtInSkillRoadmaps={builtInSkillRoadmaps} builtInSkillRoadmaps={builtInSkillRoadmaps}
builtInBestPractices={builtInBestPractices} builtInBestPractices={builtInBestPractices}
/> />
)} )}
{selectedTeamId && (
{(selectedTeamId || isTeamPage) && (
<TeamDashboard <TeamDashboard
builtInRoleRoadmaps={builtInRoleRoadmaps!} builtInRoleRoadmaps={builtInRoleRoadmaps!}
builtInSkillRoadmaps={builtInSkillRoadmaps!} builtInSkillRoadmaps={builtInSkillRoadmaps!}
teamId={selectedTeamId} teamId={selectedTeamId!}
/> />
)} )}
</div> </div>

@ -60,8 +60,6 @@ export function DashboardTeamRoadmaps(props: DashboardTeamRoadmapsProps) {
[builtInRoleRoadmaps, builtInSkillRoadmaps], [builtInRoleRoadmaps, builtInSkillRoadmaps],
); );
console.log(allRoadmaps);
async function onAdd(roadmapId: string, shouldCopyContent = false) { async function onAdd(roadmapId: string, shouldCopyContent = false) {
if (!teamId) { if (!teamId) {
return; return;
@ -272,7 +270,7 @@ export function DashboardTeamRoadmaps(props: DashboardTeamRoadmapsProps) {
{canManageCurrentTeam && ( {canManageCurrentTeam && (
<button <button
onClick={() => setIsAddingRoadmap(true)} onClick={() => setIsPickingOptions(true)}
className="group relative flex w-full items-center justify-center overflow-hidden rounded-md border border-dashed border-gray-300 bg-white px-3 py-2 text-center text-sm text-gray-500 transition-all hover:border-gray-400 hover:text-black" className="group relative flex w-full items-center justify-center overflow-hidden rounded-md border border-dashed border-gray-300 bg-white px-3 py-2 text-center text-sm text-gray-500 transition-all hover:border-gray-400 hover:text-black"
> >
+ Add Roadmap + Add Roadmap

@ -62,12 +62,8 @@ export function TeamDashboard(props: TeamDashboardProps) {
getTeamProgress().finally(() => setIsLoading(false)); getTeamProgress().finally(() => setIsLoading(false));
}, [teamId]); }, [teamId]);
if (!currentUser) {
return null;
}
const currentMember = teamMembers.find( const currentMember = teamMembers.find(
(member) => member.email === currentUser.email, (member) => member.email === currentUser?.email,
); );
const learningRoadmapsToShow = const learningRoadmapsToShow =
currentMember?.progress?.filter( currentMember?.progress?.filter(
@ -75,11 +71,11 @@ export function TeamDashboard(props: TeamDashboardProps) {
) || []; ) || [];
const allMembersWithoutCurrentUser = teamMembers.sort((a, b) => { const allMembersWithoutCurrentUser = teamMembers.sort((a, b) => {
if (a.email === currentUser.email) { if (a.email === currentUser?.email) {
return -1; return -1;
} }
if (b.email === currentUser.email) { if (b.email === currentUser?.email) {
return 1; return 1;
} }
@ -126,7 +122,11 @@ export function TeamDashboard(props: TeamDashboardProps) {
? `${import.meta.env.PUBLIC_AVATAR_BASE_URL}/${member.avatar}` ? `${import.meta.env.PUBLIC_AVATAR_BASE_URL}/${member.avatar}`
: '/images/default-avatar.png'; : '/images/default-avatar.png';
return ( return (
<span className="group relative" key={member.email}> <a
className="group relative"
key={member.email}
href={`/team/member?t=${teamId}&m=${member._id}`}
>
<figure className="relative aspect-square size-8 overflow-hidden rounded-md bg-gray-100"> <figure className="relative aspect-square size-8 overflow-hidden rounded-md bg-gray-100">
<img <img
src={avatar} src={avatar}
@ -137,7 +137,7 @@ export function TeamDashboard(props: TeamDashboardProps) {
<Tooltip position="top-center" additionalClass="text-sm"> <Tooltip position="top-center" additionalClass="text-sm">
{member.name} {member.name}
</Tooltip> </Tooltip>
</span> </a>
); );
})} })}
@ -157,7 +157,7 @@ export function TeamDashboard(props: TeamDashboardProps) {
</div> </div>
)} )}
<TeamActivityPage teamId={teamId} /> {!isLoading && <TeamActivityPage teamId={teamId} />}
</section> </section>
); );
} }

@ -1,15 +1,68 @@
--- ---
import AccountSidebar from '../../components/AccountSidebar.astro'; import { DashboardPage } from '../../components/Dashboard/DashboardPage';
import { TeamsList } from '../../components/TeamsList'; import BaseLayout from '../../layouts/BaseLayout.astro';
import AccountLayout from '../../layouts/AccountLayout.astro'; import { getAllBestPractices } from '../../lib/best-practice';
import { getRoadmapsByTag } from '../../lib/roadmap';
const roleRoadmaps = await getRoadmapsByTag('role-roadmap');
const skillRoadmaps = await getRoadmapsByTag('skill-roadmap');
const bestPractices = await getAllBestPractices();
const enrichedRoleRoadmaps = roleRoadmaps
.filter((roadmapItem) => !roadmapItem.frontmatter.isHidden)
.map((roadmap) => {
const { frontmatter } = roadmap;
return {
id: roadmap.id,
url: `/${roadmap.id}`,
title: frontmatter.briefTitle,
description: frontmatter.briefDescription,
relatedRoadmapIds: frontmatter.relatedRoadmaps,
renderer: frontmatter.renderer,
metadata: {
tags: frontmatter.tags,
},
};
});
const enrichedSkillRoadmaps = skillRoadmaps
.filter((roadmapItem) => !roadmapItem.frontmatter.isHidden)
.map((roadmap) => {
const { frontmatter } = roadmap;
return {
id: roadmap.id,
url: `/${roadmap.id}`,
title:
frontmatter.briefTitle === 'Go' ? 'Go Roadmap' : frontmatter.briefTitle,
description: frontmatter.briefDescription,
relatedRoadmapIds: frontmatter.relatedRoadmaps,
renderer: frontmatter.renderer,
metadata: {
tags: frontmatter.tags,
},
};
});
const enrichedBestPractices = bestPractices.map((bestPractice) => {
const { frontmatter } = bestPractice;
return {
id: bestPractice.id,
url: `/best-practices/${bestPractice.id}`,
title: frontmatter.briefTitle,
description: frontmatter.briefDescription,
};
});
--- ---
<AccountLayout <BaseLayout title='Dashboard' noIndex={true}>
title='Update Profile' <DashboardPage
noIndex={true} builtInRoleRoadmaps={enrichedRoleRoadmaps}
initialLoadingMessage={'Loading teams'} builtInSkillRoadmaps={enrichedSkillRoadmaps}
> builtInBestPractices={enrichedBestPractices}
<AccountSidebar hasDesktopSidebar={false} activePageId='team' activePageTitle='Teams'> isTeamPage={true}
<TeamsList client:only="react" /> client:load
</AccountSidebar> />
</AccountLayout> <div slot='open-source-banner'></div>
</BaseLayout>

Loading…
Cancel
Save