Fix eslint issues in ZodFormField

This commit is contained in:
2025-08-05 19:21:09 +02:00
parent dacaca8594
commit 0846350d41

View File

@@ -7,8 +7,8 @@ import { getFieldType, basicFieldsConfig } from '@/lib/zodFormUtils'
interface ZodFormFieldProps { interface ZodFormFieldProps {
fieldKey: keyof CreateInstanceOptions fieldKey: keyof CreateInstanceOptions
value: any value: string | number | boolean | string[] | undefined
onChange: (key: keyof CreateInstanceOptions, value: any) => void onChange: (key: keyof CreateInstanceOptions, value: string | number | boolean | string[] | undefined) => void
} }
const ZodFormField: React.FC<ZodFormFieldProps> = ({ fieldKey, value, onChange }) => { const ZodFormField: React.FC<ZodFormFieldProps> = ({ fieldKey, value, onChange }) => {
@@ -18,7 +18,7 @@ const ZodFormField: React.FC<ZodFormFieldProps> = ({ fieldKey, value, onChange }
// Get type from Zod schema // Get type from Zod schema
const fieldType = getFieldType(fieldKey) const fieldType = getFieldType(fieldKey)
const handleChange = (newValue: any) => { const handleChange = (newValue: string | number | boolean | string[] | undefined) => {
onChange(fieldKey, newValue) onChange(fieldKey, newValue)
} }
@@ -29,7 +29,7 @@ const ZodFormField: React.FC<ZodFormFieldProps> = ({ fieldKey, value, onChange }
<div className="flex items-center space-x-2"> <div className="flex items-center space-x-2">
<Checkbox <Checkbox
id={fieldKey} id={fieldKey}
checked={value || false} checked={typeof value === 'boolean' ? value : false}
onCheckedChange={(checked) => handleChange(checked)} onCheckedChange={(checked) => handleChange(checked)}
/> />
<Label htmlFor={fieldKey} className="text-sm font-normal"> <Label htmlFor={fieldKey} className="text-sm font-normal">
@@ -52,11 +52,11 @@ const ZodFormField: React.FC<ZodFormFieldProps> = ({ fieldKey, value, onChange }
id={fieldKey} id={fieldKey}
type="number" type="number"
step="any" // This allows decimal numbers step="any" // This allows decimal numbers
value={value !== undefined ? value : ''} value={typeof value === 'string' || typeof value === 'number' ? value : ''}
onChange={(e) => { onChange={(e) => {
const numValue = e.target.value ? parseFloat(e.target.value) : undefined const numValue = e.target.value ? parseFloat(e.target.value) : undefined
// Only update if the parsed value is valid or the input is empty // Only update if the parsed value is valid or the input is empty
if (e.target.value === '' || !isNaN(numValue!)) { if (e.target.value === '' || (numValue !== undefined && !isNaN(numValue))) {
handleChange(numValue) handleChange(numValue)
} }
}} }}
@@ -105,7 +105,7 @@ const ZodFormField: React.FC<ZodFormFieldProps> = ({ fieldKey, value, onChange }
<Input <Input
id={fieldKey} id={fieldKey}
type="text" type="text"
value={value || ''} value={typeof value === 'string' || typeof value === 'number' ? value : ''}
onChange={(e) => handleChange(e.target.value || undefined)} onChange={(e) => handleChange(e.target.value || undefined)}
placeholder={config.placeholder} placeholder={config.placeholder}
/> />