diff --git a/prisma/migrations/20240108174319_add_expense_date/migration.sql b/prisma/migrations/20240108174319_add_expense_date/migration.sql
new file mode 100644
index 0000000..0b6de90
--- /dev/null
+++ b/prisma/migrations/20240108174319_add_expense_date/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "Expense" ADD COLUMN "expenseDate" DATE NOT NULL DEFAULT CURRENT_DATE;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index fd65754..42d4cfc 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -32,6 +32,7 @@ model Participant {
model Expense {
id String @id
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade)
+ expenseDate DateTime @db.Date @default(dbgenerated("CURRENT_DATE"))
title String
amount Int
paidBy Participant @relation(fields: [paidById], references: [id], onDelete: Cascade)
diff --git a/src/app/groups/[groupId]/expenses/expense-list.tsx b/src/app/groups/[groupId]/expenses/expense-list.tsx
index 798a5f8..7ee8329 100644
--- a/src/app/groups/[groupId]/expenses/expense-list.tsx
+++ b/src/app/groups/[groupId]/expenses/expense-list.tsx
@@ -41,7 +41,10 @@ export function ExpenseList({
{expense.title}
- Paid by {getParticipant(expense.paidById)?.name}{' '}
+ Paid by {getParticipant(expense.paidById)?.name} on{' '}
+ {expense.expenseDate.toLocaleDateString('en-US', {
+ dateStyle: 'medium',
+ })}{' '}
for{' '}
{expense.paidFor.map((paidFor, index) => (
diff --git a/src/app/groups/actions.ts b/src/app/groups/actions.ts
index 2d07004..9e8e605 100644
--- a/src/app/groups/actions.ts
+++ b/src/app/groups/actions.ts
@@ -1,5 +1,5 @@
'use server'
-import { getGroups } from "@/lib/api"
+import { getGroups } from '@/lib/api'
export async function getGroupsAction(groupIds: string[]) {
'use server'
diff --git a/src/components/expense-form.tsx b/src/components/expense-form.tsx
index 45e34fa..98a8f29 100644
--- a/src/components/expense-form.tsx
+++ b/src/components/expense-form.tsx
@@ -56,6 +56,7 @@ export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) {
defaultValues: expense
? {
title: expense.title,
+ expenseDate: expense.expenseDate ?? new Date(),
amount: String(expense.amount / 100) as unknown as number, // hack
paidBy: expense.paidById,
paidFor: expense.paidFor.map(({ participantId, shares }) => ({
@@ -68,6 +69,7 @@ export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) {
: searchParams.get('reimbursement')
? {
title: 'Reimbursement',
+ expenseDate: new Date(),
amount: String(
(Number(searchParams.get('amount')) || 0) / 100,
) as unknown as number, // hack
@@ -81,6 +83,7 @@ export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) {
}
: {
title: '',
+ expenseDate: new Date(),
amount: 0,
paidFor: [],
isReimbursement: false,
@@ -119,6 +122,32 @@ export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) {
)}
/>
+ (
+
+ Expense Date
+
+ {
+ return field.onChange(new Date(event.target.value))
+ }}
+ />
+
+
+ Enter the date the expense was made.
+
+
+
+ )}
+ />
+
export const expenseFormSchema = z
.object({
+ expenseDate: z.coerce.date(),
title: z
.string({ required_error: 'Please enter a title.' })
.min(2, 'Enter at least two characters.'),
diff --git a/src/scripts/migrate.ts b/src/scripts/migrate.ts
index beeecc1..ed1a3a5 100644
--- a/src/scripts/migrate.ts
+++ b/src/scripts/migrate.ts
@@ -80,6 +80,7 @@ async function main() {
amount: Math.round(expenseRow.amount * 100),
groupId: groupRow.id,
title: expenseRow.description,
+ expenseDate: new Date(expenseRow.created_at.toDateString()),
createdAt: expenseRow.created_at,
isReimbursement: expenseRow.is_reimbursement === true,
paidById: participantIdsMapping[expenseRow.paid_by_participant_id],