This commit is contained in:
 Илья Шалонин 2025-10-29 13:43:43 +05:00
commit 8538ab969a
434 changed files with 44051 additions and 0 deletions

View file

@ -0,0 +1,82 @@
import { apiClient } from "@shared/lib/api-client";
import { createQueryKeyWithParams } from "@shared/lib/query-client";
import { keepPreviousData, useQuery } from "@tanstack/react-query";
/*
* Admin users
*/
type FetchAdminUsersParams = {
itemsPerPage: number;
currentPage: number;
searchTerm: string;
};
export const adminUsersQueryKey = ["admin", "users"];
export const fetchAdminUsers = async ({
itemsPerPage,
currentPage,
searchTerm,
}: FetchAdminUsersParams) => {
const response = await apiClient.admin.users.$get({
query: {
limit: itemsPerPage.toString(),
offset: ((currentPage - 1) * itemsPerPage).toString(),
query: searchTerm,
},
});
if (!response.ok) {
throw new Error("Could not fetch users");
}
return response.json();
};
export const useAdminUsersQuery = (params: FetchAdminUsersParams) => {
return useQuery({
queryKey: createQueryKeyWithParams(adminUsersQueryKey, params),
queryFn: () => fetchAdminUsers(params),
retry: false,
refetchOnWindowFocus: false,
placeholderData: keepPreviousData,
});
};
/*
* Admin organizations
*/
type FetchAdminOrganizationsParams = {
itemsPerPage: number;
currentPage: number;
searchTerm: string;
};
export const adminOrganizationsQueryKey = ["admin", "organizations"];
export const fetchAdminOrganizations = async ({
itemsPerPage,
currentPage,
searchTerm,
}: FetchAdminOrganizationsParams) => {
const response = await apiClient.admin.organizations.$get({
query: {
limit: itemsPerPage.toString(),
offset: ((currentPage - 1) * itemsPerPage).toString(),
query: searchTerm,
},
});
if (!response.ok) {
throw new Error("Could not fetch organizations");
}
return response.json();
};
export const useAdminOrganizationsQuery = (
params: FetchAdminOrganizationsParams,
) => {
return useQuery({
queryKey: createQueryKeyWithParams(adminOrganizationsQueryKey, params),
queryFn: () => fetchAdminOrganizations(params),
retry: false,
refetchOnWindowFocus: false,
placeholderData: keepPreviousData,
});
};

View file

@ -0,0 +1,5 @@
import { joinRelativeURL } from "ufo";
export function getAdminPath(path: string) {
return joinRelativeURL("/app/admin", path);
}