'use client' 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' import { Fragment } from 'react' 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`, { scroll: false, }) }} >
{expense.title}
Paid by {getParticipant(expense.paidById)?.name}{' '} for{' '} {expense.paidFor.map((paidFor, index) => ( {index !== 0 && <>, } { participants.find((p) => p.id === paidFor.participantId) ?.name } ))}
{currency} {(expense.amount / 100).toFixed(2)}
)) ) : (

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

) }