♻️ 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>>;
|
||||
|
||||
async function getServers(): Promise<ServerRow[]> {
|
||||
const { data } = await filterServerList({ page: 1, size: 1000 });
|
||||
return (data?.data?.list || []) as ServerRow[];
|
||||
}
|
||||
|
||||
export default function NodeForm(props: {
|
||||
trigger: string;
|
||||
title: string;
|
||||
@ -147,7 +142,6 @@ export default function NodeForm(props: {
|
||||
if (!allowed.includes(form.getValues('protocol') as ProtocolName)) {
|
||||
form.setValue('protocol', '' as any);
|
||||
}
|
||||
// Do not auto-fill port here; handled in handleProtocolChange
|
||||
}
|
||||
|
||||
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 (
|
||||
<Sheet open={open} onOpenChange={setOpen}>
|
||||
<SheetTrigger asChild>
|
||||
@ -310,14 +295,11 @@ export default function NodeForm(props: {
|
||||
</Button>
|
||||
<Button
|
||||
disabled={loading}
|
||||
onClick={form.handleSubmit(
|
||||
async (vals) => submit(vals),
|
||||
(errors) => {
|
||||
const key = Object.keys(errors)[0] as keyof typeof errors;
|
||||
if (key) toast.error(String(errors[key]?.message));
|
||||
return false;
|
||||
},
|
||||
)}
|
||||
onClick={form.handleSubmit(onSubmit, (errors) => {
|
||||
const key = Object.keys(errors)[0] as keyof typeof errors;
|
||||
if (key) toast.error(String(errors[key]?.message));
|
||||
return false;
|
||||
})}
|
||||
>
|
||||
{t('confirm')}
|
||||
</Button>
|
||||
|
||||
@ -190,6 +190,8 @@ export const formSchema = z.object({
|
||||
protocols: z.array(protocolApiScheme),
|
||||
});
|
||||
|
||||
export type ServerFormValues = z.infer<typeof formSchema>;
|
||||
|
||||
export type ProtocolType = (typeof protocols)[number];
|
||||
|
||||
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 (
|
||||
pagination: { page: number; size: number },
|
||||
filter: Record<string, unknown>,
|
||||
@ -125,7 +124,6 @@ export function ProtocolForm() {
|
||||
};
|
||||
};
|
||||
|
||||
// 表格列定义
|
||||
const columns: ColumnDef<API.SubscribeApplication, any>[] = [
|
||||
{
|
||||
accessorKey: 'is_default',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user