@@ -28,20 +28,12 @@ import { DeleteModal } from '@/app/workspace/[workspaceId]/w/components/sidebar/
2828import { CreateWorkspaceModal } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/components/create-workspace-modal/create-workspace-modal'
2929import { InviteModal } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/components/invite-modal'
3030import { useSubscriptionData } from '@/hooks/queries/subscription'
31+ import type { Workspace } from '@/hooks/queries/workspace'
3132import { usePermissionConfig } from '@/hooks/use-permission-config'
3233import { useSettingsNavigation } from '@/hooks/use-settings-navigation'
3334
3435const logger = createLogger ( 'WorkspaceHeader' )
3536
36- interface Workspace {
37- id : string
38- name : string
39- color ?: string
40- ownerId : string
41- role ?: string
42- permissions ?: 'admin' | 'write' | 'read' | null
43- }
44-
4537interface WorkspaceHeaderProps {
4638 /** The active workspace object */
4739 activeWorkspace ?: { name : string } | null
@@ -65,6 +57,8 @@ interface WorkspaceHeaderProps {
6557 onRenameWorkspace : ( workspaceId : string , newName : string ) => Promise < void >
6658 /** Callback to delete the workspace */
6759 onDeleteWorkspace : ( workspaceId : string ) => Promise < void >
60+ /** Whether workspace deletion is in progress */
61+ isDeletingWorkspace : boolean
6862 /** Callback to duplicate the workspace */
6963 onDuplicateWorkspace : ( workspaceId : string , workspaceName : string ) => Promise < void >
7064 /** Callback to export the workspace */
@@ -77,6 +71,8 @@ interface WorkspaceHeaderProps {
7771 onColorChange ?: ( workspaceId : string , color : string ) => Promise < void >
7872 /** Callback to leave the workspace */
7973 onLeaveWorkspace ?: ( workspaceId : string ) => Promise < void >
74+ /** Whether workspace leave is in progress */
75+ isLeavingWorkspace : boolean
8076 /** Current user's session ID for owner check */
8177 sessionUserId ?: string
8278 /** Whether the sidebar is collapsed */
@@ -98,22 +94,22 @@ export function WorkspaceHeader({
9894 onCreateWorkspace,
9995 onRenameWorkspace,
10096 onDeleteWorkspace,
97+ isDeletingWorkspace,
10198 onDuplicateWorkspace,
10299 onExportWorkspace,
103100 onImportWorkspace,
104101 isImportingWorkspace,
105102 onColorChange,
106103 onLeaveWorkspace,
104+ isLeavingWorkspace,
107105 sessionUserId,
108106 isCollapsed = false ,
109107} : WorkspaceHeaderProps ) {
110108 const [ isCreateModalOpen , setIsCreateModalOpen ] = useState ( false )
111109 const [ isInviteModalOpen , setIsInviteModalOpen ] = useState ( false )
112110 const [ isDeleteModalOpen , setIsDeleteModalOpen ] = useState ( false )
113- const [ isDeleting , setIsDeleting ] = useState ( false )
114111 const [ deleteTarget , setDeleteTarget ] = useState < Workspace | null > ( null )
115112 const [ isLeaveModalOpen , setIsLeaveModalOpen ] = useState ( false )
116- const [ isLeaving , setIsLeaving ] = useState ( false )
117113 const [ leaveTarget , setLeaveTarget ] = useState < Workspace | null > ( null )
118114 const [ editingWorkspaceId , setEditingWorkspaceId ] = useState < string | null > ( null )
119115 const [ editingName , setEditingName ] = useState ( '' )
@@ -296,32 +292,23 @@ export function WorkspaceHeader({
296292 const handleLeaveWorkspace = async ( ) => {
297293 if ( ! leaveTarget || ! onLeaveWorkspace ) return
298294
299- setIsLeaving ( true )
300295 try {
301296 await onLeaveWorkspace ( leaveTarget . id )
302297 setIsLeaveModalOpen ( false )
303298 setLeaveTarget ( null )
304299 } catch ( error ) {
305300 logger . error ( 'Error leaving workspace:' , error )
306- } finally {
307- setIsLeaving ( false )
308301 }
309302 }
310303
311- /**
312- * Handle delete workspace
313- */
314304 const handleDeleteWorkspace = async ( ) => {
315- setIsDeleting ( true )
316305 try {
317306 const targetId = deleteTarget ?. id || workspaceId
318307 await onDeleteWorkspace ( targetId )
319308 setIsDeleteModalOpen ( false )
320309 setDeleteTarget ( null )
321310 } catch ( error ) {
322311 logger . error ( 'Error deleting workspace:' , error )
323- } finally {
324- setIsDeleting ( false )
325312 }
326313 }
327314
@@ -638,7 +625,7 @@ export function WorkspaceHeader({
638625 disableRename = { ! contextCanAdmin }
639626 disableDuplicate = { ! contextCanEdit }
640627 disableExport = { ! contextCanAdmin }
641- disableDelete = { ! contextCanAdmin }
628+ disableDelete = { ! contextCanAdmin || workspaces . length <= 1 }
642629 disableColorChange = { ! contextCanAdmin }
643630 />
644631 )
@@ -666,7 +653,7 @@ export function WorkspaceHeader({
666653 isOpen = { isDeleteModalOpen }
667654 onClose = { ( ) => setIsDeleteModalOpen ( false ) }
668655 onConfirm = { handleDeleteWorkspace }
669- isDeleting = { isDeleting }
656+ isDeleting = { isDeletingWorkspace }
670657 itemType = 'workspace'
671658 itemName = { deleteTarget ?. name || activeWorkspaceFull ?. name || activeWorkspace ?. name }
672659 />
@@ -686,12 +673,16 @@ export function WorkspaceHeader({
686673 < Button
687674 variant = 'default'
688675 onClick = { ( ) => setIsLeaveModalOpen ( false ) }
689- disabled = { isLeaving }
676+ disabled = { isLeavingWorkspace }
690677 >
691678 Cancel
692679 </ Button >
693- < Button variant = 'destructive' onClick = { handleLeaveWorkspace } disabled = { isLeaving } >
694- { isLeaving ? 'Leaving...' : 'Leave Workspace' }
680+ < Button
681+ variant = 'destructive'
682+ onClick = { handleLeaveWorkspace }
683+ disabled = { isLeavingWorkspace }
684+ >
685+ { isLeavingWorkspace ? 'Leaving...' : 'Leave Workspace' }
695686 </ Button >
696687 </ ModalFooter >
697688 </ ModalContent >
0 commit comments