Elffuss BraidHub

kikocis/continue public

main · 3.6 KiBRawPermalink
1import { isOnPremSession } from "core/control-plane/AuthTypes";
2import React, { useState } from "react";
3import { useNavigate, useSearchParams } from "react-router-dom";
4import { AssistantAndOrgListbox } from "../../components/AssistantAndOrgListbox";
5import Alert from "../../components/gui/Alert";
6import { Divider } from "../../components/ui/Divider";
7import { TabGroup } from "../../components/ui/TabGroup";
8import { useAuth } from "../../context/Auth";
9import { useNavigationListener } from "../../hooks/useNavigationListener";
10import { bottomTabSections, getAllTabs, topTabSections } from "./configTabs";
11import { AccountDropdown } from "./features/account/AccountDropdown";
12
13function ConfigPage() {
14 useNavigationListener();
15 const navigate = useNavigate();
16 const [searchParams] = useSearchParams();
17 const [activeTab, setActiveTab] = useState(() => {
18 return searchParams.get("tab") || "settings";
19 });
20 const { session, organizations } = useAuth();
21
22 const allTabs = getAllTabs();
23 const shouldRenderOrgInfo =
24 session && organizations.length > 1 && !isOnPremSession(session);
25
26 const handleTabClick = (tabId: string) => {
27 if (tabId === "back") {
28 navigate("/");
29 } else {
30 setActiveTab(tabId);
31 }
32 };
33
34 return (
35 <div className="flex h-full flex-row overflow-hidden">
36 {/* Vertical Sidebar - full height */}
37 <div className="bg-vsc-background flex w-12 flex-shrink-0 flex-col border-0 md:w-40">
38 <div className="border-r-border flex flex-1 flex-col overflow-y-auto border-b-0 border-l-0 border-r-2 border-t-0 border-solid p-2 text-xs">
39 {topTabSections.map((section, index) => (
40 <React.Fragment key={section.id}>
41 <TabGroup
42 tabs={section.tabs}
43 activeTab={activeTab}
44 onTabClick={handleTabClick}
45 showTopDivider={section.showTopDivider}
46 showBottomDivider={section.showBottomDivider}
47 className={section.className}
48 />
49 {index === 0 && shouldRenderOrgInfo && (
50 <>
51 <Divider />
52 <AssistantAndOrgListbox variant="sidebar" />
53 </>
54 )}
55 </React.Fragment>
56 ))}
57
58 <div className="flex-1" />
59
60 {bottomTabSections.map((section) => (
61 <TabGroup
62 key={section.id}
63 tabs={section.tabs}
64 activeTab={activeTab}
65 onTabClick={handleTabClick}
66 showTopDivider={section.showTopDivider}
67 showBottomDivider={section.showBottomDivider}
68 className={section.className}
69 />
70 ))}
71
72 <Divider />
73
74 <AccountDropdown />
75 </div>
76 </div>
77
78 {/* Main content area */}
79 <div className="flex min-h-0 flex-1 flex-col overflow-hidden">
80 {/* Alert for small screens (sm and below) */}
81 <div className="block px-4 py-4 sm:hidden">
82 <Alert type="warning" className="max-w-md">
83 <div className="flex flex-col">
84 <div className="font-medium">Screen width too small</div>
85 <div className="text-description mt-1 text-sm">
86 To view settings, please expand the sidebar by dragging the
87 left/right border
88 </div>
89 </div>
90 </Alert>
91 </div>
92
93 {/* Tab Content for larger screens (md and above) */}
94 <div className="hidden flex-1 space-y-6 overflow-y-auto px-4 py-4 sm:block">
95 {allTabs.find((tab) => tab.id === activeTab)?.component}
96 </div>
97 </div>
98 </div>
99 );
100}
101
102export default ConfigPage;