'use client'; import { CustomerField } from '@/app/lib/definitions'; import Link from 'next/link'; import { CheckIcon, ClockIcon, CurrencyDollarIcon, UserCircleIcon, } from '@heroicons/react/24/outline'; import { Button } from '@/app/ui/button'; import {createInvoice} from "@/app/lib/actions"; import { useFormState } from 'react-dom'; export default function Form({ customers }: { customers: CustomerField[] }) { const initialState = { message: null, errors: {} }; const [state, dispatch] = useFormState(createInvoice, initialState); console.log(state); return (
{/* Customer Name */}
{state.errors?.customerId && state.errors.customerId.map((error: string) => (

{error}

))}
{/* Invoice Amount */}
{state.errors?.amount && state.errors.amount.map(s => (

{s}

) ) }
{/* Invoice Status */}
Set the invoice status
{state.errors?.status && state.errors?.status.map(e => (

{e}

))}
{ state.message && (

{state.message}

) }
Cancel
); }