Path: blob/main/components/dashboard/src/teams/git-integrations/GitIntegrationListItem.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 { FunctionComponent, useCallback, useMemo, useState } from "react";7import ConfirmationModal from "../../components/ConfirmationModal";8import { ContextMenuEntry } from "../../components/ContextMenu";9import { Item, ItemField, ItemFieldContextMenu, ItemFieldIcon } from "../../components/ItemsList";10import { useDeleteOrgAuthProviderMutation } from "../../data/auth-providers/delete-org-auth-provider-mutation";11import { GitIntegrationModal } from "./GitIntegrationModal";12import { ModalFooterAlert } from "../../components/Modal";13import { useToast } from "../../components/toasts/Toasts";14import { useListOrganizationMembers } from "../../data/organizations/members-query";15import { AuthProvider } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";16import { toAuthProviderLabel } from "../../provider-utils";1718type Props = {19provider: AuthProvider;20};21export const GitIntegrationListItem: FunctionComponent<Props> = ({ provider }) => {22const [showEditModal, setShowEditModal] = useState(false);23const [showDeleteConfirmation, setShowDeleteConfirmation] = useState(false);24const deleteAuthProvider = useDeleteOrgAuthProviderMutation();25const members = useListOrganizationMembers().data || [];26const { toast } = useToast();2728const memberCount = members.length ?? 1;2930const menuEntries = useMemo(() => {31const result: ContextMenuEntry[] = [];32result.push({33title: provider.verified ? "Edit" : "Activate",34onClick: () => setShowEditModal(true),35separator: true,36});37result.push({38title: "Remove",39customFontStyle: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300",40onClick: () => setShowDeleteConfirmation(true),41});42return result;43}, [provider.verified]);4445const deleteProvider = useCallback(async () => {46try {47await deleteAuthProvider.mutateAsync({ providerId: provider.id });4849toast("Git provider was deleted");50setShowDeleteConfirmation(false);51} catch (e) {}52}, [deleteAuthProvider, provider.id, toast]);5354return (55<>56<Item className="h-16">57<ItemFieldIcon>58<div59className={60"rounded-full w-3 h-3 text-sm align-middle m-auto " +61(provider.verified ? "bg-green-500" : "bg-gray-400")62}63>64 65</div>66</ItemFieldIcon>67<ItemField className="w-5/12 flex items-center">68<span className="font-medium truncate overflow-ellipsis">{toAuthProviderLabel(provider.type)}</span>69</ItemField>70<ItemField className="w-5/12 flex items-center">71<span className="my-auto truncate text-gray-500 overflow-ellipsis">{provider.host}</span>72</ItemField>73<ItemFieldContextMenu menuEntries={menuEntries} />74</Item>75{showDeleteConfirmation && (76<ConfirmationModal77title="Remove Git Provider"78warningText={79memberCount > 180? `You are about to delete an organization-wide Git providers integration. This will affect all ${memberCount} people in the organization. Are you sure?`81: "You are about to delete an organization-wide Git providers integration. Are you sure?"82}83children={{84name: toAuthProviderLabel(provider.type),85description: provider.host,86}}87buttonText="Remove Provider"88footerAlert={89deleteAuthProvider.isError ? (90<ModalFooterAlert type="danger">There was a problem deleting the provider</ModalFooterAlert>91) : undefined92}93onClose={() => setShowDeleteConfirmation(false)}94onConfirm={deleteProvider}95/>96)}97{showEditModal && <GitIntegrationModal provider={provider} onClose={() => setShowEditModal(false)} />}98</>99);100};101102103