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

{error}

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

{error}

))}
) : null}
{/* Invoice Status */}
{state.errors?.status ? (
{state.errors.status.map((error: string) => (

{error}

))}
) : null} {state.message ? (

{state.message}

) : null}
Cancel
); }