diff options
| author | Sebastien Castiel <sebastien@castiel.me> | 2024-01-30 16:36:29 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-30 16:36:29 -0500 |
| commit | 4a9bf575bd24b2e24348c65d9fbbf9c81a73cb35 (patch) | |
| tree | 364cb36ea89d8023676140ed2fdd166c3b1fd602 /src/components | |
| parent | 9e300e0ff0c9d93cbaeaa86c1e2a560523107382 (diff) | |
Create expense from receipt (#69)
* Create expense from receipt
* Add modal
* Update README
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/expense-form.tsx | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/components/expense-form.tsx b/src/components/expense-form.tsx index a847949..3d6c2da 100644 --- a/src/components/expense-form.tsx +++ b/src/components/expense-form.tsx @@ -34,7 +34,7 @@ import { SelectTrigger, SelectValue, } from '@/components/ui/select' -import { getCategories, getExpense, getGroup } from '@/lib/api' +import { getCategories, getExpense, getGroup, randomId } from '@/lib/api' import { ExpenseFormValues, expenseFormSchema } from '@/lib/schemas' import { cn } from '@/lib/utils' import { zodResolver } from '@hookform/resolvers/zod' @@ -105,10 +105,14 @@ export function ExpenseForm({ documents: [], } : { - title: '', - expenseDate: new Date(), - amount: 0, - category: 0, // category with Id 0 is General + title: searchParams.get('title') ?? '', + expenseDate: searchParams.get('date') + ? new Date(searchParams.get('date') as string) + : new Date(), + amount: (searchParams.get('amount') || 0) as unknown as number, // hack, + category: searchParams.get('categoryId') + ? Number(searchParams.get('categoryId')) + : 0, // category with Id 0 is General // paid for all, split evenly paidFor: group.participants.map(({ id }) => ({ participant: id, @@ -117,7 +121,16 @@ export function ExpenseForm({ paidBy: getSelectedPayer(), isReimbursement: false, splitMode: 'EVENLY', - documents: [], + documents: searchParams.get('imageUrl') + ? [ + { + id: randomId(), + url: searchParams.get('imageUrl') as string, + width: Number(searchParams.get('imageWidth')), + height: Number(searchParams.get('imageHeight')), + }, + ] + : [], }, }) |
