Use "everyone" in the expense card if it was paid for all participants (#398)

This commit is contained in:
Peter Smit
2025-09-04 20:15:00 +02:00
committed by GitHub
parent a21f0646b5
commit 86a20d6b23
4 changed files with 30 additions and 9 deletions

View File

@@ -43,6 +43,7 @@
}, },
"ExpenseCard": { "ExpenseCard": {
"paidBy": "Paid by <strong>{paidBy}</strong> for <paidFor></paidFor>", "paidBy": "Paid by <strong>{paidBy}</strong> for <paidFor></paidFor>",
"everyone": "everyone",
"receivedBy": "Received by <strong>{paidBy}</strong> for <paidFor></paidFor>", "receivedBy": "Received by <strong>{paidBy}</strong> for <paidFor></paidFor>",
"yourBalance": "Your balance:", "yourBalance": "Your balance:",
"notInvolved": "You are not involved" "notInvolved": "You are not involved"

View File

@@ -43,6 +43,7 @@
}, },
"ExpenseCard": { "ExpenseCard": {
"paidBy": "Betaald door <strong>{paidBy}</strong> voor <paidFor></paidFor>", "paidBy": "Betaald door <strong>{paidBy}</strong> voor <paidFor></paidFor>",
"everyone": "iedereen",
"receivedBy": "Ontvangen door <strong>{paidBy}</strong> voor <paidFor></paidFor>", "receivedBy": "Ontvangen door <strong>{paidBy}</strong> voor <paidFor></paidFor>",
"yourBalance": "Jouw balans:" "yourBalance": "Jouw balans:"
}, },

View File

@@ -13,15 +13,27 @@ import { Fragment } from 'react'
type Expense = Awaited<ReturnType<typeof getGroupExpenses>>[number] type Expense = Awaited<ReturnType<typeof getGroupExpenses>>[number]
function Participants({ expense }: { expense: Expense }) { function Participants({
expense,
participantCount,
}: {
expense: Expense
participantCount: number
}) {
const t = useTranslations('ExpenseCard') const t = useTranslations('ExpenseCard')
const key = expense.amount > 0 ? 'paidBy' : 'receivedBy' const key = expense.amount > 0 ? 'paidBy' : 'receivedBy'
const paidFor = expense.paidFor.map((paidFor, index) => ( const paidFor =
<Fragment key={index}> expense.paidFor.length == participantCount && participantCount >= 4 ? (
{index !== 0 && <>, </>} <strong>{t('everyone')}</strong>
<strong>{paidFor.participant.name}</strong> ) : (
</Fragment> expense.paidFor.map((paidFor, index) => (
)) <Fragment key={index}>
{index !== 0 && <>, </>}
<strong>{paidFor.participant.name}</strong>
</Fragment>
))
)
const participants = t.rich(key, { const participants = t.rich(key, {
strong: (chunks) => <strong>{chunks}</strong>, strong: (chunks) => <strong>{chunks}</strong>,
paidBy: expense.paidBy.name, paidBy: expense.paidBy.name,
@@ -35,9 +47,15 @@ type Props = {
expense: Expense expense: Expense
currency: string currency: string
groupId: string groupId: string
participantCount: number
} }
export function ExpenseCard({ expense, currency, groupId }: Props) { export function ExpenseCard({
expense,
currency,
groupId,
participantCount,
}: Props) {
const router = useRouter() const router = useRouter()
const locale = useLocale() const locale = useLocale()
@@ -61,7 +79,7 @@ export function ExpenseCard({ expense, currency, groupId }: Props) {
{expense.title} {expense.title}
</div> </div>
<div className="text-xs text-muted-foreground"> <div className="text-xs text-muted-foreground">
<Participants expense={expense} /> <Participants expense={expense} participantCount={participantCount} />
</div> </div>
<div className="text-xs text-muted-foreground"> <div className="text-xs text-muted-foreground">
<ActiveUserBalance {...{ groupId, currency, expense }} /> <ActiveUserBalance {...{ groupId, currency, expense }} />

View File

@@ -172,6 +172,7 @@ const ExpenseListForSearch = ({
expense={expense} expense={expense}
currency={group.currency} currency={group.currency}
groupId={groupId} groupId={groupId}
participantCount={group.participants.length}
/> />
))} ))}
</div> </div>