@@ -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,26 @@ 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
311304 /**
312- * Handle delete workspace
305+ * Handle delete workspace after confirmation
313306 */
314307 const handleDeleteWorkspace = async ( ) => {
315- setIsDeleting ( true )
316308 try {
317309 const targetId = deleteTarget ?. id || workspaceId
318310 await onDeleteWorkspace ( targetId )
319311 setIsDeleteModalOpen ( false )
320312 setDeleteTarget ( null )
321313 } catch ( error ) {
322314 logger . error ( 'Error deleting workspace:' , error )
323- } finally {
324- setIsDeleting ( false )
325315 }
326316 }
327317
@@ -638,7 +628,7 @@ export function WorkspaceHeader({
638628 disableRename = { ! contextCanAdmin }
639629 disableDuplicate = { ! contextCanEdit }
640630 disableExport = { ! contextCanAdmin }
641- disableDelete = { ! contextCanAdmin }
631+ disableDelete = { ! contextCanAdmin || workspaces . length <= 1 }
642632 disableColorChange = { ! contextCanAdmin }
643633 />
644634 )
@@ -666,7 +656,7 @@ export function WorkspaceHeader({
666656 isOpen = { isDeleteModalOpen }
667657 onClose = { ( ) => setIsDeleteModalOpen ( false ) }
668658 onConfirm = { handleDeleteWorkspace }
669- isDeleting = { isDeleting }
659+ isDeleting = { isDeletingWorkspace }
670660 itemType = 'workspace'
671661 itemName = { deleteTarget ?. name || activeWorkspaceFull ?. name || activeWorkspace ?. name }
672662 />
@@ -686,12 +676,16 @@ export function WorkspaceHeader({
686676 < Button
687677 variant = 'default'
688678 onClick = { ( ) => setIsLeaveModalOpen ( false ) }
689- disabled = { isLeaving }
679+ disabled = { isLeavingWorkspace }
690680 >
691681 Cancel
692682 </ Button >
693- < Button variant = 'destructive' onClick = { handleLeaveWorkspace } disabled = { isLeaving } >
694- { isLeaving ? 'Leaving...' : 'Leave Workspace' }
683+ < Button
684+ variant = 'destructive'
685+ onClick = { handleLeaveWorkspace }
686+ disabled = { isLeavingWorkspace }
687+ >
688+ { isLeavingWorkspace ? 'Leaving...' : 'Leave Workspace' }
695689 </ Button >
696690 </ ModalFooter >
697691 </ ModalContent >
0 commit comments