Skip to content

Commit

Permalink
feat(expense-list): Display the attachment count only when the expens…
Browse files Browse the repository at this point in the history
…e includes attachments (#267)

* feat(expense-list): Display the attachment count only when the expense includes attachments

* handle attachments - singular & plural

* move documents count between amount and date

* Remove label

* Use document count only instead of whole document list

---------

Co-authored-by: Sebastien Castiel <[email protected]>
  • Loading branch information
yuvarajsai and scastiel authored Dec 7, 2024
1 parent 2c973f9 commit 72ad0a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/app/groups/[groupId]/expenses/documents-count.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Paperclip } from 'lucide-react'

export function DocumentsCount({ count }: { count: number }) {
if (count === 0) return <></>
return (
<div className="flex items-center">
<Paperclip className="w-3.5 h-3.5 mr-1 mt-0.5 text-muted-foreground" />
<span>{count}</span>
</div>
)
}
4 changes: 4 additions & 0 deletions src/app/groups/[groupId]/expenses/expense-card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'
import { ActiveUserBalance } from '@/app/groups/[groupId]/expenses/active-user-balance'
import { CategoryIcon } from '@/app/groups/[groupId]/expenses/category-icon'
import { DocumentsCount } from '@/app/groups/[groupId]/expenses/documents-count'
import { Button } from '@/components/ui/button'
import { getGroupExpenses } from '@/lib/api'
import { cn, formatCurrency, formatDate } from '@/lib/utils'
Expand Down Expand Up @@ -75,6 +76,9 @@ export function ExpenseCard({ expense, currency, groupId }: Props) {
>
{formatCurrency(currency, expense.amount, locale)}
</div>
<div className="text-xs text-muted-foreground">
<DocumentsCount count={expense._count.documents} />
</div>
<div className="text-xs text-muted-foreground">
{formatDate(expense.expenseDate, locale, { dateStyle: 'medium' })}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export async function getGroupExpenses(
},
splitMode: true,
title: true,
_count: { select: { documents: true } },
},
where: {
groupId,
Expand Down

0 comments on commit 72ad0a4

Please sign in to comment.