Path: blob/main/components/dashboard/src/teams/sso/OIDCClientListItem.tsx
2506 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 { OIDCClientConfig } from "@gitpod/public-api/lib/gitpod/experimental/v1/oidc_pb";7import { FC, useCallback, useMemo, useState } from "react";8import ConfirmationModal from "../../components/ConfirmationModal";9import { ContextMenuEntry } from "../../components/ContextMenu";10import { Item, ItemField, ItemFieldContextMenu, ItemFieldIcon } from "../../components/ItemsList";11import { useDeleteOIDCClientMutation } from "../../data/oidc-clients/delete-oidc-client-mutation";12import { OIDCClientConfigModal } from "./OIDCClientConfigModal";13import { useToast } from "../../components/toasts/Toasts";14import { ModalFooterAlert } from "../../components/Modal";15import Tooltip from "../../components/Tooltip";1617type Props = {18clientConfig: OIDCClientConfig;19hasActiveConfig: boolean;20onSaved: (configId: string) => void;21onVerify: (configId: string) => void;22onActivate: (configId: string) => void;23};24export const OIDCClientListItem: FC<Props> = ({ clientConfig, hasActiveConfig, onSaved, onVerify, onActivate }) => {25const { toast } = useToast();26const [showEditModal, setShowEditModal] = useState(false);27const [showDeleteConfirmation, setShowDeleteConfirmation] = useState(false);28const deleteOIDCClient = useDeleteOIDCClientMutation();2930const menuEntries = useMemo(() => {31const result: ContextMenuEntry[] = [32{33title: clientConfig.active ? "View" : "Edit",34onClick: () => setShowEditModal(true),35separator: true,36},37...(!clientConfig.verified38? [39{40title: "Verify",41onClick: () => onVerify(clientConfig.id),42separator: true,43},44]45: []),46...(!clientConfig.active && clientConfig.verified47? [48{49title: "Activate",50onClick: () => {51onActivate(clientConfig.id);52},53separator: true,54},55]56: []),57{58title: "Remove",59customFontStyle: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300",60onClick: () => setShowDeleteConfirmation(true),61},62];63return result;64}, [clientConfig.active, clientConfig.id, clientConfig.verified, onActivate, onVerify]);6566const deleteClient = useCallback(async () => {67try {68await deleteOIDCClient.mutateAsync({ clientId: clientConfig.id });69setShowDeleteConfirmation(false);70toast("The SSO configuration was deleted");71} catch (error) {72console.log(error);73}74}, [clientConfig.id, deleteOIDCClient, toast]);7576return (77<>78<Item>79<ItemFieldIcon>80<Tooltip content={clientConfig.active ? "Active" : clientConfig.verified ? "Verified" : "Inactive"}>81<div82className={83"rounded-full w-3 h-3 text-sm align-middle m-auto " +84(clientConfig.active85? "bg-green-500"86: clientConfig.verified87? "bg-kumquat-ripe"88: "bg-gray-400")89}90>91 92</div>93</Tooltip>94</ItemFieldIcon>95<ItemField className="flex flex-col flex-grow">96<span className="font-medium truncate overflow-ellipsis">{clientConfig.oidcConfig?.issuer}</span>97<span className="text-sm text-gray-500 break-all">{clientConfig.oauth2Config?.clientId}</span>98</ItemField>99<ItemFieldContextMenu menuEntries={menuEntries} />100</Item>101{showDeleteConfirmation && (102<ConfirmationModal103title="Remove SSO configuration"104areYouSureText="Are you sure you want to remove the following SSO configuration?"105children={{106name: clientConfig.oidcConfig?.issuer ?? "",107description: clientConfig.oauth2Config?.clientId ?? "",108}}109buttonText="Remove"110warningText={111clientConfig.active112? "Warning, you are about to remove the active SSO configuration. If you continue, SSO will be disabled for your organization and no one, including yourself, will be able to log in."113: ""114}115footerAlert={116deleteOIDCClient.isError ? (117<ModalFooterAlert type="danger">118There was a problem deleting the configuration119</ModalFooterAlert>120) : null121}122onClose={() => setShowDeleteConfirmation(false)}123onConfirm={deleteClient}124/>125)}126{showEditModal && (127<OIDCClientConfigModal128clientConfig={clientConfig}129onSaved={onSaved}130onClose={() => setShowEditModal(false)}131/>132)}133</>134);135};136137138