Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 469
refactor(ui): gate mosaic organization sections by permission and admin-delete#9041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
3dcba2c6e1cfe91ceee26727b61811d1f3dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { useOrganization, useOrganizationList, useSession } from '@clerk/shared/react'; | ||
| import type { Snapshot } from '../machine/types'; | ||
| import { useMachine } from '../machine/useMachine'; | ||
| import type { DeleteOrgContext, DeleteOrgEvent } from './delete-organization.machine'; | ||
| import { deleteOrgMachine } from './delete-organization.machine'; | ||
| type DeleteOrganizationController = | ||
| | { status: 'loading' } | ||
| | { status: 'hidden' } | ||
| | { | ||
| status: 'ready'; | ||
| snapshot: Snapshot<DeleteOrgContext>; | ||
| send: (event: DeleteOrgEvent) => void; | ||
| canSubmit: boolean; | ||
| }; | ||
| export function useDeleteOrganizationController(): DeleteOrganizationController { | ||
| const { isLoaded: isOrganizationLoaded, organization } = useOrganization(); | ||
| const { isLoaded: isSessionLoaded, session } = useSession(); | ||
| const { userMemberships } = useOrganizationList({ userMemberships: true }); | ||
| const [snapshot, send, actor] = useMachine(deleteOrgMachine, { | ||
| context: { | ||
| organizationName: organization?.name ?? '', | ||
| destroyOrganization: async () => { | ||
| await organization?.destroy(); | ||
| // Refresh org lists elsewhere (e.g. the switcher). Not awaited: a stale | ||
| // list must not make a successful delete look like it failed. | ||
| void userMemberships.revalidate?.(); | ||
| // TODO(mosaic): navigate away from the deleted org's profile once the flow | ||
| // has router context, mirroring legacy navigateAfterLeaveOrganization. | ||
| }, | ||
| }, | ||
| }); | ||
| // The permission check needs both the organization and the session resolved. | ||
| // Treat either still loading as 'loading' so a not-yet-known session is never | ||
| // collapsed into a definitive 'hidden'. | ||
| if (!isOrganizationLoaded || !isSessionLoaded) { | ||
| return { status: 'loading' }; | ||
| } | ||
| const canDelete = session?.checkAuthorization({ permission: 'org:sys_profile:delete' }) ?? false; | ||
| if (!organization || !canDelete || !organization.adminDeleteEnabled) { | ||
| return { status: 'hidden' }; | ||
| } | ||
| return { | ||
| status: 'ready', | ||
| snapshot, | ||
| send, | ||
| canSubmit: actor.can({ type: 'CONFIRM' }), | ||
| }; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.