Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/teams/sso/ActivateConfigModal.tsx
2501 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { FC, useCallback } from "react";
8
import ConfirmationModal from "../../components/ConfirmationModal";
9
import { useOIDCClientsQuery } from "../../data/oidc-clients/oidc-clients-query";
10
import { useActivateOIDCClientMutation } from "../../data/oidc-clients/activate-oidc-client-mutation";
11
import { useToast } from "../../components/toasts/Toasts";
12
import { ModalFooterAlert } from "../../components/Modal";
13
14
type Props = {
15
configId: string;
16
hasActiveConfig: boolean;
17
onClose: () => void;
18
};
19
export const ActivateConfigModal: FC<Props> = ({ configId, hasActiveConfig, onClose }) => {
20
const { toast } = useToast();
21
const { data } = useOIDCClientsQuery();
22
const config = (data || []).find((c) => c.id === configId);
23
const activateClient = useActivateOIDCClientMutation();
24
25
const handleActivateClient = useCallback(async () => {
26
if (!config) {
27
return;
28
}
29
30
try {
31
await activateClient.mutateAsync({ id: config.id });
32
33
toast("Single sign-on configuration was activated.");
34
onClose();
35
} catch (e) {}
36
}, [activateClient, config, onClose, toast]);
37
38
// We should already have the config in all the scenarios we show this modal. If we don't, wait for it.
39
if (!config) {
40
return null;
41
}
42
43
return (
44
<ConfirmationModal
45
title="Activate SSO configuration"
46
areYouSureText="Are you sure you want to activate the following SSO configuration?"
47
children={{
48
name: config.oidcConfig?.issuer ?? "",
49
description: config.oauth2Config?.clientId ?? "",
50
}}
51
buttonText="Activate"
52
buttonType="default"
53
warningText={
54
hasActiveConfig
55
? "Activating this SSO configuration will also deactivate the currently active configuration."
56
: ""
57
}
58
footerAlert={
59
activateClient.isError ? (
60
<ModalFooterAlert type="danger">There was a problem activating the configuration</ModalFooterAlert>
61
) : null
62
}
63
onClose={onClose}
64
onConfirm={handleActivateClient}
65
/>
66
);
67
};
68
69