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