Files
automatisch/packages/web/src/hooks/useSamlAuthProviderRoleMappings.ts
2024-01-15 13:30:48 +01:00

30 lines
815 B
TypeScript

import * as React from 'react';
import { useLazyQuery } from '@apollo/client';
import { TSamlAuthProviderRole } from 'types';
import { GET_SAML_AUTH_PROVIDER_ROLE_MAPPINGS } from 'graphql/queries/get-saml-auth-provider-role-mappings';
type QueryResponse = {
getSamlAuthProviderRoleMappings: TSamlAuthProviderRole[];
};
export default function useSamlAuthProviderRoleMappings(providerId?: string) {
const [getSamlAuthProviderRoleMappings, { data, loading }] =
useLazyQuery<QueryResponse>(GET_SAML_AUTH_PROVIDER_ROLE_MAPPINGS);
React.useEffect(() => {
if (providerId) {
getSamlAuthProviderRoleMappings({
variables: {
id: providerId,
},
});
}
}, [providerId]);
return {
roleMappings: data?.getSamlAuthProviderRoleMappings || [],
loading,
};
}