-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4139a8c
commit 7d54c58
Showing
7 changed files
with
214 additions
and
77 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
components/dashboard/src/data/auth-providers/create-org-auth-provider-mutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { getOrgAuthProvidersQueryKey } from "./org-auth-providers-query"; | ||
import { CreateAuthProviderRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb"; | ||
import { authProviderClient } from "../../service/public-api"; | ||
|
||
type CreateAuthProviderArgs = { | ||
provider: Pick<CreateAuthProviderRequest, "host" | "type"> & { | ||
clientId: string; | ||
clientSecret: string; | ||
orgId: string; | ||
}; | ||
}; | ||
export const useCreateOrgAuthProviderMutation = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: async ({ provider }: CreateAuthProviderArgs) => { | ||
const response = await authProviderClient.createAuthProvider( | ||
new CreateAuthProviderRequest({ | ||
owner: { case: "organizationId", value: provider.orgId }, | ||
host: provider.host, | ||
oauth2Config: { | ||
clientId: provider.clientId, | ||
clientSecret: provider.clientSecret, | ||
}, | ||
type: provider.type, | ||
}), | ||
); | ||
return response.authProvider!; | ||
}, | ||
onSuccess(provider) { | ||
const orgId = provider?.owner?.value; | ||
if (!orgId) { | ||
return; | ||
} | ||
|
||
queryClient.invalidateQueries({ queryKey: getOrgAuthProvidersQueryKey(orgId) }); | ||
}, | ||
}); | ||
}; |
26 changes: 26 additions & 0 deletions
26
components/dashboard/src/data/auth-providers/get-auth-providers-query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useQuery } from "@tanstack/react-query"; | ||
import { authProviderClient } from "../../service/public-api"; | ||
import { AuthProvider, GetAuthProviderRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb"; | ||
|
||
export const useGetAuthProviderQuery = (authProviderId: string | undefined) => { | ||
return useQuery<AuthProvider | undefined, Error>(getAuthProvidersQueryKey(authProviderId || ""), async () => { | ||
if (!authProviderId) { | ||
return; | ||
} | ||
const { authProvider } = await authProviderClient.getAuthProvider( | ||
new GetAuthProviderRequest({ | ||
authProviderId: authProviderId, | ||
}), | ||
); | ||
|
||
return authProvider; | ||
}); | ||
}; | ||
|
||
export const getAuthProvidersQueryKey = (authProviderId: string) => ["auth-provider", { authProviderId }]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
components/dashboard/src/data/auth-providers/update-org-auth-provider-mutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
import { getOrgAuthProvidersQueryKey } from "./org-auth-providers-query"; | ||
import { UpdateAuthProviderRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb"; | ||
import { authProviderClient } from "../../service/public-api"; | ||
|
||
type UpdateAuthProviderArgs = { | ||
provider: { | ||
id: string; | ||
clientId: string; | ||
clientSecret: string; | ||
}; | ||
}; | ||
export const useUpdateOrgAuthProviderMutation = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: async ({ provider }: UpdateAuthProviderArgs) => { | ||
const response = await authProviderClient.updateAuthProvider( | ||
new UpdateAuthProviderRequest({ | ||
authProviderId: provider.id, | ||
clientId: provider.clientId, | ||
clientSecret: provider.clientSecret, | ||
}), | ||
); | ||
return response.authProvider!; | ||
}, | ||
onSuccess(provider) { | ||
const orgId = provider?.owner?.value; | ||
if (!orgId) { | ||
return; | ||
} | ||
|
||
queryClient.invalidateQueries({ queryKey: getOrgAuthProvidersQueryKey(orgId) }); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.