|  | 
| 1 | 1 | import { forwardRef } from 'react'; | 
| 2 | 2 | 
 | 
| 3 |  | -import { NotificationCountBadge, withGate } from '../../common'; | 
|  | 3 | +import { NotificationCountBadge, useGate } from '../../common'; | 
| 4 | 4 | import { | 
| 5 | 5 |   useCoreOrganization, | 
| 6 | 6 |   useCoreOrganizationList, | 
| @@ -72,33 +72,31 @@ export const OrganizationSwitcherTrigger = withAvatarShimmer( | 
| 72 | 72 |     ); | 
| 73 | 73 |   }), | 
| 74 | 74 | ); | 
| 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 |  | -    }); | 
| 86 | 75 | 
 | 
| 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({ | 
| 102 | 83 |     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