mirror of
https://github.com/docmost/docmost.git
synced 2026-05-13 19:55:33 +08:00
641ce142df
* SCIM - init (EE) * accept db transaction * sync * Content parser support for scim+json * patch scimmy * sync * return early if userIds is empty * sync * SCIM db table * fixes * scim tokens * backfill * feat(audit): add scim token events * rename scim migration * fix * fix translation * cleanup
97 lines
2.8 KiB
TypeScript
97 lines
2.8 KiB
TypeScript
import { IPagination, QueryParams } from "@/lib/types.ts";
|
|
import {
|
|
keepPreviousData,
|
|
useMutation,
|
|
useQuery,
|
|
useQueryClient,
|
|
UseQueryResult,
|
|
} from "@tanstack/react-query";
|
|
import {
|
|
createScimToken,
|
|
getScimTokens,
|
|
revokeScimToken,
|
|
updateScimToken,
|
|
} from "@/ee/scim/services/scim-token-service";
|
|
import {
|
|
IScimToken,
|
|
ICreateScimTokenRequest,
|
|
IRevokeScimTokenRequest,
|
|
IUpdateScimTokenRequest,
|
|
} from "@/ee/scim/types/scim-token.types";
|
|
import { notifications } from "@mantine/notifications";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
export function useGetScimTokensQuery(
|
|
params?: QueryParams,
|
|
): UseQueryResult<IPagination<IScimToken>, Error> {
|
|
return useQuery({
|
|
queryKey: ["scim-token-list", params],
|
|
queryFn: () => getScimTokens(params),
|
|
placeholderData: keepPreviousData,
|
|
});
|
|
}
|
|
|
|
export function useCreateScimTokenMutation() {
|
|
const queryClient = useQueryClient();
|
|
const { t } = useTranslation();
|
|
|
|
return useMutation<IScimToken, Error, ICreateScimTokenRequest>({
|
|
mutationFn: (data) => createScimToken(data),
|
|
onSuccess: () => {
|
|
notifications.show({
|
|
message: t("{{credential}} created successfully", {
|
|
credential: t("SCIM token"),
|
|
}),
|
|
});
|
|
queryClient.invalidateQueries({
|
|
predicate: (item) =>
|
|
["scim-token-list"].includes(item.queryKey[0] as string),
|
|
});
|
|
},
|
|
onError: (error) => {
|
|
const errorMessage = error["response"]?.data?.message;
|
|
notifications.show({ message: errorMessage, color: "red" });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useUpdateScimTokenMutation() {
|
|
const queryClient = useQueryClient();
|
|
const { t } = useTranslation();
|
|
|
|
return useMutation<void, Error, IUpdateScimTokenRequest>({
|
|
mutationFn: (data) => updateScimToken(data),
|
|
onSuccess: () => {
|
|
notifications.show({ message: t("Updated successfully") });
|
|
queryClient.invalidateQueries({
|
|
predicate: (item) =>
|
|
["scim-token-list"].includes(item.queryKey[0] as string),
|
|
});
|
|
},
|
|
onError: (error) => {
|
|
const errorMessage = error["response"]?.data?.message;
|
|
notifications.show({ message: errorMessage, color: "red" });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useRevokeScimTokenMutation() {
|
|
const queryClient = useQueryClient();
|
|
const { t } = useTranslation();
|
|
|
|
return useMutation<void, Error, IRevokeScimTokenRequest>({
|
|
mutationFn: (data) => revokeScimToken(data),
|
|
onSuccess: () => {
|
|
notifications.show({ message: t("Revoked successfully") });
|
|
queryClient.invalidateQueries({
|
|
predicate: (item) =>
|
|
["scim-token-list"].includes(item.queryKey[0] as string),
|
|
});
|
|
},
|
|
onError: (error) => {
|
|
const errorMessage = error["response"]?.data?.message;
|
|
notifications.show({ message: errorMessage, color: "red" });
|
|
},
|
|
});
|
|
}
|