完善认证功能,添加实名认证和回调处理逻辑

This commit is contained in:
2025-04-16 09:43:12 +08:00
parent 1f1f603523
commit d435d98887
8 changed files with 502 additions and 10 deletions

View File

@@ -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>