'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
) }