fix: validate

pull/22338/head^2
zxhlyh 9 months ago
parent 3b7df2f9b6
commit 29035d333d

@ -70,25 +70,33 @@ const BaseForm = ({
return null return null
}, [formSchemas, fieldClassName, labelClassName, inputContainerClassName, inputClassName, disabled]) }, [formSchemas, fieldClassName, labelClassName, inputContainerClassName, inputClassName, disabled])
const renderFieldWrapper = useCallback((formSchema: FormSchema) => {
const {
name,
} = formSchema
return (
<form.Field
key={name}
name={name}
>
{renderField}
</form.Field>
)
}, [renderField, form])
if (!formSchemas?.length) if (!formSchemas?.length)
return null return null
return ( return (
<form <form
className={cn(formClassName)} className={cn(formClassName)}
onSubmit={(e) => {
e.preventDefault()
form?.handleSubmit()
}}
> >
{ {formSchemas.map(renderFieldWrapper)}
formSchemas.map((formSchema) => {
return (
<form.Field
key={formSchema.name}
name={formSchema.name}
>
{renderField}
</form.Field>
)
})
}
</form> </form>
) )
} }

@ -2,7 +2,10 @@ import type {
ForwardedRef, ForwardedRef,
ReactNode, ReactNode,
} from 'react' } from 'react'
import type { AnyFormApi } from '@tanstack/react-form' import type {
AnyFormApi,
FieldValidators,
} from '@tanstack/react-form'
export type TypeWithI18N<T = string> = { export type TypeWithI18N<T = string> = {
en_US: T en_US: T
@ -52,6 +55,7 @@ export type FormSchema = {
placeholder?: string | TypeWithI18N placeholder?: string | TypeWithI18N
options?: FormOption[] options?: FormOption[]
labelClassName?: string labelClassName?: string
validators?: FieldValidators<any, any, any, any, any, any, any, any, any, any>
} }
export type FormValues = Record<string, any> export type FormValues = Record<string, any>

@ -217,6 +217,7 @@ const AddOAuthButton = ({
disabled={disabled} disabled={disabled}
schemas={memorizedSchemas} schemas={memorizedSchemas}
onAuth={handleOAuth} onAuth={handleOAuth}
editValues={client_params}
/> />
) )
} }

@ -72,13 +72,21 @@ const ApiKeyModal = ({
...values ...values
} = store?.state.values } = store?.state.values
const isPristineSecretInputNames: string[] = [] const isPristineSecretInputNames: string[] = []
formSchemas.forEach((schema) => { for (let i = 0; i < formSchemas.length; i++) {
const schema = formSchemas[i]
if (schema.required && !values[schema.name]) {
notify({
type: 'error',
message: t('common.errorMsg.fieldRequired', { field: schema.name }),
})
return
}
if (schema.type === FormTypeEnum.secretInput) { if (schema.type === FormTypeEnum.secretInput) {
const fieldMeta = form?.getFieldMeta(schema.name) const fieldMeta = form?.getFieldMeta(schema.name)
if (fieldMeta?.isPristine) if (fieldMeta?.isPristine)
isPristineSecretInputNames.push(schema.name) isPristineSecretInputNames.push(schema.name)
} }
}) }
const transformedValues = transformFormSchemasSecretInput(isPristineSecretInputNames, values) const transformedValues = transformFormSchemasSecretInput(isPristineSecretInputNames, values)

@ -53,13 +53,21 @@ const OAuthClientSettings = ({
...values ...values
} = store?.state.values } = store?.state.values
const isPristineSecretInputNames: string[] = [] const isPristineSecretInputNames: string[] = []
schemas.forEach((schema) => { for (let i = 0; i < schemas.length; i++) {
const schema = schemas[i]
if (schema.required && !values[schema.name]) {
notify({
type: 'error',
message: t('common.errorMsg.fieldRequired', { field: schema.name }),
})
return
}
if (schema.type === FormTypeEnum.secretInput) { if (schema.type === FormTypeEnum.secretInput) {
const fieldMeta = form?.getFieldMeta(schema.name) const fieldMeta = form?.getFieldMeta(schema.name)
if (fieldMeta?.isPristine) if (fieldMeta?.isPristine)
isPristineSecretInputNames.push(schema.name) isPristineSecretInputNames.push(schema.name)
} }
}) }
const transformedValues = transformFormSchemasSecretInput(isPristineSecretInputNames, values) const transformedValues = transformFormSchemasSecretInput(isPristineSecretInputNames, values)

@ -282,8 +282,7 @@ const Authorized = ({
deleteCredentialId && ( deleteCredentialId && (
<Confirm <Confirm
isShow isShow
title='Are you sure?' title={t('datasetDocuments.list.delete.title')}
content='content'
onCancel={closeConfirm} onCancel={closeConfirm}
onConfirm={handleConfirm} onConfirm={handleConfirm}
/> />

Loading…
Cancel
Save