mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-05 16:45:14 +03:00
1ac11c7783
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.
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
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(),
|
|
);
|
|
}
|