From 2fc4344302db6212f031618ab6e4644ac82ccc42 Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Thu, 22 Jan 2026 00:52:31 +0100 Subject: [PATCH] feat: enhance user experience with improved workspace switcher functionality --- components/WorkspaceSwitcher.tsx | 77 ++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 components/WorkspaceSwitcher.tsx diff --git a/components/WorkspaceSwitcher.tsx b/components/WorkspaceSwitcher.tsx new file mode 100644 index 0000000..1d58713 --- /dev/null +++ b/components/WorkspaceSwitcher.tsx @@ -0,0 +1,77 @@ +'use client' + +import { useState } from 'react' +import { useRouter } from 'next/navigation' +import { PlusIcon, CubeIcon, CheckIcon } from '@radix-ui/react-icons' +import { switchContext, OrganizationMember } from '@/lib/api/organization' +import { setSessionAction } from '@/app/actions/auth' +import Link from 'next/link' + +export default function WorkspaceSwitcher({ orgs, activeOrgId }: { orgs: OrganizationMember[], activeOrgId: string | null }) { + const router = useRouter() + const [switching, setSwitching] = useState(null) + + const handleSwitch = async (orgId: string) => { + console.log('Switching to workspace:', orgId) + setSwitching(orgId) + try { + const { token, refresh_token } = await switchContext(orgId) + + // * Update session cookie via server action + await setSessionAction(token, refresh_token) + + // * Update local storage for client-side optimistics + // * We store the full user object usually, but here we just need to trigger a refresh + + // Force reload to pick up new permissions + window.location.reload() + + } catch (err) { + console.error('Failed to switch workspace', err) + setSwitching(null) + } + } + + return ( +
+
+ Workspaces +
+ + {/* Organization Workspaces */} + {orgs.map((org) => ( + + ))} + + {/* Create New */} + +
+ +
+ Create Organization + +
+ ) +}