Skip to content

Commit c9e0498

Browse files
committed
ack PR comments
1 parent 39fc649 commit c9e0498

File tree

4 files changed

+65
-59
lines changed

4 files changed

+65
-59
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/components/invite-modal/components/permissions-table-skeleton.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/components/invite-modal/components/permissions-table.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
import { useEffect, useMemo, useState } from 'react'
22
import { Loader2, RotateCw, X } from 'lucide-react'
33
import { Badge, Button, Tooltip } from '@/components/emcn'
4+
import { Skeleton } from '@/components/ui/skeleton'
45
import { useSession } from '@/lib/auth/auth-client'
56
import type { PermissionType } from '@/lib/workspaces/permissions/utils'
67
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
78
import type { WorkspacePermissions } from '@/hooks/queries/workspace'
89
import { PermissionSelector } from './permission-selector'
9-
import { PermissionsTableSkeleton } from './permissions-table-skeleton'
1010
import type { UserPermissions } from './types'
1111

12+
const PermissionsTableSkeleton = () => (
13+
<div className='scrollbar-hide max-h-[300px] overflow-y-auto'>
14+
<div className='flex items-center justify-between gap-[8px] py-[8px]'>
15+
<div className='min-w-0 flex-1'>
16+
<div className='flex items-center gap-[8px]'>
17+
<Skeleton className='h-[14px] w-40 rounded-[4px]' />
18+
</div>
19+
</div>
20+
<div className='flex flex-shrink-0 items-center'>
21+
<div className='inline-flex gap-[2px]'>
22+
<Skeleton className='h-[28px] w-[44px] rounded-[5px]' />
23+
<Skeleton className='h-[28px] w-[44px] rounded-[5px]' />
24+
<Skeleton className='h-[28px] w-[44px] rounded-[5px]' />
25+
</div>
26+
</div>
27+
</div>
28+
</div>
29+
)
30+
1231
export interface PermissionsTableProps {
1332
userPermissions: UserPermissions[]
1433
onPermissionChange: (userId: string, permissionType: PermissionType) => void

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/components/invite-modal/invite-modal.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function InviteModal({ open, onOpenChange, workspaceName }: InviteModalPr
5555
} | null>(null)
5656
const [resendCooldowns, setResendCooldowns] = useState<Record<string, number>>({})
5757
const [resentInvitationIds, setResentInvitationIds] = useState<Record<string, boolean>>({})
58+
const [resendingInvitationIds, setResendingInvitationIds] = useState<Record<string, boolean>>({})
5859
const params = useParams()
5960
const workspaceId = params.workspaceId as string
6061

@@ -329,12 +330,20 @@ export function InviteModal({ open, onOpenChange, workspaceName }: InviteModalPr
329330
const secondsLeft = resendCooldowns[invitationId]
330331
if (secondsLeft && secondsLeft > 0) return
331332

333+
if (resendingInvitationIds[invitationId]) return
334+
332335
setErrorMessage(null)
336+
setResendingInvitationIds((prev) => ({ ...prev, [invitationId]: true }))
333337

334338
resendInvitation.mutate(
335339
{ invitationId, workspaceId },
336340
{
337341
onSuccess: () => {
342+
setResendingInvitationIds((prev) => {
343+
const next = { ...prev }
344+
delete next[invitationId]
345+
return next
346+
})
338347
setResentInvitationIds((prev) => ({ ...prev, [invitationId]: true }))
339348
setTimeout(() => {
340349
setResentInvitationIds((prev) => {
@@ -369,20 +378,20 @@ export function InviteModal({ open, onOpenChange, workspaceName }: InviteModalPr
369378
cooldownIntervalsRef.current.set(invitationId, interval)
370379
},
371380
onError: (error) => {
381+
setResendingInvitationIds((prev) => {
382+
const next = { ...prev }
383+
delete next[invitationId]
384+
return next
385+
})
372386
logger.error('Error resending invitation:', error)
373387
setErrorMessage(error.message || 'Failed to resend invitation. Please try again.')
374388
},
375389
}
376390
)
377391
},
378-
[workspaceId, userPerms.canAdmin, resendCooldowns, resendInvitation]
392+
[workspaceId, userPerms.canAdmin, resendCooldowns, resendingInvitationIds, resendInvitation]
379393
)
380394

381-
const resendingInvitationIds = useMemo(() => {
382-
if (!resendInvitation.isPending || !resendInvitation.variables) return {}
383-
return { [resendInvitation.variables.invitationId]: true }
384-
}, [resendInvitation.isPending, resendInvitation.variables])
385-
386395
const handleSubmit = useCallback(
387396
(e: React.FormEvent) => {
388397
e.preventDefault()
@@ -435,6 +444,7 @@ export function InviteModal({ open, onOpenChange, workspaceName }: InviteModalPr
435444
setInvitationToRemove(null)
436445
setResendCooldowns({})
437446
setResentInvitationIds({})
447+
setResendingInvitationIds({})
438448

439449
cooldownIntervalsRef.current.forEach((interval) => clearInterval(interval))
440450
cooldownIntervalsRef.current.clear()

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-workspace-management.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -201,36 +201,36 @@ export function useWorkspaceManagement({
201201

202202
logger.info('Leaving workspace:', workspaceToLeave.id)
203203

204-
leaveWorkspaceMutation.mutate(
205-
{ userId: sessionUserId, workspaceId: workspaceToLeave.id },
206-
{
207-
onSuccess: async () => {
208-
logger.info('Left workspace successfully:', workspaceToLeave.id)
209-
210-
const isLeavingCurrentWorkspace =
211-
workspaceIdRef.current === workspaceToLeave.id ||
212-
activeWorkspaceRef.current?.id === workspaceToLeave.id
213-
214-
if (isLeavingCurrentWorkspace) {
215-
logger.info(
216-
'Leaving current workspace - using full workspace refresh with URL validation'
217-
)
218-
hasValidatedRef.current = false
219-
const { data: updatedWorkspaces } = await refetchWorkspaces()
220-
221-
const remainingWorkspaces = (updatedWorkspaces || []).filter(
222-
(w) => w.id !== workspaceToLeave.id
223-
)
224-
if (remainingWorkspaces.length > 0) {
225-
await switchWorkspace(remainingWorkspaces[0])
226-
}
227-
}
228-
},
229-
onError: (error) => {
230-
logger.error('Error leaving workspace:', error)
231-
},
204+
try {
205+
await leaveWorkspaceMutation.mutateAsync({
206+
userId: sessionUserId,
207+
workspaceId: workspaceToLeave.id,
208+
})
209+
210+
logger.info('Left workspace successfully:', workspaceToLeave.id)
211+
212+
const isLeavingCurrentWorkspace =
213+
workspaceIdRef.current === workspaceToLeave.id ||
214+
activeWorkspaceRef.current?.id === workspaceToLeave.id
215+
216+
if (isLeavingCurrentWorkspace) {
217+
logger.info(
218+
'Leaving current workspace - using full workspace refresh with URL validation'
219+
)
220+
hasValidatedRef.current = false
221+
const { data: updatedWorkspaces } = await refetchWorkspaces()
222+
223+
const remainingWorkspaces = (updatedWorkspaces || []).filter(
224+
(w) => w.id !== workspaceToLeave.id
225+
)
226+
if (remainingWorkspaces.length > 0) {
227+
await switchWorkspace(remainingWorkspaces[0])
228+
}
232229
}
233-
)
230+
} catch (error) {
231+
logger.error('Error leaving workspace:', error)
232+
throw error
233+
}
234234
},
235235
[refetchWorkspaces, switchWorkspace, sessionUserId, leaveWorkspaceMutation]
236236
)

0 commit comments

Comments
 (0)