|
| 1 | +import { |
| 2 | + ExpenseDto, |
| 3 | + GroupDto, |
| 4 | + GroupMemberSummaryDto, |
| 5 | + PaginatedExpensesResponseDto |
| 6 | +} from '@fairshare/shared-types'; |
| 7 | +import { notFound } from 'next/navigation'; |
| 8 | + |
| 9 | +import { DashboardLayout } from '../../../../src/components/layout'; |
| 10 | +import { MemberList, ExpenseTable } from '../../../../src/components/groups'; |
| 11 | +import { backendFetch } from '../../../../src/lib/backend'; |
| 12 | + |
| 13 | +interface GroupDetailPageProps { |
| 14 | + params: Promise<{ |
| 15 | + groupId: string; |
| 16 | + }>; |
| 17 | +} |
| 18 | + |
| 19 | +export default async function GroupDetailPage({ params }: GroupDetailPageProps) { |
| 20 | + const { groupId } = await params; |
| 21 | + |
| 22 | + try { |
| 23 | + const [group, members, expenses] = await Promise.all([ |
| 24 | + backendFetch<GroupDto>(`/groups/${groupId}`), |
| 25 | + backendFetch<GroupMemberSummaryDto[]>(`/groups/${groupId}/members`), |
| 26 | + backendFetch<PaginatedExpensesResponseDto>(`/groups/${groupId}/expenses?limit=50`), |
| 27 | + ]); |
| 28 | + |
| 29 | + return ( |
| 30 | + <DashboardLayout> |
| 31 | + <header className="mb-8"> |
| 32 | + <div className="flex items-center justify-between"> |
| 33 | + <h1 className="text-3xl font-bold text-text-primary">{group.name}</h1> |
| 34 | + <div className="rounded-full bg-brand/10 px-4 py-1.5 text-xs font-semibold uppercase tracking-wider text-brand"> |
| 35 | + {group.currency} |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + <p className="mt-2 text-text-secondary"> |
| 39 | + Manage members and track shared expenses. |
| 40 | + </p> |
| 41 | + </header> |
| 42 | + |
| 43 | + <div className="grid gap-6 lg:grid-cols-[1fr_320px]"> |
| 44 | + <div className="space-y-6"> |
| 45 | + <ExpenseTable expenses={expenses.items} /> |
| 46 | + </div> |
| 47 | + |
| 48 | + <aside className="space-y-6"> |
| 49 | + <MemberList members={members} /> |
| 50 | + |
| 51 | + <div className="rounded-2xl border border-border bg-card p-5 shadow-glass backdrop-blur-glass"> |
| 52 | + <h3 className="text-sm font-semibold text-text-primary">Quick Actions</h3> |
| 53 | + <div className="mt-4 grid gap-2"> |
| 54 | + <button className="w-full rounded-xl bg-brand py-2.5 text-sm font-semibold text-white transition-opacity hover:opacity-90"> |
| 55 | + Add Expense |
| 56 | + </button> |
| 57 | + <button className="w-full rounded-xl border border-border bg-surface/10 py-2.5 text-sm font-semibold text-text-primary transition-colors hover:bg-surface/20"> |
| 58 | + Invite Member |
| 59 | + </button> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + </aside> |
| 63 | + </div> |
| 64 | + </DashboardLayout> |
| 65 | + ); |
| 66 | + } catch (error) { |
| 67 | + console.error('Failed to fetch group details:', error); |
| 68 | + return notFound(); |
| 69 | + } |
| 70 | +} |
0 commit comments