♻️ refactor: Clean up NodeForm and ServerForm components by removing unused functions and optimizing state management
This commit is contained in:
parent
6a3bb7016e
commit
10250d9e34
@ -62,11 +62,6 @@ const buildSchema = (t: ReturnType<typeof useTranslations>) =>
|
|||||||
|
|
||||||
export type NodeFormValues = z.infer<ReturnType<typeof buildSchema>>;
|
export type NodeFormValues = z.infer<ReturnType<typeof buildSchema>>;
|
||||||
|
|
||||||
async function getServers(): Promise<ServerRow[]> {
|
|
||||||
const { data } = await filterServerList({ page: 1, size: 1000 });
|
|
||||||
return (data?.data?.list || []) as ServerRow[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function NodeForm(props: {
|
export default function NodeForm(props: {
|
||||||
trigger: string;
|
trigger: string;
|
||||||
title: string;
|
title: string;
|
||||||
@ -147,7 +142,6 @@ export default function NodeForm(props: {
|
|||||||
if (!allowed.includes(form.getValues('protocol') as ProtocolName)) {
|
if (!allowed.includes(form.getValues('protocol') as ProtocolName)) {
|
||||||
form.setValue('protocol', '' as any);
|
form.setValue('protocol', '' as any);
|
||||||
}
|
}
|
||||||
// Do not auto-fill port here; handled in handleProtocolChange
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleProtocolChange(nextProto?: ProtocolName | null) {
|
function handleProtocolChange(nextProto?: ProtocolName | null) {
|
||||||
@ -164,15 +158,6 @@ export default function NodeForm(props: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submit(values: NodeFormValues) {
|
|
||||||
const ok = await onSubmit(values);
|
|
||||||
if (ok) {
|
|
||||||
form.reset();
|
|
||||||
setOpen(false);
|
|
||||||
}
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sheet open={open} onOpenChange={setOpen}>
|
<Sheet open={open} onOpenChange={setOpen}>
|
||||||
<SheetTrigger asChild>
|
<SheetTrigger asChild>
|
||||||
@ -310,14 +295,11 @@ export default function NodeForm(props: {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
onClick={form.handleSubmit(
|
onClick={form.handleSubmit(onSubmit, (errors) => {
|
||||||
async (vals) => submit(vals),
|
const key = Object.keys(errors)[0] as keyof typeof errors;
|
||||||
(errors) => {
|
if (key) toast.error(String(errors[key]?.message));
|
||||||
const key = Object.keys(errors)[0] as keyof typeof errors;
|
return false;
|
||||||
if (key) toast.error(String(errors[key]?.message));
|
})}
|
||||||
return false;
|
|
||||||
},
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
{t('confirm')}
|
{t('confirm')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -190,6 +190,8 @@ export const formSchema = z.object({
|
|||||||
protocols: z.array(protocolApiScheme),
|
protocols: z.array(protocolApiScheme),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type ServerFormValues = z.infer<typeof formSchema>;
|
||||||
|
|
||||||
export type ProtocolType = (typeof protocols)[number];
|
export type ProtocolType = (typeof protocols)[number];
|
||||||
|
|
||||||
export function getProtocolDefaultConfig(proto: ProtocolType) {
|
export function getProtocolDefaultConfig(proto: ProtocolType) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -109,7 +109,6 @@ export function ProtocolForm() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// API请求函数
|
|
||||||
const request = async (
|
const request = async (
|
||||||
pagination: { page: number; size: number },
|
pagination: { page: number; size: number },
|
||||||
filter: Record<string, unknown>,
|
filter: Record<string, unknown>,
|
||||||
@ -125,7 +124,6 @@ export function ProtocolForm() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// 表格列定义
|
|
||||||
const columns: ColumnDef<API.SubscribeApplication, any>[] = [
|
const columns: ColumnDef<API.SubscribeApplication, any>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: 'is_default',
|
accessorKey: 'is_default',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user