|
| 1 | +// app/(root)/dashboard/org/[orgname]/page.tsx |
| 2 | + |
| 3 | +import type { Metadata } from 'next'; |
| 4 | +import { notFound } from 'next/navigation'; |
| 5 | +import Link from 'next/link'; |
| 6 | + |
| 7 | +import ProfileCard from '@/components/dashboard/ProfileCard'; |
| 8 | +import ActivityLandscape from '@/components/dashboard/ActivityLandscape'; |
| 9 | +import StatsCard from '@/components/dashboard/StatsCard'; |
| 10 | +import CommitClock from '@/components/dashboard/CommitClock'; |
| 11 | +import Heatmap from '@/components/dashboard/Heatmap'; |
| 12 | +import AIInsights from '@/components/dashboard/AIInsights'; |
| 13 | +import Achievements from '@/components/dashboard/Achievements'; |
| 14 | +import { getOrgDashboardData, buildCommitClock, generateAchievements } from '@/lib/github'; |
| 15 | + |
| 16 | +export const revalidate = 3600; // Cache for 1 hour |
| 17 | + |
| 18 | +const BASE_URL = |
| 19 | + process.env.NEXT_PUBLIC_SITE_URL ?? |
| 20 | + (process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : 'http://localhost:3000'); |
| 21 | + |
| 22 | +export async function generateMetadata({ |
| 23 | + params, |
| 24 | +}: { |
| 25 | + params: Promise<{ orgname: string }>; |
| 26 | +}): Promise<Metadata> { |
| 27 | + const { orgname } = await params; |
| 28 | + const ogImage = `${BASE_URL}/api/og?user=${orgname}`; // Reuse OG, but it will fetch org data gracefully |
| 29 | + const title = `${orgname} | Organization Mega-City`; |
| 30 | + const description = `Explore the aggregated open-source contribution pulse for the ${orgname} organization on CommitPulse.`; |
| 31 | + |
| 32 | + return { |
| 33 | + title, |
| 34 | + description, |
| 35 | + openGraph: { |
| 36 | + title, |
| 37 | + description, |
| 38 | + url: `${BASE_URL}/dashboard/org/${orgname}`, |
| 39 | + siteName: 'CommitPulse', |
| 40 | + images: [{ url: ogImage, width: 1200, height: 630, alt: title }], |
| 41 | + type: 'profile', |
| 42 | + }, |
| 43 | + }; |
| 44 | +} |
| 45 | + |
| 46 | +export default async function OrgDashboardPage({ |
| 47 | + params, |
| 48 | + searchParams, |
| 49 | +}: { |
| 50 | + params: Promise<{ orgname: string }>; |
| 51 | + searchParams: Promise<{ refresh?: string }>; |
| 52 | +}) { |
| 53 | + const { orgname } = await params; |
| 54 | + const refreshParams = await searchParams; |
| 55 | + const bypassCache = refreshParams?.refresh === 'true'; |
| 56 | + |
| 57 | + let data; |
| 58 | + |
| 59 | + try { |
| 60 | + data = await getOrgDashboardData(orgname, { bypassCache }); |
| 61 | + } catch (error) { |
| 62 | + console.error(error); |
| 63 | + return notFound(); |
| 64 | + } |
| 65 | + |
| 66 | + // 1. Process Calendar into Activity Array for Org |
| 67 | + const allDays = data.calendar.weeks.flatMap((w) => w.contributionDays); |
| 68 | + const activity = allDays.map((day) => { |
| 69 | + let intensity: 0 | 1 | 2 | 3 | 4 = 0; |
| 70 | + // Scaled up intensity thresholds because orgs have way more commits than single users |
| 71 | + if (day.contributionCount > 0) intensity = 1; |
| 72 | + if (day.contributionCount > 15) intensity = 2; |
| 73 | + if (day.contributionCount > 50) intensity = 3; |
| 74 | + if (day.contributionCount > 150) intensity = 4; |
| 75 | + |
| 76 | + return { |
| 77 | + date: day.date, |
| 78 | + count: day.contributionCount, |
| 79 | + intensity, |
| 80 | + }; |
| 81 | + }); |
| 82 | + |
| 83 | + // 2. Generate Org Specific Assets |
| 84 | + const commitClock = buildCommitClock(allDays); |
| 85 | + const achievements = generateAchievements( |
| 86 | + data.stats.totalContributions, |
| 87 | + data.stats.currentStreak |
| 88 | + ); |
| 89 | + |
| 90 | + // 3. Custom Org AI Insights |
| 91 | + const insights = [ |
| 92 | + { |
| 93 | + id: '1', |
| 94 | + icon: 'Users', |
| 95 | + text: `This organization is powered by ${data.profile.stats.following} core open-source contributors.`, |
| 96 | + }, |
| 97 | + { |
| 98 | + id: '2', |
| 99 | + icon: 'GitCommit', |
| 100 | + text: `A massive ${data.stats.totalContributions} total contributions were merged by the team this year.`, |
| 101 | + }, |
| 102 | + { |
| 103 | + id: '3', |
| 104 | + icon: 'Flame', |
| 105 | + text: `The team's peak collaborative streak reached ${data.stats.peakStreak} consecutive days.`, |
| 106 | + }, |
| 107 | + ]; |
| 108 | + |
| 109 | + return ( |
| 110 | + <div id="dashboard-root" data-dashboard className="p-4 md:p-6 lg:p-8 min-h-screen relative"> |
| 111 | + {/* Top Action Bar */} |
| 112 | + <div id="generate-dashboard-btn" className="flex justify-between items-center mb-6"> |
| 113 | + <div className="inline-flex items-center gap-2 rounded-full border border-indigo-400/20 bg-indigo-500/10 px-4 py-1.5 text-xs font-semibold uppercase tracking-[0.2em] text-indigo-400"> |
| 114 | + Organization Mega-City |
| 115 | + </div> |
| 116 | + <div className="flex gap-4"> |
| 117 | + <Link |
| 118 | + href={`/dashboard/org/${orgname}?refresh=true`} |
| 119 | + className="flex items-center gap-2 rounded-xl border border-black/10 dark:border-[rgba(255,255,255,0.15)] bg-black dark:bg-black px-4 py-2 text-sm font-semibold text-white dark:text-white transition-all duration-200 hover:bg-gray-800 dark:hover:bg-white/10 active:scale-[0.98]" |
| 120 | + > |
| 121 | + Refresh Data |
| 122 | + </Link> |
| 123 | + <Link |
| 124 | + href="/" |
| 125 | + className="flex items-center gap-2 rounded-xl border border-black/10 dark:border-[rgba(255,255,255,0.15)] bg-gray-100 dark:bg-[#111] px-4 py-2 text-sm font-semibold text-black dark:text-white transition-all duration-200 hover:bg-gray-200 dark:hover:bg-white/10 active:scale-[0.98]" |
| 126 | + > |
| 127 | + Generate Yours |
| 128 | + </Link> |
| 129 | + </div> |
| 130 | + </div> |
| 131 | + |
| 132 | + <div className="grid grid-cols-1 lg:grid-cols-[300px_1fr_320px] gap-6 lg:gap-8"> |
| 133 | + {/* Left Sidebar */} |
| 134 | + <aside className="flex flex-col gap-6"> |
| 135 | + <ProfileCard |
| 136 | + user={data.profile} |
| 137 | + exportData={{ |
| 138 | + stats: data.stats, |
| 139 | + languages: [], // Orgs skip language donut chart for now |
| 140 | + }} |
| 141 | + /> |
| 142 | + <Achievements achievements={achievements} /> |
| 143 | + </aside> |
| 144 | + |
| 145 | + {/* Main Content */} |
| 146 | + <div className="flex flex-col gap-6 lg:gap-8 min-w-0"> |
| 147 | + <section> |
| 148 | + <ActivityLandscape data={activity} /> |
| 149 | + </section> |
| 150 | + |
| 151 | + {/* Org specific layout: CommitClock takes full width of the main content column */} |
| 152 | + <section className="grid grid-cols-1 gap-6"> |
| 153 | + <CommitClock data={commitClock} /> |
| 154 | + </section> |
| 155 | + |
| 156 | + <section> |
| 157 | + <Heatmap data={activity} /> |
| 158 | + </section> |
| 159 | + </div> |
| 160 | + |
| 161 | + {/* Right Sidebar */} |
| 162 | + <aside className="flex flex-col gap-6"> |
| 163 | + <div className="flex flex-col gap-4"> |
| 164 | + <StatsCard |
| 165 | + title="Team Current Streak" |
| 166 | + value={data.stats.currentStreak.toString()} |
| 167 | + description="Days" |
| 168 | + icon="Flame" |
| 169 | + /> |
| 170 | + |
| 171 | + <StatsCard |
| 172 | + title="Team Peak Streak" |
| 173 | + value={data.stats.peakStreak.toString()} |
| 174 | + description="Days" |
| 175 | + icon="TrendingUp" |
| 176 | + /> |
| 177 | + |
| 178 | + <StatsCard |
| 179 | + title="Total Team Commits" |
| 180 | + value={data.stats.totalContributions.toString()} |
| 181 | + description="Last 365 Days" |
| 182 | + icon="GitCommit" |
| 183 | + /> |
| 184 | + </div> |
| 185 | + |
| 186 | + <AIInsights insights={insights} /> |
| 187 | + </aside> |
| 188 | + </div> |
| 189 | + </div> |
| 190 | + ); |
| 191 | +} |
0 commit comments