From a0f64430e05ad5bc7238d8dd337d22c9bc85ae63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Znamen=C3=A1=C4=8Dek?= Date: Mon, 8 Jul 2024 14:38:53 +0200 Subject: [PATCH] Add project engagement section to user profile --- app/people/[id]/page.tsx | 47 +++++++++++++++++++++++++++++++++---- src/data/team-engagement.ts | 14 +++++++++++ src/routing.ts | 2 +- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/app/people/[id]/page.tsx b/app/people/[id]/page.tsx index 21663006a..96cbe2451 100644 --- a/app/people/[id]/page.tsx +++ b/app/people/[id]/page.tsx @@ -1,9 +1,13 @@ import Image from "next/image"; +import Link from "next/link"; import { notFound } from "next/navigation"; import { Breadcrumbs } from "~/components/Breadcrumbs"; -import { TextPill } from "~/components/TextPill"; -import { getUserProfile } from "~/src/data/user-profile"; +import { + getPublicTeamEngagementsForUser, + type TeamEngagement, +} from "~/src/data/team-engagement"; +import { getUserProfile, type UserProfile } from "~/src/data/user-profile"; import { Route } from "~/src/routing"; import { skillsToHashtags } from "~/src/skills/skills"; @@ -21,6 +25,7 @@ async function Page({ params }: Props) { // TBD: Maybe the profile is private? notFound(); } + const projectEngagements = await getPublicTeamEngagementsForUser(profile.id); const avatarUrl = profile.slackAvatarUrl ?? "https://data.cesko.digital/people/generic-profile.jpg"; @@ -46,13 +51,45 @@ async function Page({ params }: Props) { Napsat mail -
-

{profile.name}

-
{skillsToHashtags(profile.skills)}
+
+ + {projectEngagements.length > 0 && ( + + )}
); } +const IntroSection = ({ profile }: { profile: UserProfile }) => ( +
+

{profile.name}

+

{skillsToHashtags(profile.skills)}

+
+); + +const ProjectSection = ({ engagements }: { engagements: TeamEngagement[] }) => ( +
+

Moje projekty

+ +
+); + export default Page; diff --git a/src/data/team-engagement.ts b/src/data/team-engagement.ts index 54ea861d8..e83d66526 100644 --- a/src/data/team-engagement.ts +++ b/src/data/team-engagement.ts @@ -39,6 +39,7 @@ export const decodeTeamEngagement = record({ userAvatarUrl: relationToOne, projectRole: optional(string), projectName: relationToOne, + projectSlug: relationToOne, coordinatingRole: withDefault(boolean, false), fields: optionalArray(string), inactive: withDefault(boolean, false), @@ -73,3 +74,16 @@ export async function getPublicTeamEngagementsForProject( .then(unwrapRecords) .then(decodeValidItemsFromArray(decodeTeamEngagement, "Teams")); } + +export async function getPublicTeamEngagementsForUser( + userId: string, +): Promise { + return await teamEngagementTable + .select({ + view: "Public Team Engagements", + filterByFormula: `{userId} = "${userId}"`, + }) + .all() + .then(unwrapRecords) + .then(decodeValidItemsFromArray(decodeTeamEngagement, "Teams")); +} diff --git a/src/routing.ts b/src/routing.ts index a8650d7a0..2ace8dbe7 100644 --- a/src/routing.ts +++ b/src/routing.ts @@ -28,7 +28,7 @@ export const Route = { eventFeed: "/events/feed.ical", // Dynamic routes toEvent: (e: Event) => `/events/${e.slug}`, - toProject: (p: Project) => `/projects/${p.slug}`, + toProject: (p: Pick) => `/projects/${p.slug}`, toOpportunity: (o: Pick) => `/opportunities/${o.slug}`, toYouTubePlaylist: (playlistId: string) => `https://www.youtube.com/playlist?list=${playlistId}`,