mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-18 17:31:55 +08:00
refactor(ui): clean code
This commit is contained in:
parent
1184e52ba9
commit
4008c2bfd5
@ -40,7 +40,11 @@ export type AccessEditFormProps = {
|
|||||||
onValuesChange?: (values: AccessEditFormFieldValues) => void;
|
onValuesChange?: (values: AccessEditFormFieldValues) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AccessEditFormInstance = FormInstance<AccessEditFormFieldValues>;
|
export type AccessEditFormInstance = {
|
||||||
|
getFieldsValue: () => ReturnType<FormInstance<AccessEditFormFieldValues>["getFieldsValue"]>;
|
||||||
|
resetFields: FormInstance<AccessEditFormFieldValues>["resetFields"];
|
||||||
|
validateFields: FormInstance<AccessEditFormFieldValues>["validateFields"];
|
||||||
|
};
|
||||||
|
|
||||||
const AccessEditForm = forwardRef<AccessEditFormInstance, AccessEditFormProps>(({ className, style, disabled, initialValues, preset, onValuesChange }, ref) => {
|
const AccessEditForm = forwardRef<AccessEditFormInstance, AccessEditFormProps>(({ className, style, disabled, initialValues, preset, onValuesChange }, ref) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -131,26 +135,12 @@ const AccessEditForm = forwardRef<AccessEditFormInstance, AccessEditFormProps>((
|
|||||||
|
|
||||||
useImperativeHandle(ref, () => {
|
useImperativeHandle(ref, () => {
|
||||||
return {
|
return {
|
||||||
getFieldValue: (name) => formInst.getFieldValue(name),
|
getFieldsValue: () => {
|
||||||
getFieldsValue: (...args) => {
|
return formInst.getFieldsValue(true);
|
||||||
if (Array.from(args).length === 0) {
|
},
|
||||||
return formInst.getFieldsValue(true);
|
resetFields: (fields) => {
|
||||||
}
|
return formInst.resetFields(fields);
|
||||||
|
|
||||||
return formInst.getFieldsValue(args[0] as any, args[1] as any);
|
|
||||||
},
|
},
|
||||||
getFieldError: (name) => formInst.getFieldError(name),
|
|
||||||
getFieldsError: (nameList) => formInst.getFieldsError(nameList),
|
|
||||||
getFieldWarning: (name) => formInst.getFieldWarning(name),
|
|
||||||
isFieldsTouched: (nameList, allFieldsTouched) => formInst.isFieldsTouched(nameList, allFieldsTouched),
|
|
||||||
isFieldTouched: (name) => formInst.isFieldTouched(name),
|
|
||||||
isFieldValidating: (name) => formInst.isFieldValidating(name),
|
|
||||||
isFieldsValidating: (nameList) => formInst.isFieldsValidating(nameList),
|
|
||||||
resetFields: (fields) => formInst.resetFields(fields),
|
|
||||||
setFields: (fields) => formInst.setFields(fields),
|
|
||||||
setFieldValue: (name, value) => formInst.setFieldValue(name, value),
|
|
||||||
setFieldsValue: (values) => formInst.setFieldsValue(values),
|
|
||||||
submit: () => formInst.submit(),
|
|
||||||
validateFields: (nameList, config) => {
|
validateFields: (nameList, config) => {
|
||||||
const t1 = formInst.validateFields(nameList, config);
|
const t1 = formInst.validateFields(nameList, config);
|
||||||
const t2 = configFormInst.validateFields(undefined, config);
|
const t2 = configFormInst.validateFields(undefined, config);
|
||||||
|
@ -62,13 +62,13 @@ const AccessEditModal = ({ data, loading, trigger, preset, ...props }: AccessEdi
|
|||||||
throw "Invalid props: `data`";
|
throw "Invalid props: `data`";
|
||||||
}
|
}
|
||||||
|
|
||||||
await createAccess(formRef.current!.getFieldsValue(true) as AccessModel);
|
await createAccess(formRef.current!.getFieldsValue() as AccessModel);
|
||||||
} else if (preset === "edit") {
|
} else if (preset === "edit") {
|
||||||
if (!data?.id) {
|
if (!data?.id) {
|
||||||
throw "Invalid props: `data`";
|
throw "Invalid props: `data`";
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateAccess({ ...data, ...formRef.current!.getFieldsValue(true) } as AccessModel);
|
await updateAccess({ ...data, ...formRef.current!.getFieldsValue() } as AccessModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
@ -24,7 +24,11 @@ export type NotifyChannelEditFormProps = {
|
|||||||
onValuesChange?: (values: NotifyChannelEditFormFieldValues) => void;
|
onValuesChange?: (values: NotifyChannelEditFormFieldValues) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NotifyChannelEditFormInstance = FormInstance;
|
export type NotifyChannelEditFormInstance = {
|
||||||
|
getFieldsValue: () => ReturnType<FormInstance<NotifyChannelEditFormFieldValues>["getFieldsValue"]>;
|
||||||
|
resetFields: FormInstance<NotifyChannelEditFormFieldValues>["resetFields"];
|
||||||
|
validateFields: FormInstance<NotifyChannelEditFormFieldValues>["validateFields"];
|
||||||
|
};
|
||||||
|
|
||||||
const NotifyChannelEditForm = forwardRef<NotifyChannelEditFormInstance, NotifyChannelEditFormProps>(
|
const NotifyChannelEditForm = forwardRef<NotifyChannelEditFormInstance, NotifyChannelEditFormProps>(
|
||||||
({ className, style, channel, disabled, initialValues, onValuesChange }, ref) => {
|
({ className, style, channel, disabled, initialValues, onValuesChange }, ref) => {
|
||||||
@ -63,27 +67,15 @@ const NotifyChannelEditForm = forwardRef<NotifyChannelEditFormInstance, NotifyCh
|
|||||||
|
|
||||||
useImperativeHandle(ref, () => {
|
useImperativeHandle(ref, () => {
|
||||||
return {
|
return {
|
||||||
getFieldValue: (name) => formInst.getFieldValue(name),
|
getFieldsValue: () => {
|
||||||
getFieldsValue: (...args) => {
|
return formInst.getFieldsValue(true);
|
||||||
if (Array.from(args).length === 0) {
|
},
|
||||||
return formInst.getFieldsValue(true);
|
resetFields: (fields) => {
|
||||||
}
|
return formInst.resetFields(fields);
|
||||||
|
},
|
||||||
return formInst.getFieldsValue(args[0] as any, args[1] as any);
|
validateFields: (nameList, config) => {
|
||||||
|
return formInst.validateFields(nameList, config);
|
||||||
},
|
},
|
||||||
getFieldError: (name) => formInst.getFieldError(name),
|
|
||||||
getFieldsError: (nameList) => formInst.getFieldsError(nameList),
|
|
||||||
getFieldWarning: (name) => formInst.getFieldWarning(name),
|
|
||||||
isFieldsTouched: (nameList, allFieldsTouched) => formInst.isFieldsTouched(nameList, allFieldsTouched),
|
|
||||||
isFieldTouched: (name) => formInst.isFieldTouched(name),
|
|
||||||
isFieldValidating: (name) => formInst.isFieldValidating(name),
|
|
||||||
isFieldsValidating: (nameList) => formInst.isFieldsValidating(nameList),
|
|
||||||
resetFields: (fields) => formInst.resetFields(fields),
|
|
||||||
setFields: (fields) => formInst.setFields(fields),
|
|
||||||
setFieldValue: (name, value) => formInst.setFieldValue(name, value),
|
|
||||||
setFieldsValue: (values) => formInst.setFieldsValue(values),
|
|
||||||
validateFields: (nameList, config) => formInst.validateFields(nameList, config),
|
|
||||||
submit: () => formInst.submit(),
|
|
||||||
} as NotifyChannelEditFormInstance;
|
} as NotifyChannelEditFormInstance;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ const NotifyChannel = ({ className, style, channel }: NotifyChannelProps) => {
|
|||||||
await channelFormRef.current!.validateFields();
|
await channelFormRef.current!.validateFields();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setChannel(channel, channelFormRef.current!.getFieldsValue(true));
|
setChannel(channel, channelFormRef.current!.getFieldsValue());
|
||||||
setChannelFormChanged(false);
|
setChannelFormChanged(false);
|
||||||
|
|
||||||
messageApi.success(t("common.text.operation_succeeded"));
|
messageApi.success(t("common.text.operation_succeeded"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user