完善认证功能,添加实名认证和回调处理逻辑
This commit is contained in:
@@ -14,25 +14,31 @@ import {
|
||||
import {merge} from '@/lib/utils'
|
||||
import {Label} from '@/components/ui/label'
|
||||
|
||||
import {BaseSyntheticEvent, ComponentProps, createContext, ReactNode, useContext, useId} from 'react'
|
||||
import React, {BaseSyntheticEvent, ComponentProps, createContext, ReactNode, useContext, useId} from 'react'
|
||||
|
||||
type FormProps<T extends FieldValues> = {
|
||||
form: UseFormReturn<T>
|
||||
onSubmit: SubmitHandler<T>
|
||||
onSubmit?: SubmitHandler<T>
|
||||
onError?: SubmitErrorHandler<T>
|
||||
handler?: (e?: React.BaseSyntheticEvent) => Promise<void>
|
||||
} & Omit<ComponentProps<'form'>, 'onSubmit' | 'onError'>
|
||||
|
||||
function Form<T extends FieldValues>(rawProps: FormProps<T>) {
|
||||
|
||||
const {children, onSubmit, onError, ...props} = rawProps
|
||||
const {children, onSubmit, onError, handler, ...props} = rawProps
|
||||
const form = props.form
|
||||
|
||||
const handle = handler || form.handleSubmit(
|
||||
onSubmit || (_ => {}),
|
||||
onError,
|
||||
)
|
||||
|
||||
return (
|
||||
<FormProvider {...form}>
|
||||
<form {...props} onSubmit={event => {
|
||||
<form {...props} onSubmit={async event => {
|
||||
event.preventDefault()
|
||||
form.handleSubmit(onSubmit, onError)(event)
|
||||
event.stopPropagation()
|
||||
await handle(event)
|
||||
}}>
|
||||
{children}
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user