import { ChangeEvent } from 'react'; import { Trash2 } from 'lucide-react'; import { FormError } from '@@/form-components/FormError'; import { Button } from '@@/buttons'; import { isArrayErrorType } from '@@/form-components/formikUtils'; import { Annotation, AnnotationErrors } from './types'; interface Props { annotations: Annotation[]; handleAnnotationChange: ( index: number, key: 'key' | 'value', val: string ) => void; removeAnnotation: (index: number) => void; errors: AnnotationErrors; placeholder: string[]; } export function AnnotationsForm({ annotations, handleAnnotationChange, removeAnnotation, errors, placeholder, }: Props) { const annotationErrors = isArrayErrorType(errors) ? errors : undefined; return ( <> {annotations.map((annotation, i) => (
Key ) => handleAnnotationChange(i, 'key', e.target.value) } data-cy={`annotation-key-${i}`} />
{annotationErrors?.[i]?.key && ( {annotationErrors[i]?.key} )}
Value ) => handleAnnotationChange(i, 'value', e.target.value) } data-cy={`annotation-value-${i}`} />
{annotationErrors?.[i]?.value && ( {annotationErrors[i]?.value} )}
))} ); }