Files
docmost/apps/client/src/ee/security/queries/security-query.ts
T
Philip Okugbe 78b1c1a453 feat: switch to cursor pagination (#1884)
* add cursor pagination function

* support custom order modifier
* refactor returned object

* feat(db): migrate paginated endpoints to cursor-based pagination

* sync

* support hasPrevPage boolean

* feat(client): migrate pagination from offset to cursor-based

* support beforeCursor/prevCursor

* wrap search results in items array for API consistency
2026-01-30 19:28:54 +00:00

90 lines
2.5 KiB
TypeScript

import {
useMutation,
useQuery,
useQueryClient,
UseQueryResult,
} from "@tanstack/react-query";
import {
createSsoProvider,
deleteSsoProvider,
getSsoProviderById,
getSsoProviders,
updateSsoProvider,
} from "@/ee/security/services/security-service.ts";
import { notifications } from "@mantine/notifications";
import { IAuthProvider } from "@/ee/security/types/security.types.ts";
import { IPagination } from "@/lib/types.ts";
export function useGetSsoProviders(): UseQueryResult<IPagination<IAuthProvider>, Error> {
return useQuery({
queryKey: ["sso-providers"],
queryFn: () => getSsoProviders(),
staleTime: 5 * 60 * 1000,
});
}
export function useSsoProvider(
providerId: string,
): UseQueryResult<IAuthProvider, Error> {
return useQuery({
queryKey: ["sso-provider", providerId],
queryFn: () => getSsoProviderById({ providerId }),
enabled: !!providerId,
staleTime: 5 * 60 * 1000,
});
}
export function useCreateSsoProviderMutation() {
const queryClient = useQueryClient();
return useMutation<any, Error, Partial<IAuthProvider>>({
mutationFn: (data: Partial<IAuthProvider>) => createSsoProvider(data),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ["sso-providers"],
});
},
onError: (error) => {
const errorMessage = error["response"]?.data?.message;
notifications.show({ message: errorMessage, color: "red" });
},
});
}
export function useUpdateSsoProviderMutation() {
const queryClient = useQueryClient();
return useMutation<any, Error, Partial<IAuthProvider>>({
mutationFn: (data: Partial<IAuthProvider>) => updateSsoProvider(data),
onSuccess: (data, variables) => {
notifications.show({ message: "Updated successfully" });
queryClient.invalidateQueries({
queryKey: ["sso-providers"],
});
},
onError: (error) => {
const errorMessage = error["response"]?.data?.message;
notifications.show({ message: errorMessage, color: "red" });
},
});
}
export function useDeleteSsoProviderMutation() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (providerId: string) => deleteSsoProvider({ providerId }),
onSuccess: (data, variables) => {
notifications.show({ message: "Deleted successfully" });
queryClient.invalidateQueries({
queryKey: ["sso-providers"],
});
},
onError: (error) => {
const errorMessage = error["response"]?.data?.message;
notifications.show({ message: errorMessage, color: "red" });
},
});
}