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>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
'use client'
|
|
import { getGroup, getGroupExpenses } from '@/lib/api'
|
|
import { getTotalActiveUserShare } from '@/lib/totals'
|
|
import { cn, formatCurrency } from '@/lib/utils'
|
|
import { useLocale, useTranslations } from 'next-intl'
|
|
import { useEffect, useState } from 'react'
|
|
|
|
type Props = {
|
|
group: NonNullable<Awaited<ReturnType<typeof getGroup>>>
|
|
expenses: NonNullable<Awaited<ReturnType<typeof getGroupExpenses>>>
|
|
}
|
|
|
|
export function TotalsYourShare({ group, expenses }: Props) {
|
|
const locale = useLocale()
|
|
const t = useTranslations('Stats.Totals')
|
|
const [activeUser, setActiveUser] = useState('')
|
|
|
|
useEffect(() => {
|
|
const activeUser = localStorage.getItem(`${group.id}-activeUser`)
|
|
if (activeUser) setActiveUser(activeUser)
|
|
}, [group, expenses])
|
|
|
|
const totalActiveUserShare =
|
|
activeUser === '' || activeUser === 'None'
|
|
? 0
|
|
: getTotalActiveUserShare(activeUser, expenses)
|
|
const currency = group.currency
|
|
|
|
return (
|
|
<div>
|
|
<div className="text-muted-foreground">{t('yourShare')}</div>
|
|
<div
|
|
className={cn(
|
|
'text-lg',
|
|
totalActiveUserShare < 0 ? 'text-green-600' : 'text-red-600',
|
|
)}
|
|
>
|
|
{formatCurrency(currency, Math.abs(totalActiveUserShare), locale)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|