Skip to content

Commit

Permalink
Show expense date instead of created date in groups (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
KMKoushik authored Apr 30, 2024
1 parent f0aae3f commit 491c8a9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/components/Expense/ExpensePage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ExpenseParticipant, type Expense, type User } from '@prisma/client';
import { type User as NextUser } from 'next-auth';
import { format } from 'date-fns';
import { format, isSameDay } from 'date-fns';
import React from 'react';
import { toUIString } from '~/utils/numbers';
import { UserAvatar } from '../ui/avatar';
Expand Down Expand Up @@ -38,15 +38,18 @@ const ExpenseDetails: React.FC<ExpenseDetailsProps> = ({ user, expense }) => {
<p className="text-2xl font-semibold">
{expense.currency} {toUIString(expense.amount ?? 0)}
</p>
{!isSameDay(expense.expenseDate, expense.createdAt) ? (
<p className="text-sm text-gray-500">{format(expense.expenseDate, 'dd MMM yyyy')}</p>
) : null}
{expense.deletedByUser ? (
<p className=" text-sm text-orange-600">
Deleted by {expense.deletedByUser.name ?? expense.addedByUser.email} on{' '}
{format(expense.deletedAt ?? expense.expenseDate, 'dd MMM yyyy')}
{format(expense.deletedAt ?? expense.createdAt, 'dd MMM yyyy')}
</p>
) : (
<p className=" text-sm text-gray-500">
Added by {expense.addedByUser.name ?? expense.addedByUser.email} on{' '}
{format(expense.expenseDate, 'dd MMM yyyy')}
{format(expense.createdAt, 'dd MMM yyyy')}
</p>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/groups/[groupId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ const BalancePage: NextPageWithUser = ({ user }) => {
>
<div className="flex items-center gap-4">
<div className="text-xs text-gray-500">
{format(e.createdAt, 'MMM dd')
{format(e.expenseDate, 'MMM dd')
.split(' ')
.map((d) => (
<div className="text-center" key={d}>
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/routers/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const groupRouter = createTRPCRouter({
deletedBy: null,
},
orderBy: {
createdAt: 'desc',
expenseDate: 'desc',
},
include: {
expenseParticipants: true,
Expand Down

0 comments on commit 491c8a9

Please sign in to comment.