Skip to content

Commit 5b7559c

Browse files
committed
fix(clerk-js): Avoid wrapping NotificationCountBadge of OrgSwitcher with Gate (#2147)
1 parent 203def1 commit 5b7559c

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

.changeset/brown-clouds-divide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
A bug fix for prefetching data for OrganizationSwitcher and correctly displaying a notification count in the switcher as well.

packages/clerk-js/src/ui/components/OrganizationSwitcher/OrganizationSwitcherTrigger.tsx

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { forwardRef } from 'react';
22

3-
import { NotificationCountBadge, withGate } from '../../common';
3+
import { NotificationCountBadge, useGate } from '../../common';
44
import {
55
useCoreOrganization,
66
useCoreOrganizationList,
@@ -72,33 +72,31 @@ export const OrganizationSwitcherTrigger = withAvatarShimmer(
7272
);
7373
}),
7474
);
75-
const NotificationCountBadgeSwitcherTrigger = withGate(
76-
() => {
77-
/**
78-
* Prefetch user invitations and suggestions
79-
*/
80-
const { userInvitations, userSuggestions } = useCoreOrganizationList(organizationListParams);
81-
const { organizationSettings } = useEnvironment();
82-
const isDomainsEnabled = organizationSettings?.domains?.enabled;
83-
const { membershipRequests } = useCoreOrganization({
84-
membershipRequests: isDomainsEnabled || undefined,
85-
});
8675

87-
const notificationCount =
88-
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
89-
(userInvitations.count || 0) + (userSuggestions.count || 0) + (membershipRequests?.count || 0);
90-
91-
return (
92-
<NotificationCountBadge
93-
containerSx={t => ({
94-
marginLeft: `${t.space.$2}`,
95-
})}
96-
notificationCount={notificationCount}
97-
/>
98-
);
99-
},
100-
{
101-
// if the user is not able to accept a request we should not notify them
76+
const NotificationCountBadgeSwitcherTrigger = () => {
77+
/**
78+
* Prefetch user invitations and suggestions
79+
*/
80+
const { userInvitations, userSuggestions } = useCoreOrganizationList(organizationListParams);
81+
const { organizationSettings } = useEnvironment();
82+
const { isAuthorizedUser: canAcceptRequests } = useGate({
10283
permission: 'org:sys_memberships:manage',
103-
},
104-
);
84+
});
85+
const isDomainsEnabled = organizationSettings?.domains?.enabled;
86+
const { membershipRequests } = useCoreOrganization({
87+
membershipRequests: (isDomainsEnabled && canAcceptRequests) || undefined,
88+
});
89+
90+
const notificationCount =
91+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
92+
(userInvitations.count || 0) + (userSuggestions.count || 0) + (membershipRequests?.count || 0);
93+
94+
return (
95+
<NotificationCountBadge
96+
containerSx={t => ({
97+
marginLeft: `${t.space.$2}`,
98+
})}
99+
notificationCount={notificationCount}
100+
/>
101+
);
102+
};

0 commit comments

Comments
 (0)