From 7ec5e30b51b398b0cd8dcc21fc64d6594b919987 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Fri, 6 Oct 2023 19:00:08 +0100 Subject: [PATCH] Hero roadmap section updates --- .../CreateRoadmap/CreateRoadmapButton.tsx | 7 +- .../HeroSection/FavoriteRoadmaps.tsx | 25 ++++- src/components/HeroSection/HeroRoadmaps.tsx | 103 +++++++++++++++++- 3 files changed, 125 insertions(+), 10 deletions(-) diff --git a/src/components/CustomRoadmap/CreateRoadmap/CreateRoadmapButton.tsx b/src/components/CustomRoadmap/CreateRoadmap/CreateRoadmapButton.tsx index 267b6f51a..eeffd1a02 100644 --- a/src/components/CustomRoadmap/CreateRoadmap/CreateRoadmapButton.tsx +++ b/src/components/CustomRoadmap/CreateRoadmap/CreateRoadmapButton.tsx @@ -12,10 +12,12 @@ import { useState } from 'react'; type CreateRoadmapButtonProps = { className?: string; type?: AllowedCustomRoadmapType; + text?: string; + teamId?: string; }; export function CreateRoadmapButton(props: CreateRoadmapButtonProps) { - const { className, type } = props; + const { teamId, className, type, text = 'Create your own Roadmap' } = props; const [isCreatingRoadmap, setIsCreatingRoadmap] = useState(false); @@ -31,6 +33,7 @@ export function CreateRoadmapButton(props: CreateRoadmapButtonProps) { <> {isCreatingRoadmap && ( { setIsCreatingRoadmap(false); @@ -46,7 +49,7 @@ export function CreateRoadmapButton(props: CreateRoadmapButtonProps) { onClick={toggleCreateRoadmapHandler} > - Create your own Roadmap + {text} ); diff --git a/src/components/HeroSection/FavoriteRoadmaps.tsx b/src/components/HeroSection/FavoriteRoadmaps.tsx index cb73504b2..73dced17b 100644 --- a/src/components/HeroSection/FavoriteRoadmaps.tsx +++ b/src/components/HeroSection/FavoriteRoadmaps.tsx @@ -1,8 +1,9 @@ import { useEffect, useState } from 'react'; import { EmptyProgress } from './EmptyProgress'; import { httpGet } from '../../lib/http'; -import { HeroRoadmaps } from './HeroRoadmaps'; +import { HeroRoadmaps, type HeroTeamRoadmaps } from './HeroRoadmaps'; import { isLoggedIn } from '../../lib/jwt'; +import type { AllowedMemberRoles } from '../ShareOptions/ShareTeamMemberList.tsx'; export type UserProgressResponse = { resourceId: string; @@ -15,6 +16,11 @@ export type UserProgressResponse = { total: number; updatedAt: Date; isCustomResource: boolean; + team?: { + name: string; + id: string; + role: AllowedMemberRoles; + }; }[]; function renderProgress(progressList: UserProgressResponse) { @@ -114,8 +120,22 @@ export function FavoriteRoadmaps() { } const hasProgress = progress?.length > 0; - const customRoadmaps = progress?.filter((p) => p.isCustomResource); + const customRoadmaps = progress?.filter( + (p) => p.isCustomResource && !p.team?.name + ); const defaultRoadmaps = progress?.filter((p) => !p.isCustomResource); + const teamRoadmaps: HeroTeamRoadmaps = progress + ?.filter((p) => p.isCustomResource && p.team?.name) + .reduce((acc: HeroTeamRoadmaps, curr) => { + const currTeam = curr.team!; + if (!acc[currTeam.name]) { + acc[currTeam.name] = []; + } + + acc[currTeam.name].push(curr); + + return acc; + }, {}); return (
} {hasProgress && ( ); } +export type HeroTeamRoadmaps = Record; type ProgressListProps = { progress: UserProgressResponse; customRoadmaps: UserProgressResponse; + teamRoadmaps?: HeroTeamRoadmaps; isLoading?: boolean; }; export function HeroRoadmaps(props: ProgressListProps) { - const { progress, isLoading = false, customRoadmaps } = props; + const { + teamRoadmaps = {}, + progress, + isLoading = false, + customRoadmaps, + } = props; const [isCreatingRoadmap, setIsCreatingRoadmap] = useState(false); + const [creatingRoadmapTeamId, setCreatingRoadmapTeamId] = useState(); return (
-

+

{isCreatingRoadmap && ( - setIsCreatingRoadmap(false)} /> + { + setIsCreatingRoadmap(false); + setCreatingRoadmapTeamId(undefined); + }} + /> )} { )}
+ + {Object.keys(teamRoadmaps).map((teamName) => { + const currentTeam: UserProgressResponse[0]['team'] = + teamRoadmaps?.[teamName]?.[0]?.team; + const roadmapsList = teamRoadmaps[teamName].filter( + (roadmap) => !!roadmap.resourceTitle + ); + const canManageTeam = ['admin', 'manager'].includes(currentTeam?.role!); + + return ( +
+ { + } + title={ + <> + Team{' '} + + {teamName} + + Roadmaps + + } + /> + } + + {roadmapsList.length === 0 && ( +

+ Team does not have any roadmaps yet.{' '} + {canManageTeam && ( + + )} +

+ )} + + {roadmapsList.length > 0 && ( +
+ {roadmapsList.map((customRoadmap) => { + return ( + + ); + })} + + {canManageTeam && ( + + )} +
+ )} +
+ ); + })}
); }