From ec981fd237a50dfc547d8c162b22f4e1a691c9fc Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Wed, 6 Dec 2023 21:07:51 -0500 Subject: Improve responsiveness --- src/app/groups/[groupId]/balances-list.tsx | 6 +- src/app/groups/[groupId]/expenses/expense-list.tsx | 76 +++++++++++++ src/app/groups/[groupId]/expenses/page.tsx | 124 ++------------------- src/app/groups/[groupId]/reimbursement-list.tsx | 12 +- 4 files changed, 94 insertions(+), 124 deletions(-) create mode 100644 src/app/groups/[groupId]/expenses/expense-list.tsx (limited to 'src') diff --git a/src/app/groups/[groupId]/balances-list.tsx b/src/app/groups/[groupId]/balances-list.tsx index c0d48b9..26092ec 100644 --- a/src/app/groups/[groupId]/balances-list.tsx +++ b/src/app/groups/[groupId]/balances-list.tsx @@ -20,13 +20,13 @@ export function BalancesList({ balances, participants, currency }: Props) { key={participant.id} className={cn( 'flex', - balances[participant.id]?.total > 0 || 'flex-row-reverse', + balances[participant.id]?.total >= 0 || 'flex-row-reverse', )} >
0 && 'text-right', + balances[participant.id]?.total >= 0 && 'text-right', )} > {participant.name} @@ -34,7 +34,7 @@ export function BalancesList({ balances, participants, currency }: Props) {
0 || 'text-right', + balances[participant.id]?.total >= 0 || 'text-right', )} >
diff --git a/src/app/groups/[groupId]/expenses/expense-list.tsx b/src/app/groups/[groupId]/expenses/expense-list.tsx new file mode 100644 index 0000000..0c03756 --- /dev/null +++ b/src/app/groups/[groupId]/expenses/expense-list.tsx @@ -0,0 +1,76 @@ +'use client' +import { Badge } from '@/components/ui/badge' +import { Button } from '@/components/ui/button' +import { getGroupExpenses } from '@/lib/api' +import { cn } from '@/lib/utils' +import { Participant } from '@prisma/client' +import { ChevronRight } from 'lucide-react' +import Link from 'next/link' +import { useRouter } from 'next/navigation' + +type Props = { + expenses: Awaited> + participants: Participant[] + currency: string + groupId: string +} + +export function ExpenseList({ + expenses, + currency, + participants, + groupId, +}: Props) { + const getParticipant = (id: string) => participants.find((p) => p.id === id) + const router = useRouter() + + return expenses.length > 0 ? ( + expenses.map((expense) => ( +
{ + router.push(`/groups/${groupId}/expenses/${expense.id}/edit`) + }} + > +
+
{expense.title}
+
+ Paid by{' '} + + {getParticipant(expense.paidById)?.name} + {' '} + for{' '} + {expense.paidFor.map((paidFor, index) => ( + + {participants.find((p) => p.id === paidFor.participantId)?.name} + + ))} +
+
+
+
+ {currency} {expense.amount.toFixed(2)} +
+ +
+
+ )) + ) : ( +

+ Your group doesn’t contain any expense yet.{' '} + +

+ ) +} diff --git a/src/app/groups/[groupId]/expenses/page.tsx b/src/app/groups/[groupId]/expenses/page.tsx index 0047b1e..48f355b 100644 --- a/src/app/groups/[groupId]/expenses/page.tsx +++ b/src/app/groups/[groupId]/expenses/page.tsx @@ -1,4 +1,4 @@ -import { Badge } from '@/components/ui/badge' +import { ExpenseList } from '@/app/groups/[groupId]/expenses/expense-list' import { Button } from '@/components/ui/button' import { Card, @@ -8,8 +8,7 @@ import { CardTitle, } from '@/components/ui/card' import { getGroup, getGroupExpenses } from '@/lib/api' -import { cn } from '@/lib/utils' -import { ChevronRight, Plus } from 'lucide-react' +import { Plus } from 'lucide-react' import Link from 'next/link' import { notFound } from 'next/navigation' @@ -42,119 +41,12 @@ export default async function GroupExpensesPage({
- {expenses.length > 0 ? ( - expenses.map((expense) => ( -
-
-
{expense.title}
-
- Paid by{' '} - - { - group.participants.find((p) => p.id === expense.paidById) - ?.name - } - {' '} - for{' '} - {expense.paidFor.map((paidFor, index) => ( - - { - group.participants.find( - (p) => p.id === paidFor.participantId, - )?.name - } - - ))} -
-
-
-
- {group.currency} {expense.amount.toFixed(2)} -
- -
-
- )) - ) : ( -

- Your group doesn’t contain any expense yet.{' '} - -

- )} - {/* - - - 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]/reimbursement-list.tsx b/src/app/groups/[groupId]/reimbursement-list.tsx index 3fc94bc..e8400ca 100644 --- a/src/app/groups/[groupId]/reimbursement-list.tsx +++ b/src/app/groups/[groupId]/reimbursement-list.tsx @@ -20,11 +20,13 @@ export function ReimbursementList({ return (
{reimbursements.map((reimbursement, index) => ( -
-
- {getParticipant(reimbursement.from)?.name} owes{' '} - {getParticipant(reimbursement.to)?.name} -