From 57899b0160385c53df4e43ef2fd12492e0dffb77 Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Wed, 6 Dec 2023 20:21:26 -0500 Subject: Reimbursements --- src/components/expense-form.tsx | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/components') diff --git a/src/components/expense-form.tsx b/src/components/expense-form.tsx index 6420bc6..3f6490f 100644 --- a/src/components/expense-form.tsx +++ b/src/components/expense-form.tsx @@ -29,6 +29,7 @@ import { import { getExpense, getGroup } from '@/lib/api' import { ExpenseFormValues, expenseFormSchema } from '@/lib/schemas' import { zodResolver } from '@hookform/resolvers/zod' +import { useSearchParams } from 'next/navigation' import { useForm } from 'react-hook-form' export type Props = { @@ -40,6 +41,7 @@ export type Props = { export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) { const isCreate = expense === undefined + const searchParams = useSearchParams() const form = useForm({ resolver: zodResolver(expenseFormSchema), defaultValues: expense @@ -48,8 +50,17 @@ export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) { amount: expense.amount, paidBy: expense.paidById, paidFor: expense.paidFor.map(({ participantId }) => participantId), + isReimbursement: expense.isReimbursement, } - : { title: '', amount: 0, paidFor: [] }, + : searchParams.get('reimbursement') + ? { + title: 'Reimbursement', + amount: Number(searchParams.get('amount')) || 0, + paidBy: searchParams.get('from') ?? undefined, + paidFor: [searchParams.get('to') ?? undefined], + isReimbursement: true, + } + : { title: '', amount: 0, paidFor: [], isReimbursement: false }, }) return ( @@ -131,8 +142,25 @@ export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) { /> - Enter the expense amount. + + ( + + + + +
+ This is a reimbursement +
+
+ )} + /> )} /> @@ -141,7 +169,7 @@ export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) { control={form.control} name="paidFor" render={() => ( - +
Paid for -- cgit v1.3