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