fix: match workspace switcher UI with Drop
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { PlusIcon, CubeIcon, CheckIcon } from '@radix-ui/react-icons'
|
||||
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'
|
||||
@@ -11,18 +11,28 @@ export default function WorkspaceSwitcher({ orgs, activeOrgId }: { orgs: Organiz
|
||||
const router = useRouter()
|
||||
const [switching, setSwitching] = useState<string | null>(null)
|
||||
|
||||
const handleSwitch = async (orgId: string) => {
|
||||
const handleSwitch = async (orgId: string | null) => {
|
||||
console.log('Switching to workspace:', orgId)
|
||||
setSwitching(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 { 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()
|
||||
|
||||
@@ -38,6 +48,27 @@ export default function WorkspaceSwitcher({ orgs, activeOrgId }: { orgs: Organiz
|
||||
Workspaces
|
||||
</div>
|
||||
|
||||
{/* Personal Workspace - HIDDEN IN PULSE (Strict Mode) */}
|
||||
{/*
|
||||
<button
|
||||
onClick={() => handleSwitch(null)}
|
||||
className={`w-full flex items-center justify-between px-3 py-2 text-sm rounded-md transition-colors group ${
|
||||
!activeOrgId ? 'bg-neutral-100 dark:bg-neutral-800' : 'hover:bg-neutral-50 dark:hover:bg-neutral-800/50'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="h-5 w-5 rounded bg-neutral-200 dark:bg-neutral-700 flex items-center justify-center">
|
||||
<PersonIcon className="h-3 w-3 text-neutral-500 dark:text-neutral-400" />
|
||||
</div>
|
||||
<span className="text-neutral-700 dark:text-neutral-300">Personal</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{switching === 'personal' && <span className="text-xs text-neutral-400">Loading...</span>}
|
||||
{!activeOrgId && !switching && <CheckIcon className="h-4 w-4 text-neutral-600 dark:text-neutral-400" />}
|
||||
</div>
|
||||
</button>
|
||||
*/}
|
||||
|
||||
{/* Organization Workspaces */}
|
||||
{orgs.map((org) => (
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user