-
Notifications
You must be signed in to change notification settings - Fork 422
fix(ui): Hide "must belong to org" screen when org resources exist #7553
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
Merged
LauraBeatris
merged 2 commits into
main
from
laura/orgs-1152-taskchooseorganization-displays-you-must-belong-to-an
Jan 7, 2026
+67
−31
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/ui': patch | ||
| --- | ||
|
|
||
| Fix "You must belong to an organization" screen showing when user has existing memberships, invitations or suggestions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,10 @@ import { describe, expect, it } from 'vitest'; | |
|
|
||
| import { bindCreateFixtures } from '@/test/create-fixtures'; | ||
| import { render } from '@/test/utils'; | ||
| import { createFakeUserOrganizationMembership } from '@/ui/components/OrganizationSwitcher/__tests__/test-utils'; | ||
| import { | ||
| createFakeUserOrganizationMembership, | ||
| createFakeUserOrganizationSuggestion, | ||
| } from '@/ui/components/OrganizationSwitcher/__tests__/test-utils'; | ||
|
|
||
| import { TaskChooseOrganization } from '..'; | ||
|
|
||
|
|
@@ -296,5 +299,56 @@ describe('TaskChooseOrganization', () => { | |
| expect(queryByText(/you must belong to an organization/i)).toBeInTheDocument(); | ||
| expect(queryByText(/contact your organization admin for an invitation/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('with existing memberships or suggestions, displays create organization screen', async () => { | ||
| const { wrapper, fixtures } = await createFixtures(f => { | ||
| f.withOrganizations(); | ||
| f.withForceOrganizationSelection(); | ||
| f.withUser({ | ||
| create_organization_enabled: false, | ||
| }); | ||
| }); | ||
|
|
||
| fixtures.clerk.user?.getOrganizationMemberships.mockReturnValueOnce( | ||
| Promise.resolve({ | ||
| data: [ | ||
| createFakeUserOrganizationMembership({ | ||
| id: '1', | ||
| organization: { | ||
| id: '1', | ||
| name: 'Existing Org', | ||
| slug: 'org1', | ||
| membersCount: 1, | ||
| adminDeleteEnabled: false, | ||
| maxAllowedMemberships: 1, | ||
| pendingInvitationsCount: 1, | ||
| }, | ||
| }), | ||
| ], | ||
| total_count: 1, | ||
| }), | ||
| ); | ||
|
|
||
| fixtures.clerk.user?.getOrganizationSuggestions.mockReturnValueOnce( | ||
| Promise.resolve({ | ||
| data: [ | ||
| createFakeUserOrganizationSuggestion({ | ||
| id: '2', | ||
| emailAddress: '[email protected]', | ||
| publicOrganizationData: { | ||
| name: 'OrgTwoSuggestion', | ||
| }, | ||
| }), | ||
| ], | ||
| total_count: 1, | ||
| }), | ||
| ); | ||
|
|
||
| const { findByText, queryByRole } = render(<TaskChooseOrganization />, { wrapper }); | ||
|
|
||
| expect(await findByText('Existing Org')).toBeInTheDocument(); | ||
| expect(await findByText('Create new organization')).toBeInTheDocument(); | ||
| expect(queryByRole('textbox', { name: /name/i })).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { useClerk, useSession, useUser } from '@clerk/shared/react'; | ||
| import { useState, type ComponentType } from 'react'; | ||
| import { useState } from 'react'; | ||
|
|
||
| import { useSignOutContext, withCoreSessionSwitchGuard } from '@/ui/contexts'; | ||
| import { descriptors, Flex, Flow, localizationKeys, Spinner } from '@/ui/customizables'; | ||
|
|
@@ -14,24 +14,16 @@ import { ChooseOrganizationScreen } from './ChooseOrganizationScreen'; | |
| import { CreateOrganizationScreen } from './CreateOrganizationScreen'; | ||
|
|
||
| const TaskChooseOrganizationInternal = () => { | ||
| const { signOut } = useClerk(); | ||
| const { user } = useUser(); | ||
| const { session } = useSession(); | ||
| const { userMemberships, userSuggestions, userInvitations } = useOrganizationListInView(); | ||
| const { otherSessions } = useMultipleSessions({ user }); | ||
| const { navigateAfterSignOut, navigateAfterMultiSessionSingleSignOutUrl } = useSignOutContext(); | ||
|
|
||
| const handleSignOut = () => { | ||
| if (otherSessions.length === 0) { | ||
| return signOut(navigateAfterSignOut); | ||
| } | ||
|
|
||
| return signOut(navigateAfterMultiSessionSingleSignOutUrl, { sessionId: session?.id }); | ||
| }; | ||
|
Comment on lines
-21
to
-30
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was unused, somehow linter didn't caught it as well |
||
|
|
||
| const isLoading = userMemberships?.isLoading || userInvitations?.isLoading || userSuggestions?.isLoading; | ||
| const hasExistingResources = !!(userMemberships?.count || userInvitations?.count || userSuggestions?.count); | ||
| const identifier = user?.primaryEmailAddress?.emailAddress ?? user?.username; | ||
| const isOrganizationCreationDisabled = !isLoading && !user?.createOrganizationEnabled && !hasExistingResources; | ||
|
|
||
| if (isOrganizationCreationDisabled) { | ||
| return <OrganizationCreationDisabledScreen />; | ||
| } | ||
|
|
||
| return ( | ||
| <Flow.Root flow='taskChooseOrganization'> | ||
|
|
@@ -127,18 +119,6 @@ const TaskChooseOrganizationFlows = withCardStateProvider((props: TaskChooseOrga | |
| return <ChooseOrganizationScreen onCreateOrganizationClick={() => setCurrentFlow('create')} />; | ||
| }); | ||
|
|
||
| export const withOrganizationCreationEnabledGuard = <T,>(Component: ComponentType<T>) => { | ||
| return (props: T) => { | ||
| const { user } = useUser(); | ||
|
|
||
| if (!user?.createOrganizationEnabled) { | ||
| return <OrganizationCreationDisabledScreen />; | ||
| } | ||
|
|
||
| return <Component {...props} />; | ||
| }; | ||
| }; | ||
|
|
||
| function OrganizationCreationDisabledScreen() { | ||
| return ( | ||
| <Flow.Root flow='taskChooseOrganization'> | ||
|
|
@@ -163,8 +143,5 @@ function OrganizationCreationDisabledScreen() { | |
| } | ||
|
|
||
| export const TaskChooseOrganization = withCoreSessionSwitchGuard( | ||
| withTaskGuard( | ||
| withCardStateProvider(withOrganizationCreationEnabledGuard(TaskChooseOrganizationInternal)), | ||
| 'choose-organization', | ||
| ), | ||
| withTaskGuard(withCardStateProvider(TaskChooseOrganizationInternal), 'choose-organization'), | ||
| ); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: clerk/javascript
Length of output: 2669
🏁 Script executed:
Repository: clerk/javascript
Length of output: 521
🏁 Script executed:
Repository: clerk/javascript
Length of output: 9572
🏁 Script executed:
Repository: clerk/javascript
Length of output: 42
🏁 Script executed:
Repository: clerk/javascript
Length of output: 42
🏁 Script executed:
Repository: clerk/javascript
Length of output: 148
🏁 Script executed:
Repository: clerk/javascript
Length of output: 40420
🏁 Script executed:
Repository: clerk/javascript
Length of output: 782
🏁 Script executed:
Repository: clerk/javascript
Length of output: 1237
🏁 Script executed:
Repository: clerk/javascript
Length of output: 2046
🏁 Script executed:
Repository: clerk/javascript
Length of output: 737
🏁 Script executed:
Repository: clerk/javascript
Length of output: 1076
🏁 Script executed:
Repository: clerk/javascript
Length of output: 1714
Add
tasksarray to the user fixture in this test.The
withForceOrganizationSelection()method only sets a configuration flag and does not automatically add thechoose-organizationtask to the user. The component useswithTaskGuard(line 146 of index.tsx) which requires the task to be present in the session to render—without it, the component will redirect instead.The test on lines 16-31 explicitly demonstrates this requirement by verifying the component does not render when the task is absent. The similar test on lines 286-301 (with the same configuration) includes
tasks: [{ key: 'choose-organization' }]. Add this to the user fixture at lines 307-309 to ensure the component can render for the test assertions at lines 349-351 to execute.🤖 Prompt for AI Agents