import InputError from '@/components/input-error'; import { Checkbox } from '@/components/ui/checkbox'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Textarea } from '@/components/ui/textarea'; import { useTranslation } from '@/hooks/use-translation'; export interface CustomFieldDefinition { id: number; label: string; type: string; options: string[] | null; required: boolean; locked?: boolean; } interface ClientCustomFieldsSectionProps { fields: CustomFieldDefinition[]; values: Record; onChange: (fieldId: number, value: string) => void; errors: Partial>; } /** * Custom field values are keyed by field id in both `values` and the * outgoing `custom_field_values` payload — checkboxes store '1'/'0' * rather than a real boolean so every field shares one string shape. */ export function ClientCustomFieldsSection({ fields, values, onChange, errors }: ClientCustomFieldsSectionProps) { const { t } = useTranslation(); if (fields.length === 0) return null; return (
{fields.map((field) => { const value = values[field.id] ?? ''; const error = errors[`custom_field_values.${field.id}`]; const htmlId = `custom-field-${field.id}`; if (field.type === 'checkbox') { return (
onChange(field.id, checked === true ? '1' : '0')} />
); } return (
{field.type === 'textarea' ? (