"use client"; import { TrashIcon } from "@heroicons/react/24/outline"; import { FC } from "react"; import { BillingLocation, YearMonth } from "../lib/db-types"; import { updateOrAddLocation } from "../lib/actions/locationActions"; import { useFormState } from "react-dom"; import Link from "next/link"; import { gotoHome } from "../lib/actions/navigationActions"; export type LocationEditFormProps = { /** location which should be edited */ location: BillingLocation, /** year adn month at a new billing location should be assigned */ yearMonth?: undefined } | { /** location which should be edited */ location?: undefined, /** year adn month at a new billing location should be assigned */ yearMonth: YearMonth } export const LocationEditForm:FC = ({ location, yearMonth }) => { const initialState = { message: null, errors: {} }; const handleAction = updateOrAddLocation.bind(null, location?._id, yearMonth); const [ state, dispatch ] = useFormState(handleAction, initialState); let { year, month } = location ? location.yearMonth : yearMonth; return(
{ location && }
{state.errors?.locationName && state.errors.locationName.map((error: string) => (

{error}

))}
{state.errors?.locationNotes && state.errors.locationNotes.map((error: string) => (

{error}

))}
{ state.message &&

{state.message}

}
Cancel
) } export const LocationEditFormSkeleton:FC = () => { return(
) }