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