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