feat: improved form validation and model addition functionality
This commit is contained in:
parent
1bf147fa6a
commit
15fb605eb4
@ -41,22 +41,39 @@ const PopupContainer: React.FC<Props> = ({ title, provider, resolve }) => {
|
||||
resolve({})
|
||||
}
|
||||
|
||||
const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
|
||||
if (find(models, { id: values.id })) {
|
||||
Modal.error({ title: 'Error', content: 'Model ID already exists' })
|
||||
const onAddModel = (values: FieldType) => {
|
||||
const id = values.id.trim()
|
||||
|
||||
if (find(models, { id })) {
|
||||
window.message.error('Model ID already exists')
|
||||
return
|
||||
}
|
||||
|
||||
const model: Model = {
|
||||
id,
|
||||
provider: provider.id,
|
||||
id: values.id,
|
||||
name: values.name ? values.name : values.id.toUpperCase(),
|
||||
group: getDefaultGroupName(values.group || values.id)
|
||||
name: values.name ? values.name : id.toUpperCase(),
|
||||
group: getDefaultGroupName(values.group || id)
|
||||
}
|
||||
|
||||
addModel(model)
|
||||
|
||||
resolve(model)
|
||||
return true
|
||||
}
|
||||
|
||||
const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
|
||||
const id = values.id.trim().replaceAll(',', ',')
|
||||
|
||||
if (id.includes(',')) {
|
||||
const ids = id.split(',')
|
||||
ids.forEach((id) => onAddModel({ id, name: id } as FieldType))
|
||||
resolve({})
|
||||
return
|
||||
}
|
||||
|
||||
if (onAddModel(values)) {
|
||||
resolve({})
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user