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