Skip to content
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

fix(clerk-js): Fallback to custom role name if localization is not provided #2194

Merged
merged 1 commit into from
Nov 23, 2023
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/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 @@ -79,6 +79,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 @@ -101,7 +102,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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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 @@ -101,7 +102,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
Loading