From 8e5198839563d97982129845c59a8780050e416d Mon Sep 17 00:00:00 2001 From: Jakub Knetl Date: Thu, 4 Jan 2024 08:11:04 +0100 Subject: [PATCH] Chapter 14 - form validation completed (create form only) --- app/ui/invoices/create-form.tsx | 57 ++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/app/ui/invoices/create-form.tsx b/app/ui/invoices/create-form.tsx index 6492feb..548e7ec 100644 --- a/app/ui/invoices/create-form.tsx +++ b/app/ui/invoices/create-form.tsx @@ -16,7 +16,7 @@ export default function Form({ customers }: { customers: CustomerField[] }) { const [state, dispatch] = useFormState(createInvoice, initialState); console.log(state); return ( -
+
{/* Customer Name */}
@@ -70,6 +70,13 @@ export default function Form({ customers }: { customers: CustomerField[] }) { />
+
+ {state.errors?.amount && state.errors.amount.map(s => ( +

{s}

+ ) + ) + } +
@@ -82,42 +89,54 @@ export default function Form({ customers }: { customers: CustomerField[] }) {
+
+ {state.errors?.status && state.errors?.status.map(e => ( +

{e}

+ ))} +
+ +
+ { + state.message && (

{state.message}

) + } +
Cancel