fix(ui): 修复修改弹窗中 FormField 结构被破坏导致的上下文越界报错
This commit is contained in:
parent
a408cad494
commit
2395d792db
@ -47,6 +47,8 @@ interface Asset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const updateTransactionSchema = z.object({
|
const updateTransactionSchema = z.object({
|
||||||
|
assetId: z.string(),
|
||||||
|
txType: z.string(),
|
||||||
quantity: z.string().regex(/^-?\d+(\.\d+)?$/, '数量必须是数字'),
|
quantity: z.string().regex(/^-?\d+(\.\d+)?$/, '数量必须是数字'),
|
||||||
price: z.string().regex(/^-?\d+(\.\d+)?$/, '价格必须是数字'),
|
price: z.string().regex(/^-?\d+(\.\d+)?$/, '价格必须是数字'),
|
||||||
fee: z.string().regex(/^-?\d+(\.\d+)?$/, '手续费必须是数字').default('0'),
|
fee: z.string().regex(/^-?\d+(\.\d+)?$/, '手续费必须是数字').default('0'),
|
||||||
@ -85,6 +87,8 @@ export function UpdateTransactionDialog({
|
|||||||
const form = useForm<UpdateForm>({
|
const form = useForm<UpdateForm>({
|
||||||
resolver: zodResolver(updateTransactionSchema),
|
resolver: zodResolver(updateTransactionSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
|
assetId: '',
|
||||||
|
txType: '',
|
||||||
quantity: '',
|
quantity: '',
|
||||||
price: '',
|
price: '',
|
||||||
fee: '0',
|
fee: '0',
|
||||||
@ -96,6 +100,8 @@ export function UpdateTransactionDialog({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (transaction && open) {
|
if (transaction && open) {
|
||||||
form.reset({
|
form.reset({
|
||||||
|
assetId: transaction.assetId,
|
||||||
|
txType: transaction.txType,
|
||||||
quantity: transaction.quantity.toString(),
|
quantity: transaction.quantity.toString(),
|
||||||
price: transaction.price.toString(),
|
price: transaction.price.toString(),
|
||||||
fee: transaction.fee.toString(),
|
fee: transaction.fee.toString(),
|
||||||
@ -138,6 +144,10 @@ export function UpdateTransactionDialog({
|
|||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-4">
|
<form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-4">
|
||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="assetId"
|
||||||
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>标的资产</FormLabel>
|
<FormLabel>标的资产</FormLabel>
|
||||||
<Select disabled>
|
<Select disabled>
|
||||||
@ -154,7 +164,14 @@ export function UpdateTransactionDialog({
|
|||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="txType"
|
||||||
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>交易类型</FormLabel>
|
<FormLabel>交易类型</FormLabel>
|
||||||
<Select disabled>
|
<Select disabled>
|
||||||
@ -171,7 +188,10 @@ export function UpdateTransactionDialog({
|
|||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<FormField
|
<FormField
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user