mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-04 16:34:52 +03:00
fix(groups): page client dialogs and submit server-resolved scopes
Keep group client tables and bulk requests bounded with paged queries, frozen selections, and a streamed subscription export. Reuse existing bulk mutations and preserve the explicit-email contracts.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { withBasePath } from '@/api/http-init';
|
||||
import { keys } from '@/api/queryKeys';
|
||||
import { GroupClientPageSchema, type GroupClientSelection } from '@/generated/zod';
|
||||
import { HttpUtil } from '@/utils';
|
||||
import { parseMsg } from '@/utils/zodValidate';
|
||||
|
||||
const PAGE_ENDPOINT = '/panel/api/clients/groups/clientPage';
|
||||
export const GROUP_CLIENT_PAGE_SIZE = 100;
|
||||
export const MAX_GROUP_EXCLUSIONS = 1000;
|
||||
|
||||
export type { GroupClientSelection };
|
||||
export type GroupClientMode = 'add' | 'remove' | 'links';
|
||||
export type GroupBulkScope = { group: string; scopeToken?: string };
|
||||
|
||||
type PageParams = {
|
||||
group: string;
|
||||
mode: GroupClientMode;
|
||||
page?: number;
|
||||
search?: string;
|
||||
freeze?: boolean;
|
||||
scopeSearch?: string;
|
||||
maxId?: number;
|
||||
};
|
||||
|
||||
export async function fetchGroupClients(params: PageParams, signal?: AbortSignal) {
|
||||
const response = await HttpUtil.get(PAGE_ENDPOINT, params, { signal, silent: true });
|
||||
const result = parseMsg(response, GroupClientPageSchema, 'clients/groups/clientPage');
|
||||
if (!result.success || !result.obj) throw new Error(result.msg);
|
||||
return result.obj;
|
||||
}
|
||||
|
||||
export function useGroupClientPage(params: PageParams, enabled: boolean) {
|
||||
return useQuery({
|
||||
queryKey: [...keys.clients.root(), 'groupClientPage', params],
|
||||
queryFn: ({ signal }) => fetchGroupClients(params, signal),
|
||||
enabled,
|
||||
gcTime: 0,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function groupSubscriptionExportPath(group: string) {
|
||||
return withBasePath(
|
||||
'/panel/api/clients/groups/subLinks/export?' + new URLSearchParams({ group }).toString(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user