fix(ui): wrong form initial values

This commit is contained in:
Fu Diwei
2025-01-05 00:47:27 +08:00
parent 61843a4997
commit ddb6a88392
12 changed files with 38 additions and 29 deletions

View File

@@ -1,6 +1,5 @@
import { forwardRef, useEffect, useImperativeHandle, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useCreation } from "ahooks";
import { Form, type FormInstance, Input } from "antd";
import { createSchemaFieldRule } from "antd-zod";
import { z } from "zod";
@@ -8,7 +7,7 @@ import { z } from "zod";
import AccessProviderSelect from "@/components/provider/AccessProviderSelect";
import { type AccessModel } from "@/domain/access";
import { ACCESS_PROVIDERS } from "@/domain/provider";
import { useAntdForm } from "@/hooks";
import { useAntdForm, useAntdFormName } from "@/hooks";
import AccessEditFormACMEHttpReqConfig from "./AccessEditFormACMEHttpReqConfig";
import AccessEditFormAWSConfig from "./AccessEditFormAWSConfig";
@@ -71,7 +70,7 @@ const AccessEditForm = forwardRef<AccessEditFormInstance, AccessEditFormProps>((
}, [initialValues?.provider]);
const [configFormInst] = Form.useForm();
const configFormName = useCreation(() => `accessEditForm_config${Math.random().toString(36).substring(2, 10)}${new Date().getTime()}`, []);
const configFormName = useAntdFormName({ form: configFormInst, name: "accessEditConfigForm" });
const configFormComponent = useMemo(() => {
/*
注意:如果追加新的子组件,请保持以 ASCII 排序。

View File

@@ -1,9 +1,8 @@
import { forwardRef, useImperativeHandle, useMemo } from "react";
import { useCreation } from "ahooks";
import { Form, type FormInstance } from "antd";
import { NOTIFY_CHANNELS, type NotifyChannelsSettingsContent } from "@/domain/settings";
import { useAntdForm } from "@/hooks";
import { useAntdForm, useAntdFormName } from "@/hooks";
import NotifyChannelEditFormBarkFields from "./NotifyChannelEditFormBarkFields";
import NotifyChannelEditFormDingTalkFields from "./NotifyChannelEditFormDingTalkFields";
@@ -35,8 +34,8 @@ const NotifyChannelEditForm = forwardRef<NotifyChannelEditFormInstance, NotifyCh
({ className, style, channel, disabled, initialValues, onValuesChange }, ref) => {
const { form: formInst, formProps } = useAntdForm({
initialValues: initialValues,
name: "notifyChannelEditForm",
});
const formName = useCreation(() => `notifyChannelEditForm_${Math.random().toString(36).substring(2, 10)}${new Date().getTime()}`, []);
const formFieldsComponent = useMemo(() => {
/*
注意:如果追加新的子组件,请保持以 ASCII 排序。
@@ -81,16 +80,7 @@ const NotifyChannelEditForm = forwardRef<NotifyChannelEditFormInstance, NotifyCh
});
return (
<Form
{...formProps}
className={className}
style={style}
form={formInst}
disabled={disabled}
name={formName}
layout="vertical"
onValuesChange={handleFormChange}
>
<Form {...formProps} className={className} style={style} form={formInst} disabled={disabled} layout="vertical" onValuesChange={handleFormChange}>
{formFieldsComponent}
</Form>
);

View File

@@ -52,7 +52,9 @@ const ApplyNodeForm = ({ node }: ApplyNodeFormProps) => {
providerAccessId: z
.string({ message: t("workflow_node.apply.form.provider_access.placeholder") })
.min(1, t("workflow_node.apply.form.provider_access.placeholder")),
keyAlgorithm: z.string().nullish(),
keyAlgorithm: z
.string({ message: t("workflow_node.apply.form.key_algorithm.placeholder") })
.nonempty(t("workflow_node.apply.form.key_algorithm.placeholder")),
nameservers: z
.string()
.nullish()
@@ -76,6 +78,7 @@ const ApplyNodeForm = ({ node }: ApplyNodeFormProps) => {
formPending,
formProps,
} = useAntdForm<z.infer<typeof formSchema>>({
name: "workflowApplyNodeForm",
initialValues: (node?.config as WorkflowNodeConfigForApply) ?? initFormModel(),
onSubmit: async (values) => {
await formInst.validateFields();
@@ -305,7 +308,7 @@ const FormFieldEmailSelect = ({
const handleSearch = (text: string) => {
const temp = emailsToOptions();
if (text) {
if (text?.trim()) {
if (temp.every((option) => option.label !== text)) {
temp.unshift({ label: text, value: text });
}

View File

@@ -67,6 +67,7 @@ const DeployNodeForm = ({ node }: DeployFormProps) => {
formPending,
formProps,
} = useAntdForm<z.infer<typeof formSchema>>({
name: "workflowDeployNodeForm",
initialValues: (node?.config as WorkflowNodeConfigForDeploy) ?? initFormModel(),
onSubmit: async (values) => {
await formInst.validateFields();

View File

@@ -57,6 +57,7 @@ const NotifyNodeForm = ({ node }: NotifyNodeFormProps) => {
formPending,
formProps,
} = useAntdForm<z.infer<typeof formSchema>>({
name: "workflowNotifyNodeForm",
initialValues: (node?.config as WorkflowNodeConfigForNotify) ?? initFormModel(),
onSubmit: async (values) => {
await formInst.validateFields();

View File

@@ -54,6 +54,7 @@ const StartNodeForm = ({ node }: StartNodeFormProps) => {
formPending,
formProps,
} = useAntdForm<z.infer<typeof formSchema>>({
name: "workflowStartNodeForm",
initialValues: (node?.config as WorkflowNodeConfigForStart) ?? initFormModel(),
onSubmit: async (values) => {
await formInst.validateFields();