Skip to content

Commit 7d5092c

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents fff2e34 + 578c34f commit 7d5092c

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

src/components/Expense/ExpenseList.tsx

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import type { ExpenseRouter } from '~/server/api/routers/expense';
1212
import { useTranslationWithUtils } from '~/hooks/useTranslationWithUtils';
1313
import { api } from '~/utils/api';
1414
import { useRouter } from 'next/router';
15+
import { Separator } from '../ui/separator';
16+
import { cn } from '~/lib/utils';
1517

1618
type 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

src/pages/balances/[friendId].tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,13 @@ const FriendPage: NextPageWithUser = ({ user }) => {
134134
disabled={!expenses.data || 0 === expenses.data.length}
135135
/>
136136
</div>
137-
<Separator />
138-
<div className="mx-4 mt-4 flex flex-col gap-3">
139-
<ExpenseList
140-
expenses={expenses.data}
141-
contactId={_friendId}
142-
isLoading={expenses.isPending}
143-
userId={user.id}
144-
/>
145-
</div>
137+
<Separator className="mt-4" />
138+
<ExpenseList
139+
expenses={expenses.data}
140+
contactId={_friendId}
141+
isLoading={expenses.isPending}
142+
userId={user.id}
143+
/>
146144
</div>
147145
)}
148146
</MainLayout>

0 commit comments

Comments
 (0)