refactor: rewrite useSamlAuthProviders with RQ
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
import SamlAuthProvider from '../../models/saml-auth-provider.ee.js';
|
||||
|
||||
const listSamlAuthProviders = async () => {
|
||||
const providers = await SamlAuthProvider.query().where({ active: true });
|
||||
|
||||
return providers;
|
||||
};
|
||||
|
||||
export default listSamlAuthProviders;
|
@@ -14,7 +14,6 @@ import getSamlAuthProviderRoleMappings from './queries/get-saml-auth-provider-ro
|
||||
import getStepWithTestExecutions from './queries/get-step-with-test-executions.js';
|
||||
import getTrialStatus from './queries/get-trial-status.ee.js';
|
||||
import getUsers from './queries/get-users.js';
|
||||
import listSamlAuthProviders from './queries/list-saml-auth-providers.ee.js';
|
||||
import testConnection from './queries/test-connection.js';
|
||||
|
||||
const queryResolvers = {
|
||||
@@ -34,7 +33,6 @@ const queryResolvers = {
|
||||
getStepWithTestExecutions,
|
||||
getTrialStatus,
|
||||
getUsers,
|
||||
listSamlAuthProviders,
|
||||
testConnection,
|
||||
};
|
||||
|
||||
|
@@ -30,7 +30,6 @@ type Query {
|
||||
getSamlAuthProviderRoleMappings(id: String!): [SamlAuthProvidersRoleMapping]
|
||||
getTrialStatus: GetTrialStatus
|
||||
getUsers(limit: Int!, offset: Int!): UserConnection
|
||||
listSamlAuthProviders: [ListSamlAuthProvider]
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
@@ -642,13 +641,6 @@ type Usage {
|
||||
task: Int
|
||||
}
|
||||
|
||||
type ListSamlAuthProvider {
|
||||
id: String
|
||||
name: String
|
||||
issuer: String
|
||||
loginUrl: String
|
||||
}
|
||||
|
||||
type Permission {
|
||||
id: String
|
||||
action: String
|
||||
|
@@ -44,7 +44,6 @@ export const authenticationRules = {
|
||||
'*': isAuthenticatedRule,
|
||||
getConfig: allow,
|
||||
getNotifications: allow,
|
||||
listSamlAuthProviders: allow,
|
||||
},
|
||||
Mutation: {
|
||||
'*': isAuthenticatedRule,
|
||||
|
@@ -3,19 +3,25 @@ import Paper from '@mui/material/Paper';
|
||||
import Button from '@mui/material/Button';
|
||||
import Stack from '@mui/material/Stack';
|
||||
import Divider from '@mui/material/Divider';
|
||||
|
||||
import useSamlAuthProviders from 'hooks/useSamlAuthProviders.ee';
|
||||
import useFormatMessage from 'hooks/useFormatMessage';
|
||||
|
||||
function SsoProviders() {
|
||||
const formatMessage = useFormatMessage();
|
||||
const { providers, loading } = useSamlAuthProviders();
|
||||
if (!loading && providers.length === 0) return null;
|
||||
const { data, isLoading: isSamlAuthProvidersLoading } =
|
||||
useSamlAuthProviders();
|
||||
const providers = data?.data;
|
||||
|
||||
if (!isSamlAuthProvidersLoading && providers?.length === 0) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Divider>{formatMessage('loginPage.divider')}</Divider>
|
||||
|
||||
<Paper sx={{ px: 2, py: 4 }}>
|
||||
<Stack direction="column" gap={1}>
|
||||
{providers.map((provider) => (
|
||||
{providers?.map((provider) => (
|
||||
<Button
|
||||
key={provider.id}
|
||||
component="a"
|
||||
|
@@ -1,11 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
export const LIST_SAML_AUTH_PROVIDERS = gql`
|
||||
query ListSamlAuthProviders {
|
||||
listSamlAuthProviders {
|
||||
id
|
||||
name
|
||||
loginUrl
|
||||
issuer
|
||||
}
|
||||
}
|
||||
`;
|
18
packages/web/src/hooks/useAdminSamlAuthProviders.ee.js
Normal file
18
packages/web/src/hooks/useAdminSamlAuthProviders.ee.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useAdminSamlAuthProviders() {
|
||||
const query = useQuery({
|
||||
queryKey: ['adminSamlAuthProviders'],
|
||||
queryFn: async ({ signal }) => {
|
||||
const { data } = await api.get('/v1/admin/saml-auth-providers', {
|
||||
signal,
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
@@ -3,7 +3,7 @@ import { useMutation } from '@tanstack/react-query';
|
||||
import api from 'helpers/api';
|
||||
import React from 'react';
|
||||
|
||||
export default function useLazyApps({ appName } = {}, { onSuccess }) {
|
||||
export default function useLazyApps({ appName } = {}, { onSuccess } = {}) {
|
||||
const abortControllerRef = React.useRef(new AbortController());
|
||||
|
||||
React.useEffect(() => {
|
||||
|
@@ -1,9 +1,18 @@
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { LIST_SAML_AUTH_PROVIDERS } from 'graphql/queries/list-saml-auth-providers.ee';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import api from 'helpers/api';
|
||||
|
||||
export default function useSamlAuthProviders() {
|
||||
const { data, loading } = useQuery(LIST_SAML_AUTH_PROVIDERS);
|
||||
return {
|
||||
providers: data?.listSamlAuthProviders || [],
|
||||
loading,
|
||||
};
|
||||
const query = useQuery({
|
||||
queryKey: ['samlAuthProviders'],
|
||||
queryFn: async ({ signal }) => {
|
||||
const { data } = await api.get('/v1/saml-auth-providers', {
|
||||
signal,
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@@ -6,12 +6,14 @@ import useFormatMessage from 'hooks/useFormatMessage';
|
||||
import useSamlAuthProvider from 'hooks/useSamlAuthProvider';
|
||||
import SamlConfiguration from './SamlConfiguration';
|
||||
import RoleMappings from './RoleMappings';
|
||||
import useSamlAuthProviders from 'hooks/useSamlAuthProviders.ee';
|
||||
import useAdminSamlAuthProviders from 'hooks/useAdminSamlAuthProviders.ee';
|
||||
function AuthenticationPage() {
|
||||
const formatMessage = useFormatMessage();
|
||||
const { providers } = useSamlAuthProviders();
|
||||
const samlAuthProviderId = providers[0]?.id;
|
||||
const { data, loading: isProviderLoading } = useSamlAuthProvider({
|
||||
|
||||
const { data: adminSamlAuthProviders } = useAdminSamlAuthProviders();
|
||||
const samlAuthProviderId = adminSamlAuthProviders?.data?.[0].id;
|
||||
|
||||
const { data, isLoading: isProviderLoading } = useSamlAuthProvider({
|
||||
samlAuthProviderId,
|
||||
});
|
||||
const provider = data?.data;
|
||||
|
@@ -30,7 +30,7 @@ export default function EditUser() {
|
||||
const { userId } = useParams();
|
||||
const { data: userData, loading: isUserLoading } = useUser({ userId });
|
||||
const user = userData?.data;
|
||||
const { data, loading: isRolesLoading } = useRoles();
|
||||
const { data, isLoading: isRolesLoading } = useRoles();
|
||||
const roles = data?.data;
|
||||
const enqueueSnackbar = useEnqueueSnackbar();
|
||||
const navigate = useNavigate();
|
||||
|
@@ -63,7 +63,7 @@ function ProfileSettings() {
|
||||
optimisticResponse: {
|
||||
updateCurrentUser: {
|
||||
__typename: 'User',
|
||||
id: currentUser?.id,
|
||||
id: currentUser.id,
|
||||
fullName,
|
||||
email,
|
||||
},
|
||||
|
Reference in New Issue
Block a user