mirror of
https://github.com/spliit-app/spliit.git
synced 2026-03-09 13:49:04 +01:00
* I18n with next-intl * package-lock * Finnish translations * Development fix * Use locale for positioning currency symbol * Translations: Expenses.ActiveUserModal * Translations: group 404 * Better translation for ExpenseCard * Apply translations in CategorySelect search * Fix for Finnish translation * Translations for ExpenseDocumentsInput * Translations for CreateFromReceipt * Fix for Finnish translation * Translations for schema errors * Fix for Finnish translation * Fixes for Finnish translations * Prettier --------- Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
'use client'
|
|
import { getGroup, getGroupExpenses } from '@/lib/api'
|
|
import { useActiveUser } from '@/lib/hooks'
|
|
import { getTotalActiveUserPaidFor } from '@/lib/totals'
|
|
import { cn, formatCurrency } from '@/lib/utils'
|
|
import { useLocale, useTranslations } from 'next-intl'
|
|
|
|
type Props = {
|
|
group: NonNullable<Awaited<ReturnType<typeof getGroup>>>
|
|
expenses: NonNullable<Awaited<ReturnType<typeof getGroupExpenses>>>
|
|
}
|
|
|
|
export function TotalsYourSpendings({ group, expenses }: Props) {
|
|
const locale = useLocale()
|
|
const t = useTranslations('Stats.Totals')
|
|
const activeUser = useActiveUser(group.id)
|
|
|
|
const totalYourSpendings =
|
|
activeUser === '' || activeUser === 'None'
|
|
? 0
|
|
: getTotalActiveUserPaidFor(activeUser, expenses)
|
|
const currency = group.currency
|
|
const balance = totalYourSpendings < 0 ? 'yourEarnings' : 'yourSpendings'
|
|
|
|
return (
|
|
<div>
|
|
<div className="text-muted-foreground">{t(balance)}</div>
|
|
|
|
<div
|
|
className={cn(
|
|
'text-lg',
|
|
totalYourSpendings < 0 ? 'text-green-600' : 'text-red-600',
|
|
)}
|
|
>
|
|
{formatCurrency(currency, Math.abs(totalYourSpendings), locale)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|