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