@@ -12,6 +12,8 @@ import type { ExpenseRouter } from '~/server/api/routers/expense';
1212import { useTranslationWithUtils } from '~/hooks/useTranslationWithUtils' ;
1313import { api } from '~/utils/api' ;
1414import { useRouter } from 'next/router' ;
15+ import { Separator } from '../ui/separator' ;
16+ import { cn } from '~/lib/utils' ;
1517
1618type ExpensesOutput =
1719 | inferRouterOutputs < ExpenseRouter > [ 'getGroupExpenses' ]
@@ -35,25 +37,54 @@ export const ExpenseList: React.FC<{
3537 return < NoExpenses /> ;
3638 }
3739
40+ const { i18n } = useTranslationWithUtils ( ) ;
41+
42+ let lastDate : Date | null = null ;
43+
3844 return (
39- < >
45+ < div className = "flex flex-col gap-3" >
4046 { expenses . map ( ( e ) => {
47+ const currentDate = e . expenseDate ;
48+ let isFirstOfMonth = false ;
49+
50+ if (
51+ lastDate === null ||
52+ currentDate . getMonth ( ) !== lastDate . getMonth ( ) ||
53+ currentDate . getFullYear ( ) !== lastDate . getFullYear ( )
54+ ) {
55+ isFirstOfMonth = true ;
56+ }
57+
58+ lastDate = currentDate ;
59+
4160 const isSettlement = e . splitType === SplitType . SETTLEMENT ;
4261 const isCurrencyConversion = e . splitType === SplitType . CURRENCY_CONVERSION ;
4362
4463 return (
45- < Link
46- href = { `/${ isGroup ? 'groups' : 'balances' } /${ contactId } /expenses/${ e . id } ` }
47- key = { e . id }
48- className = "flex items-center justify-between py-2"
49- >
50- { isSettlement && < Settlement e = { e } userId = { userId } /> }
51- { isCurrencyConversion && < CurrencyConversion e = { e } userId = { userId } /> }
52- { ! isSettlement && ! isCurrencyConversion && < Expense e = { e } userId = { userId } /> }
53- </ Link >
64+ < React . Fragment key = { e . id } >
65+ { isFirstOfMonth && (
66+ < div className = "flex flex-row gap-3 pt-2" >
67+ < div className = "text-xs font-medium text-gray-700 uppercase" >
68+ { new Intl . DateTimeFormat ( i18n . language , {
69+ month : 'long' ,
70+ year : 'numeric' ,
71+ } ) . format ( currentDate ) }
72+ </ div >
73+ < Separator className = "flex-1 bg-gray-800" />
74+ </ div >
75+ ) }
76+ < Link
77+ href = { `/${ isGroup ? 'groups' : 'balances' } /${ contactId } /expenses/${ e . id } ` }
78+ className = { cn ( 'flex items-center justify-between' , isFirstOfMonth ? 'pb-2' : 'py-2' ) }
79+ >
80+ { isSettlement && < Settlement e = { e } userId = { userId } /> }
81+ { isCurrencyConversion && < CurrencyConversion e = { e } userId = { userId } /> }
82+ { ! isSettlement && ! isCurrencyConversion && < Expense e = { e } userId = { userId } /> }
83+ </ Link >
84+ </ React . Fragment >
5485 ) ;
5586 } ) }
56- </ >
87+ </ div >
5788 ) ;
5889} ;
5990
0 commit comments