'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, State} from "@/app/lib/actions"; import {useActionState} from "react"; export default function Form({customers}: { customers: CustomerField[] }) { const initialState: State = { message: null, errors: {} } const [state, formAction] = useActionState(createInvoice, initialState); return (
{/* Customer Name */}
{state.errors?.customerId && state.errors.customerId.map((error: string) => (

{error}

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

{error}

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

{error}

))}
{state.message &&

{state.message}

}
Cancel
); }