https://dev.kronoz.win/r/marzneshin.git
1import { useQuery } from "@tanstack/react-query";
2import { fetch } from "@marzneshin/utils";
3import { UsersQueryFetchKey } from ".";
4
5export interface UsersStatsResponse {
6 total: number;
7 active: number;
8 on_hold: number;
9 expired: number;
10 limited: number;
11 online: number;
12 recent_subscription_updates: string[]
13}
14
15export const UsersStatsDefault = {
16 total: 0,
17 active: 0,
18 on_hold: 0,
19 expired: 0,
20 limited: 0,
21 online: 0,
22 recent_subscription_updates: []
23}
24
25export async function fetchUsersStats(): Promise<UsersStatsResponse> {
26 return await fetch(`/system/stats/users`).then((result) => {
27 return result;
28 });
29}
30
31export const UsersStatsQueryFetchKey = "stats";
32
33export const useUsersStatsQuery = () => {
34 return useQuery({
35 queryKey: [UsersStatsQueryFetchKey, UsersQueryFetchKey],
36 queryFn: fetchUsersStats,
37 initialData: UsersStatsDefault
38 })
39}