From 247355664606e553795cb38e0b433e2fbadbaf95 Mon Sep 17 00:00:00 2001 From: akshat mittal Date: Fri, 9 Jan 2026 17:20:53 +0200 Subject: [PATCH] refactor: reuse RoleCard and KpiCard in member page Replace custom MemberRoleCard with existing RoleCard and KpiCard components. Each role now displays as a paired layout with role info on left and KPI on right. --- .../[id]/_components/member-role-card.tsx | 85 ------------------- .../member/[id]/_components/role-kpi-pair.tsx | 68 +++++++++++++++ .../member/[id]/_components/team-section.tsx | 29 +++---- 3 files changed, 82 insertions(+), 100 deletions(-) delete mode 100644 src/app/member/[id]/_components/member-role-card.tsx create mode 100644 src/app/member/[id]/_components/role-kpi-pair.tsx diff --git a/src/app/member/[id]/_components/member-role-card.tsx b/src/app/member/[id]/_components/member-role-card.tsx deleted file mode 100644 index 88188f2d..00000000 --- a/src/app/member/[id]/_components/member-role-card.tsx +++ /dev/null @@ -1,85 +0,0 @@ -"use client"; - -import { Gauge, TrendingUp, User } from "lucide-react"; - -import { ReadOnlyMetricCard } from "@/app/dashboard/[teamId]/_components/dashboard-metric-card"; -import { stripHtml } from "@/lib/html-utils"; -import { type RouterOutputs } from "@/trpc/react"; - -type Role = RouterOutputs["role"]["getByUser"][number]; -type DashboardMetrics = RouterOutputs["dashboard"]["getDashboardCharts"]; - -interface MemberRoleCardProps { - role: Role; - dashboardChart?: DashboardMetrics[number]; -} - -export function MemberRoleCard({ role, dashboardChart }: MemberRoleCardProps) { - const purpose = stripHtml(role.purpose ?? ""); - const truncatedPurpose = - purpose.length > 100 ? purpose.substring(0, 100) + "..." : purpose; - - return ( -
- {/* Header */} -
- -

{role.title}

-
- - {/* Body */} -
- {/* Purpose */} - {truncatedPurpose && ( -

- {truncatedPurpose} -

- )} - - {/* Metric info when no chart */} - {!dashboardChart && role.metric && ( -
-
- - {role.metric.name} -
- {role.metric.description && ( -

- {role.metric.description} -

- )} -
- )} -
- - {/* Footer - Effort Points */} - {role.effortPoints && ( -
-
- - - {role.effortPoints} {role.effortPoints === 1 ? "point" : "points"} - -
-
- )} - - {/* Metric Chart Section */} - {dashboardChart ? ( -
- -
- ) : !role.metric ? ( -
- No KPI assigned -
- ) : null} -
- ); -} diff --git a/src/app/member/[id]/_components/role-kpi-pair.tsx b/src/app/member/[id]/_components/role-kpi-pair.tsx new file mode 100644 index 00000000..4d54772a --- /dev/null +++ b/src/app/member/[id]/_components/role-kpi-pair.tsx @@ -0,0 +1,68 @@ +"use client"; + +import { KpiCard } from "@/components/metric/kpi-card"; +import { RoleCard, type RoleCardData } from "@/components/role/role-card"; +import { cn } from "@/lib/utils"; +import { type RouterOutputs } from "@/trpc/react"; + +type Role = RouterOutputs["role"]["getByUser"][number]; +type DashboardChart = RouterOutputs["dashboard"]["getDashboardCharts"][number]; + +interface RoleKpiPairProps { + role: Role; + dashboardChart?: DashboardChart; + teamId: string; +} + +export function RoleKpiPair({ + role, + dashboardChart, + teamId, +}: RoleKpiPairProps) { + const roleCardData: RoleCardData = { + id: role.id, + title: role.title, + purpose: role.purpose, + color: role.color ?? "#3b82f6", + effortPoints: role.effortPoints, + assignedUserId: role.assignedUserId, + assignedUserName: role.assignedUserName, + metric: role.metric + ? { + name: role.metric.name, + dashboardCharts: role.metric.dashboardCharts, + } + : null, + }; + + const hasKpi = !!dashboardChart; + const hasMetricButNoChart = !!role.metricId && !dashboardChart; + + return ( +
+ + + {hasKpi && ( + + )} + + {hasMetricButNoChart && ( +
+ KPI data loading... +
+ )} +
+ ); +} diff --git a/src/app/member/[id]/_components/team-section.tsx b/src/app/member/[id]/_components/team-section.tsx index 61e9ba8a..3d761f91 100644 --- a/src/app/member/[id]/_components/team-section.tsx +++ b/src/app/member/[id]/_components/team-section.tsx @@ -13,7 +13,7 @@ import { } from "@/components/ui/collapsible"; import { type RouterOutputs } from "@/trpc/react"; -import { MemberRoleCard } from "./member-role-card"; +import { RoleKpiPair } from "./role-kpi-pair"; type Role = RouterOutputs["role"]["getByUser"][number]; type DashboardMetrics = RouterOutputs["dashboard"]["getDashboardCharts"]; @@ -74,20 +74,19 @@ export function TeamSection({ -
-
- {roles.map((role) => ( - - ))} -
+
+ {roles.map((role) => ( + + ))}