From e747ec3ea02dd01e9ffa9e398e24e6939a5b738c Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Wed, 6 Dec 2023 17:47:41 -0500 Subject: Tabs --- src/app/groups/[groupId]/balances/page.tsx | 41 +++++++++ src/app/groups/[groupId]/expenses/page.tsx | 114 +++++++++++++++++++++++++ src/app/groups/[groupId]/group-tabs.tsx | 30 +++++++ src/app/groups/[groupId]/layout.tsx | 20 ++--- src/app/groups/[groupId]/page.tsx | 132 +---------------------------- 5 files changed, 196 insertions(+), 141 deletions(-) create mode 100644 src/app/groups/[groupId]/balances/page.tsx create mode 100644 src/app/groups/[groupId]/expenses/page.tsx create mode 100644 src/app/groups/[groupId]/group-tabs.tsx (limited to 'src/app/groups') diff --git a/src/app/groups/[groupId]/balances/page.tsx b/src/app/groups/[groupId]/balances/page.tsx new file mode 100644 index 0000000..24818c9 --- /dev/null +++ b/src/app/groups/[groupId]/balances/page.tsx @@ -0,0 +1,41 @@ +import { BalancesList } from '@/app/groups/[groupId]/balances-list' +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from '@/components/ui/card' +import { getGroup, getGroupExpenses } from '@/lib/api' +import { getBalances } from '@/lib/balances' +import { notFound } from 'next/navigation' + +export default async function GroupPage({ + params: { groupId }, +}: { + params: { groupId: string } +}) { + const group = await getGroup(groupId) + if (!group) notFound() + + const expenses = await getGroupExpenses(groupId) + const balances = getBalances(expenses) + + return ( + + + Balances + + This is the amount that each participant paid or was paid for. + + + + + + + ) +} diff --git a/src/app/groups/[groupId]/expenses/page.tsx b/src/app/groups/[groupId]/expenses/page.tsx new file mode 100644 index 0000000..2eb98ab --- /dev/null +++ b/src/app/groups/[groupId]/expenses/page.tsx @@ -0,0 +1,114 @@ +import { Badge } from '@/components/ui/badge' +import { Button } from '@/components/ui/button' +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from '@/components/ui/card' +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from '@/components/ui/table' +import { getGroup, getGroupExpenses } from '@/lib/api' +import { ChevronRight, Plus } from 'lucide-react' +import Link from 'next/link' +import { notFound } from 'next/navigation' + +export default async function GroupExpensesPage({ + params: { groupId }, +}: { + params: { groupId: string } +}) { + const group = await getGroup(groupId) + if (!group) notFound() + + const expenses = await getGroupExpenses(groupId) + + return ( + +
+ + Expenses + + Here are the expenses that you created for your group. + + + + + +
+ + + {expenses.length > 0 ? ( + + + + Title + Paid by + Paid for + Amount + + + + + {expenses.map((expense) => ( + + {expense.title} + + + { + group.participants.find( + (p) => p.id === expense.paidById, + )?.name + } + + + + {expense.paidFor.map((paidFor, index) => ( + + { + group.participants.find( + (p) => p.id === paidFor.participantId, + )?.name + } + + ))} + + + {group.currency} {expense.amount.toFixed(2)} + + + + + + ))} + +
+ ) : ( +
Your group doesn’t have any expense yet.
+ )} +
+
+ ) +} diff --git a/src/app/groups/[groupId]/group-tabs.tsx b/src/app/groups/[groupId]/group-tabs.tsx new file mode 100644 index 0000000..e5c48c2 --- /dev/null +++ b/src/app/groups/[groupId]/group-tabs.tsx @@ -0,0 +1,30 @@ +'use client' +import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs' +import { usePathname, useRouter } from 'next/navigation' + +type Props = { + groupId: string +} + +export function GroupTabs({ groupId }: Props) { + const pathname = usePathname() + const value = + pathname.replace(/\/groups\/[^\/]+\/([^/]+).*/, '$1') || 'expenses' + const router = useRouter() + + return ( + { + router.push(`/groups/${groupId}/${value}`) + }} + > + + Expenses + Balances + Settings + + + ) +} diff --git a/src/app/groups/[groupId]/layout.tsx b/src/app/groups/[groupId]/layout.tsx index 5c835f5..5b99dd2 100644 --- a/src/app/groups/[groupId]/layout.tsx +++ b/src/app/groups/[groupId]/layout.tsx @@ -1,6 +1,8 @@ +import { GroupTabs } from '@/app/groups/[groupId]/group-tabs' +import { SaveGroupLocally } from '@/app/groups/[groupId]/save-recent-group' import { Button } from '@/components/ui/button' import { getGroup } from '@/lib/api' -import { ChevronLeft, Edit } from 'lucide-react' +import { ChevronLeft } from 'lucide-react' import Link from 'next/link' import { notFound } from 'next/navigation' import { PropsWithChildren } from 'react' @@ -24,19 +26,15 @@ export default async function GroupLayout({ -
-

- {group.name} -

+

+ {group.name} +

- -
+ {children} + + ) } diff --git a/src/app/groups/[groupId]/page.tsx b/src/app/groups/[groupId]/page.tsx index 7fffcb3..b28c3c9 100644 --- a/src/app/groups/[groupId]/page.tsx +++ b/src/app/groups/[groupId]/page.tsx @@ -1,137 +1,9 @@ -import { BalancesList } from '@/app/groups/[groupId]/balances-list' -import { SaveGroupLocally } from '@/app/groups/[groupId]/save-recent-group' -import { Badge } from '@/components/ui/badge' -import { Button } from '@/components/ui/button' -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from '@/components/ui/card' -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from '@/components/ui/table' -import { getGroup, getGroupExpenses } from '@/lib/api' -import { getBalances } from '@/lib/balances' -import { ChevronRight, Plus } from 'lucide-react' -import Link from 'next/link' -import { notFound } from 'next/navigation' +import { redirect } from 'next/navigation' export default async function GroupPage({ params: { groupId }, }: { params: { groupId: string } }) { - const group = await getGroup(groupId) - if (!group) notFound() - - const expenses = await getGroupExpenses(groupId) - const balances = getBalances(expenses) - - return ( - <> - -
- - Expenses - - Here are the expenses that you created for your group. - - - - - -
- - - {expenses.length > 0 ? ( - - - - Title - Paid by - Paid for - Amount - - - - - {expenses.map((expense) => ( - - {expense.title} - - - { - group.participants.find( - (p) => p.id === expense.paidById, - )?.name - } - - - - {expense.paidFor.map((paidFor, index) => ( - - { - group.participants.find( - (p) => p.id === paidFor.participantId, - )?.name - } - - ))} - - - {group.currency} {expense.amount.toFixed(2)} - - - - - - ))} - -
- ) : ( -
Your group doesn’t have any expense yet.
- )} -
-
- - - - Balances - - This is the amount that each participant paid or was paid for. - - - - - - - - - ) + redirect(`/groups/${groupId}/expenses`) } -- cgit v1.3