From aa5c625e0ede296db99d8da786f8d688e96a582c Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Sat, 16 Dec 2023 16:54:42 -0500 Subject: [PATCH] Form validation --- src/components/expense-form.tsx | 273 ++++++++++++++++++-------------- src/lib/schemas.ts | 120 ++++++++++---- 2 files changed, 242 insertions(+), 151 deletions(-) diff --git a/src/components/expense-form.tsx b/src/components/expense-form.tsx index 4182d253..3e0909b3 100644 --- a/src/components/expense-form.tsx +++ b/src/components/expense-form.tsx @@ -29,6 +29,7 @@ import { } from '@/components/ui/select' import { getExpense, getGroup } from '@/lib/api' import { ExpenseFormValues, expenseFormSchema } from '@/lib/schemas' +import { cn } from '@/lib/utils' import { zodResolver } from '@hookform/resolvers/zod' import { useSearchParams } from 'next/navigation' import { useForm } from 'react-hook-form' @@ -84,12 +85,12 @@ export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) { {isCreate ? <>Create expense : <>Edit expense} - + ( - + Expense title - ( - - Paid by - - - Select the participant who paid the expense. - - - - )} - /> - ( - + Amount
{group.currency} @@ -179,45 +151,80 @@ export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) { ( - - ( - - Split mode - - + + + + + {group.participants.map(({ id, name }) => ( + + {name} + + ))} + + + + Select the participant who paid the expense. + + + + )} + /> + + ( + + Split mode + + - - - Select how to split the expense. - - - )} - /> + */} + + + + + Select how to split the expense. + + + )} + /> -
+ ( + +
Paid for