Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-bags-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/clerk-js": patch
---

When organization changes, display/fetch the corresponding organization roles.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ describe('OrganizationSwitcher', () => {
f.withOrganizations();
f.withUser({ email_addresses: ['test@clerk.com'], organization_memberships: ['Org1', 'Org2'] });
});
fixtures.clerk.organization?.getRoles.mockRejectedValue(null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@panteliselef Based on the ticket i think that we need to add a test to verify that different organization roles are displayed / fetched when the organization is switched.
The updated test does not seem to be related to that scenario.


fixtures.clerk.user?.getOrganizationMemberships.mockReturnValueOnce(
Promise.resolve({
Expand Down
5 changes: 4 additions & 1 deletion packages/clerk-js/src/ui/hooks/useFetchRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const getRolesParams = {
};
export const useFetchRoles = (enabled = true) => {
const { organization } = useOrganization();
const { data, isLoading } = useFetch(enabled ? organization?.getRoles : undefined, getRolesParams);
const { data, isLoading } = useFetch(enabled && !!organization?.id ? organization?.getRoles : undefined, {
...getRolesParams,
orgId: organization?.id,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃 Do we populate the organization instance for personal account? If not i would expect to use enabled && !!organization instead. Eg:

  const { data, isLoading } = useFetch(enabled && !!organization ? organization?.getRoles : undefined, {
    ...getRolesParams,
    orgId: organization?.id,
  });


return {
isLoading,
Expand Down