'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { PlusIcon, PersonIcon, 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 | null) => { console.log('Switching to workspace:', orgId) setSwitching(orgId || 'personal') try { // * If orgId is null, we can't switch context via API in the same way if strict mode is on // * BUT, Pulse doesn't support personal workspace. // * So we should probably NOT show the "Personal" option in Pulse if strict mode is enforced. // * However, to match Drop exactly, we might want to show it but have it fail or redirect? // * Let's assume for now we want to match Drop's UI structure. if (!orgId) { // * Pulse doesn't support personal context. // * We could redirect to onboarding or show an error. // * For now, let's just return to avoid breaking. return } const { access_token } = await switchContext(orgId) // * Update session cookie via server action // * Note: switchContext only returns access_token, we keep existing refresh token await setSessionAction(access_token) // Force reload to pick up new permissions window.location.reload() } catch (err) { console.error('Failed to switch workspace', err) setSwitching(null) } } return (
Workspaces
{/* Personal Workspace - HIDDEN IN PULSE (Strict Mode) */} {/* */} {/* Organization Workspaces */} {orgs.map((org) => ( ))} {/* Create New */}
Create Organization
) }