https://dev.kronoz.win/r/marzneshin.git
1import { queryOptions, useQuery } from "@tanstack/react-query";
2import { fetch } from "@marzneshin/utils";
3import type { AdminType } from "../types";
4
5export async function fetchAdmin({
6 queryKey,
7}: { queryKey: [string, string] }): Promise<AdminType> {
8 return fetch(`/admins/${queryKey[1]}`);
9}
10
11export const AdminQueryFetchKey = "admins";
12
13export const adminQueryOptions = ({ username }: { username: string }) => {
14 return queryOptions({
15 queryKey: [AdminQueryFetchKey, username],
16 queryFn: fetchAdmin,
17 initialData: null,
18 });
19};
20
21export const useAdminQuery = ({ username }: { username: string }) => {
22 return useQuery({
23 queryKey: [AdminQueryFetchKey, username],
24 queryFn: fetchAdmin,
25 initialData: null,
26 });
27};