Skip to content

Commit

Permalink
Add notes in expense (#126)
Browse files Browse the repository at this point in the history
* Feature: Added notes in expense

* Add missing notes in form values

* Prettier

---------

Co-authored-by: deep.golani <deep.golani@bfhl.in>
Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
  • Loading branch information
3 people authored Apr 5, 2024
1 parent b61d183 commit 2fd38aa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Expense" ADD COLUMN "notes" TEXT;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ model Expense {
splitMode SplitMode @default(EVENLY)
createdAt DateTime @default(now())
documents ExpenseDocument[]
notes String?
}

model ExpenseDocument {
Expand Down
16 changes: 16 additions & 0 deletions src/components/expense-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { useForm } from 'react-hook-form'
import { match } from 'ts-pattern'
import { DeletePopup } from './delete-popup'
import { extractCategoryFromTitle } from './expense-form-actions'
import { Textarea } from './ui/textarea'

export type Props = {
group: NonNullable<Awaited<ReturnType<typeof getGroup>>>
Expand Down Expand Up @@ -180,6 +181,7 @@ export function ExpenseForm({
saveDefaultSplittingOptions: false,
isReimbursement: expense.isReimbursement,
documents: expense.documents,
notes: expense.notes ?? '',
}
: searchParams.get('reimbursement')
? {
Expand All @@ -202,6 +204,7 @@ export function ExpenseForm({
splitMode: defaultSplittingOptions.splitMode,
saveDefaultSplittingOptions: false,
documents: [],
notes: '',
}
: {
title: searchParams.get('title') ?? '',
Expand All @@ -228,6 +231,7 @@ export function ExpenseForm({
},
]
: [],
notes: '',
},
})
const [isCategoryLoading, setCategoryLoading] = useState(false)
Expand Down Expand Up @@ -400,6 +404,18 @@ export function ExpenseForm({
</FormItem>
)}
/>
<FormField
control={form.control}
name="notes"
render={({ field }) => (
<FormItem className="sm:order-6">
<FormLabel>Notes</FormLabel>
<FormControl>
<Textarea className="text-base" {...field} />
</FormControl>
</FormItem>
)}
/>
</CardContent>
</Card>

Expand Down
2 changes: 2 additions & 0 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export async function createExpense(
})),
},
},
notes: expenseFormValues.notes,
},
})
}
Expand Down Expand Up @@ -185,6 +186,7 @@ export async function updateExpense(
id: doc.id,
})),
},
notes: expenseFormValues.notes,
},
})
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const expenseFormSchema = z
}),
)
.default([]),
notes: z.string().optional(),
})
.superRefine((expense, ctx) => {
let sum = 0
Expand Down

0 comments on commit 2fd38aa

Please sign in to comment.