diff --git a/web/src/app/admin/connectors/[connector]/Sidebar.tsx b/web/src/app/admin/connectors/[connector]/Sidebar.tsx index c31e3930c24..e227159ed9d 100644 --- a/web/src/app/admin/connectors/[connector]/Sidebar.tsx +++ b/web/src/app/admin/connectors/[connector]/Sidebar.tsx @@ -8,12 +8,47 @@ import { credentialTemplates } from "@/lib/connectors/credentials"; import Link from "next/link"; import { useUser } from "@/components/user/UserProvider"; import { useContext } from "react"; +import { User } from "@/lib/types"; + +function BackButton({ + isAdmin, + isCurator, + user, +}: { + isAdmin: boolean; + isCurator: boolean; + user: User | null; +}) { + const buttonText = isAdmin ? "Admin Page" : "Curator Page"; + + if (!isAdmin && !isCurator) { + console.error( + `User is neither admin nor curator, defaulting to curator view. Found user:\n ${JSON.stringify( + user, + null, + 2 + )}` + ); + } + + return ( +
+ + +

{buttonText}

+ +
+ ); +} export default function Sidebar() { const { formStep, setFormStep, connector, allowAdvanced, allowCreate } = useFormContext(); const combinedSettings = useContext(SettingsContext); - const { isLoadingUser, isAdmin } = useUser(); + const { isCurator, isAdmin, user } = useUser(); if (!combinedSettings) { return null; } @@ -55,17 +90,7 @@ export default function Sidebar() { -
- - -

- {isAdmin ? "Admin Page" : "Curator Page"} -

- -
+
diff --git a/web/src/app/chat/page.tsx b/web/src/app/chat/page.tsx index 4f91699b48c..05207ea9282 100644 --- a/web/src/app/chat/page.tsx +++ b/web/src/app/chat/page.tsx @@ -5,7 +5,6 @@ import { WelcomeModal } from "@/components/initialSetup/welcome/WelcomeModalWrap import { ChatProvider } from "@/components/context/ChatContext"; import { fetchChatData } from "@/lib/chat/fetchChatData"; import WrappedChat from "./WrappedChat"; -import { AssistantsProvider } from "@/components/context/AssistantsContext"; export default async function Page({ searchParams, diff --git a/web/src/app/layout.tsx b/web/src/app/layout.tsx index e7e3c2c416d..6fd2799ab85 100644 --- a/web/src/app/layout.tsx +++ b/web/src/app/layout.tsx @@ -19,6 +19,7 @@ import { fetchAssistantData } from "@/lib/chat/fetchAssistantdata"; import { AppProvider } from "@/components/context/AppProvider"; import { PHProvider } from "./providers"; import { default as dynamicImport } from "next/dynamic"; +import { getCurrentUserSS } from "@/lib/userSS"; const PostHogPageView = dynamicImport(() => import("./PostHogPageView"), { ssr: false, @@ -57,7 +58,11 @@ export default async function RootLayout({ }: { children: React.ReactNode; }) { - const combinedSettings = await fetchSettingsSS(); + const [combinedSettings, assistantsData, user] = await Promise.all([ + fetchSettingsSS(), + fetchAssistantData(), + getCurrentUserSS(), + ]); const productGating = combinedSettings?.settings.product_gating ?? GatingType.NONE; @@ -165,11 +170,12 @@ export default async function RootLayout({ ); } - const data = await fetchAssistantData(); - const { assistants, hasAnyConnectors, hasImageCompatibleModel } = data; + const { assistants, hasAnyConnectors, hasImageCompatibleModel } = + assistantsData; return getPageContent( { return ( - + (undefined); -export function UserProvider({ children }: { children: React.ReactNode }) { - const [user, setUser] = useState(null); - const [isLoadingUser, setIsLoadingUser] = useState(true); - const [isAdmin, setIsAdmin] = useState(false); - const [isCurator, setIsCurator] = useState(false); +export function UserProvider({ + children, + user, +}: { + children: React.ReactNode; + user: User | null; +}) { + const [upToDateUser, setUpToDateUser] = useState(user); + const [isLoadingUser, setIsLoadingUser] = useState(false); const fetchUser = async () => { try { - const user = await getCurrentUser(); - setUser(user); - setIsAdmin(user?.role === UserRole.ADMIN); - setIsCurator( - user?.role === UserRole.CURATOR || user?.role == UserRole.GLOBAL_CURATOR - ); + setIsLoadingUser(true); + const currentUser = await getCurrentUser(); + setUpToDateUser(currentUser); } catch (error) { console.error("Error fetching current user:", error); } finally { @@ -35,17 +36,19 @@ export function UserProvider({ children }: { children: React.ReactNode }) { } }; - useEffect(() => { - fetchUser(); - }, []); - const refreshUser = async () => { await fetchUser(); }; return ( {children}