diff --git a/app/[slug]/dashboard/page.tsx b/app/[slug]/dashboard/page.tsx index 51c96c1..00408ad 100644 --- a/app/[slug]/dashboard/page.tsx +++ b/app/[slug]/dashboard/page.tsx @@ -1,9 +1,26 @@ /* Copyright (C) 2024 Manuel Bustillo*/ +'use client' + +import { GlobalSummary as Summary } from '@/app/lib/definitions'; +import { getSlug } from '@/app/lib/utils'; import GlobalSummary from '@/app/ui/dashboard/global-summary'; +import { useEffect, useState } from 'react'; export default function Page() { - return( - + const [globalSummary, setGlobalSummary] = useState(undefined); + + function refreshSummary() { + fetch(`/api/${getSlug()}/summary`) + .then((response) => response.json()) + .then((data) => { + setGlobalSummary(data); + }) + } + + useEffect(refreshSummary, []); + + return ( + globalSummary && ); } \ No newline at end of file diff --git a/app/lib/definitions.ts b/app/lib/definitions.ts index 218150d..0e1fce7 100644 --- a/app/lib/definitions.ts +++ b/app/lib/definitions.ts @@ -1,5 +1,6 @@ /* Copyright (C) 2024 Manuel Bustillo*/ +import { AttendanceSummary } from "./group"; import { Guest } from "./guest"; export interface Entity { @@ -37,4 +38,23 @@ export type Captcha = { export type StructuredErrors = { [key: string]: string[] | string; -}; \ No newline at end of file +}; + +export type GlobalSummary = { + expenses: ExpenseSummary; + guests: AttendanceSummary +} + +export type ExpenseSummary = { + projected: ExpensePossibleSummary; + confirmed: ExpensePossibleSummary; + status: StatusSummary; +} + +export type ExpensePossibleSummary = { + total: number; + guests: number; +} +export type StatusSummary = { + paid: number; +} \ No newline at end of file diff --git a/app/ui/components/dashboard-cards.tsx b/app/ui/components/dashboard-cards.tsx index 6c72ac4..0240938 100644 --- a/app/ui/components/dashboard-cards.tsx +++ b/app/ui/components/dashboard-cards.tsx @@ -21,7 +21,7 @@ const colorClasses = (style: Style) => { } } -export async function MainCard({ amount, title, subtitle, style, iconName }: +export function MainCard({ amount, title, subtitle, style, iconName }: { amount: string, title: string, @@ -42,7 +42,7 @@ export async function MainCard({ amount, title, subtitle, style, iconName }: ); } -export async function SecondaryCard({ amount, title, iconName, style }: { amount: string, title: string, iconName: keyof typeof HeroIcon, style: Style }) { +export function SecondaryCard({ amount, title, iconName, style }: { amount: string, title: string, iconName: keyof typeof HeroIcon, style: Style }) { return (
diff --git a/app/ui/dashboard/global-summary.tsx b/app/ui/dashboard/global-summary.tsx index 9b00359..8de82ee 100644 --- a/app/ui/dashboard/global-summary.tsx +++ b/app/ui/dashboard/global-summary.tsx @@ -1,45 +1,41 @@ /* Copyright (C) 2024 Manuel Bustillo*/ +import { GlobalSummary } from '@/app/lib/definitions'; import { MainCard, SecondaryCard } from '../components/dashboard-cards'; -export default async function GlobalSummary() { - return ( -
- -
- - -
- - -
-
- - -
- -
- -
- - -
- - -
- -
- - - -
-
- -
- - - -
+export default function GlobalSummary({ summary }: { summary: GlobalSummary }) { + return ( +
+
+
+ +
- ); +
+ + + +
+
+ + +
+ +
+ +
+ + +
+ + +
+ +
+ + +
+
+
+ ); } \ No newline at end of file