Skip to content

Commit

Permalink
fix(clerk-js): Fallback to custom role name if localization is not pr…
Browse files Browse the repository at this point in the history
…ovided (#2194) (#2196)
  • Loading branch information
panteliselef authored Nov 23, 2023
1 parent c6950d7 commit bfa1b78
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-wasps-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Fallback to custom role name if localization is not provided.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const MemberRow = (props: {
const user = useCoreUser();

const isCurrentUser = user.id === membership.publicUserData.userId;
const unlocalizedRoleLabel = options?.find(a => a.value === membership.role)?.label;

return (
<RowContainer>
Expand All @@ -106,7 +107,11 @@ const MemberRow = (props: {
<Td>
<Gate
permission={'org:sys_memberships:manage'}
fallback={<Text sx={t => ({ opacity: t.opacity.$inactive })}>{localizeCustomRole(membership.role)}</Text>}
fallback={
<Text sx={t => ({ opacity: t.opacity.$inactive })}>
{localizeCustomRole(membership.role) || unlocalizedRoleLabel}
</Text>
}
>
<RoleSelect
isDisabled={card.isLoading || !onRoleChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { OrganizationInvitationResource } from '@clerk/types';
import { useCoreOrganization } from '../../contexts';
import { localizationKeys, Td, Text } from '../../customizables';
import { ThreeDotsMenu, useCardState, UserPreview } from '../../elements';
import { useLocalizeCustomRoles } from '../../hooks/useFetchRoles';
import { useFetchRoles, useLocalizeCustomRoles } from '../../hooks/useFetchRoles';
import { handleError } from '../../utils';
import { DataTable, RowContainer } from './MemberListTable';

Expand All @@ -18,6 +18,8 @@ export const InvitedMembersList = () => {
const card = useCardState();
const { organization, invitations } = useCoreOrganization(invitationsParams);

const { options, isLoading: loadingRoles } = useFetchRoles();

if (!organization) {
return null;
}
Expand All @@ -39,7 +41,7 @@ export const InvitedMembersList = () => {
itemCount={invitations?.count || 0}
pageCount={invitations?.pageCount || 0}
itemsPerPage={invitationsParams.invitations.pageSize}
isLoading={invitations?.isLoading}
isLoading={invitations?.isLoading || loadingRoles}
emptyStateLocalizationKey={localizationKeys('organizationProfile.membersPage.invitationsTab.table__emptyRow')}
headers={[
localizationKeys('organizationProfile.membersPage.activeMembersTab.tableHeader__user'),
Expand All @@ -50,6 +52,7 @@ export const InvitedMembersList = () => {
rows={(invitations?.data || []).map(i => (
<InvitationRow
key={i.id}
options={options}
invitation={i}
onRevoke={revoke(i)}
/>
Expand All @@ -58,9 +61,16 @@ export const InvitedMembersList = () => {
);
};

const InvitationRow = (props: { invitation: OrganizationInvitationResource; onRevoke: () => unknown }) => {
const { invitation, onRevoke } = props;
const InvitationRow = (props: {
invitation: OrganizationInvitationResource;
options: ReturnType<typeof useFetchRoles>['options'];
onRevoke: () => unknown;
}) => {
const { invitation, onRevoke, options } = props;
const { localizeCustomRole } = useLocalizeCustomRoles();

const unlocalizedRoleLabel = options?.find(a => a.value === invitation.role)?.label;

return (
<RowContainer>
<Td>
Expand All @@ -73,7 +83,7 @@ const InvitationRow = (props: { invitation: OrganizationInvitationResource; onRe
<Td>
<Text
colorScheme={'neutral'}
localizationKey={localizeCustomRole(invitation.role)}
localizationKey={localizeCustomRole(invitation.role) || unlocalizedRoleLabel}
/>
</Td>
<Td>
Expand Down

0 comments on commit bfa1b78

Please sign in to comment.