Elffuss BraidHub

kikocis/continue public

main · 3.1 KiBRawPermalink
1import { Cog6ToothIcon } from "@heroicons/react/24/outline";
2import { BuildingOfficeIcon, UserIcon } from "@heroicons/react/24/solid";
3import { isOnPremSession } from "core/control-plane/AuthTypes";
4import { useContext } from "react";
5import { Button, Card, Divider } from "../../../components/ui";
6import { useAuth } from "../../../context/Auth";
7import { IdeMessengerContext } from "../../../context/IdeMessenger";
8import { ConfigHeader } from "../components/ConfigHeader";
9
10function getOrgIcon(org: { name: string; iconUrl?: string | null }) {
11 if (org.iconUrl) {
12 return (
13 <img
14 src={org.iconUrl}
15 alt=""
16 className="h-5 w-5 flex-shrink-0 rounded-full"
17 />
18 );
19 }
20
21 const IconComponent = org.name === "Personal" ? UserIcon : BuildingOfficeIcon;
22 return <IconComponent className="h-5 w-5 flex-shrink-0" />;
23}
24
25export function OrganizationsSection() {
26 const { organizations, session } = useAuth();
27 const ideMessenger = useContext(IdeMessengerContext);
28
29 const shouldRenderOrgInfo =
30 session && organizations.length > 1 && !isOnPremSession(session);
31
32 function handleAddOrganization() {
33 ideMessenger.request("controlPlane/openUrl", {
34 path: "/organizations/new",
35 });
36 }
37
38 function handleConfigureOrganization(orgId: string) {
39 ideMessenger.request("controlPlane/openUrl", {
40 path: `/organizations/${orgId}/settings`,
41 });
42 }
43
44 if (!shouldRenderOrgInfo) {
45 return (
46 <>
47 <div className="mb-8 flex items-center justify-between">
48 <div className="flex flex-col">
49 <h2 className="mb-0 text-xl font-semibold">Organizations</h2>
50 </div>
51 </div>
52 <Card>
53 <div className="text-description py-8 text-center text-sm">
54 Organizations are only available with cloud accounts. Sign in to
55 manage organizations.
56 </div>
57 </Card>
58 </>
59 );
60 }
61
62 return (
63 <>
64 <ConfigHeader
65 title="Organizations"
66 onAddClick={handleAddOrganization}
67 addButtonTooltip="Add organization"
68 />
69
70 <Card>
71 {organizations.map((organization, index) => (
72 <div key={organization.id}>
73 <div className="flex items-center justify-between">
74 <div className="flex items-center gap-3">
75 <div className="flex h-5 w-5 flex-shrink-0 items-center justify-center">
76 {getOrgIcon(organization)}
77 </div>
78 <div className="flex-1">
79 <h3 className="my-2 text-sm font-medium">
80 {organization.name}
81 </h3>
82 </div>
83 </div>
84 <Button
85 onClick={() => handleConfigureOrganization(organization.id)}
86 variant="ghost"
87 size="sm"
88 className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0"
89 >
90 <Cog6ToothIcon className="h-4 w-4 flex-shrink-0" />
91 </Button>
92 </div>
93 {index < organizations.length - 1 && <Divider />}
94 </div>
95 ))}
96 </Card>
97 </>
98 );
99}