https://dev.kronoz.win/r/marzneshin.git
1import { queryOptions, useQuery } from "@tanstack/react-query";
2import { fetch } from "@marzneshin/common/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 });
18};
19
20export const useAdminQuery = ({ username }: { username: string }) => {
21 return useQuery({
22 queryKey: [AdminQueryFetchKey, username],
23 queryFn: fetchAdmin,
24 initialData: null,
25 });
26};