mirror of
https://github.com/spliit-app/spliit.git
synced 2026-03-03 19:46:13 +01:00
format currency with thousand separators (#81)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { Balances } from '@/lib/balances'
|
import { Balances } from '@/lib/balances'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn, formatCurrency } from '@/lib/utils'
|
||||||
import { Participant } from '@prisma/client'
|
import { Participant } from '@prisma/client'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -28,7 +28,7 @@ export function BalancesList({ balances, participants, currency }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
<div className={cn('w-1/2 relative', isLeft || 'text-right')}>
|
<div className={cn('w-1/2 relative', isLeft || 'text-right')}>
|
||||||
<div className="absolute inset-0 p-2 z-20">
|
<div className="absolute inset-0 p-2 z-20">
|
||||||
{currency} {(balance / 100).toFixed(2)}
|
{formatCurrency(currency, balance)}
|
||||||
</div>
|
</div>
|
||||||
{balance !== 0 && (
|
{balance !== 0 && (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import {
|
|||||||
import { ToastAction } from '@/components/ui/toast'
|
import { ToastAction } from '@/components/ui/toast'
|
||||||
import { useToast } from '@/components/ui/use-toast'
|
import { useToast } from '@/components/ui/use-toast'
|
||||||
import { useMediaQuery } from '@/lib/hooks'
|
import { useMediaQuery } from '@/lib/hooks'
|
||||||
import { formatExpenseDate } from '@/lib/utils'
|
import { formatCurrency, formatExpenseDate } from '@/lib/utils'
|
||||||
import { Category } from '@prisma/client'
|
import { Category } from '@prisma/client'
|
||||||
import { ChevronRight, FileQuestion, Loader2, Receipt } from 'lucide-react'
|
import { ChevronRight, FileQuestion, Loader2, Receipt } from 'lucide-react'
|
||||||
import { getImageData, usePresignedUpload } from 'next-s3-upload'
|
import { getImageData, usePresignedUpload } from 'next-s3-upload'
|
||||||
@@ -185,9 +185,7 @@ export function CreateFromReceiptButton({
|
|||||||
<div>
|
<div>
|
||||||
{receiptInfo ? (
|
{receiptInfo ? (
|
||||||
receiptInfo.amount ? (
|
receiptInfo.amount ? (
|
||||||
<>
|
<>{formatCurrency(groupCurrency, receiptInfo.amount)}</>
|
||||||
{groupCurrency} {receiptInfo.amount.toFixed(2)}
|
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
<Unknown />
|
<Unknown />
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { CategoryIcon } from '@/app/groups/[groupId]/expenses/category-icon'
|
|||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { SearchBar } from '@/components/ui/search-bar'
|
import { SearchBar } from '@/components/ui/search-bar'
|
||||||
import { getGroupExpenses } from '@/lib/api'
|
import { getGroupExpenses } from '@/lib/api'
|
||||||
import { cn, formatExpenseDate } from '@/lib/utils'
|
import { cn, formatCurrency, formatExpenseDate } from '@/lib/utils'
|
||||||
import { Expense, Participant } from '@prisma/client'
|
import { Expense, Participant } from '@prisma/client'
|
||||||
import dayjs, { type Dayjs } from 'dayjs'
|
import dayjs, { type Dayjs } from 'dayjs'
|
||||||
import { ChevronRight } from 'lucide-react'
|
import { ChevronRight } from 'lucide-react'
|
||||||
@@ -156,7 +156,7 @@ export function ExpenseList({
|
|||||||
expense.isReimbursement ? 'italic' : 'font-bold',
|
expense.isReimbursement ? 'italic' : 'font-bold',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{currency} {(expense.amount / 100).toFixed(2)}
|
{formatCurrency(currency, expense.amount)}
|
||||||
</div>
|
</div>
|
||||||
<div className="text-xs text-muted-foreground">
|
<div className="text-xs text-muted-foreground">
|
||||||
{formatExpenseDate(expense.expenseDate)}
|
{formatExpenseDate(expense.expenseDate)}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Reimbursement } from '@/lib/balances'
|
import { Reimbursement } from '@/lib/balances'
|
||||||
|
import { formatCurrency } from '@/lib/utils'
|
||||||
import { Participant } from '@prisma/client'
|
import { Participant } from '@prisma/client'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
|
||||||
@@ -42,9 +43,7 @@ export function ReimbursementList({
|
|||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>{formatCurrency(currency, reimbursement.amount)}</div>
|
||||||
{currency} {(reimbursement.amount / 100).toFixed(2)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,3 +20,12 @@ export function formatExpenseDate(date: Date) {
|
|||||||
export function formatCategoryForAIPrompt(category: Category) {
|
export function formatCategoryForAIPrompt(category: Category) {
|
||||||
return `"${category.grouping}/${category.name}" (ID: ${category.id})`
|
return `"${category.grouping}/${category.name}" (ID: ${category.id})`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatCurrency(currency: string, amount: number) {
|
||||||
|
const format = new Intl.NumberFormat('en-US', {
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
maximumFractionDigits: 2,
|
||||||
|
})
|
||||||
|
const formattedAmount = format.format(amount / 100)
|
||||||
|
return `${currency} ${formattedAmount}`
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user