https://dev.kronoz.win/r/marzneshin.git
1import { useQuery } from "@tanstack/react-query";
2import { fetch } from "@marzneshin/common/utils";
3import type { ServiceType } from "../types";
4
5export async function fetchService({
6 queryKey,
7}: { queryKey: [string, number] }): Promise<ServiceType> {
8 return await fetch(`/services/${queryKey[1]}`).then(result => {
9 return {
10 ...result,
11 users: result.user_ids,
12 inbounds: result.inbound_ids,
13 };
14 });
15}
16
17const ServiceQueryFetchKey = "services";
18
19export const useServiceQuery = ({ serviceId }: { serviceId: number }) => {
20 return useQuery({
21 queryKey: [ServiceQueryFetchKey, serviceId],
22 queryFn: fetchService,
23 initialData: null,
24 });
25};