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

chore(clerk-js): Remove legacy roles fallback #2385

Merged
merged 1 commit into from
Dec 18, 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
6 changes: 6 additions & 0 deletions .changeset/lovely-experts-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
---

Remove legacy roles fallback
After the release of Custom Roles, roles should always be dynamically fetched.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MembershipRole } from '@clerk/types';
import React from 'react';
import React, { useMemo } from 'react';

import type { LocalizationKey } from '../../customizables';
import { Col, descriptors, Flex, Spinner, Table, Tbody, Td, Text, Th, Thead, Tr } from '../../customizables';
Expand Down Expand Up @@ -129,24 +129,20 @@ export const RoleSelect = (props: {
}) => {
const { value, roles, onChange, isDisabled, triggerSx, optionListSx } = props;

const shouldDisplayLegacyRoles = !roles;

const legacyRoles: Array<{ label: string; value: MembershipRole }> = [
{ label: 'admin', value: 'admin' },
{ label: 'basic_member', value: 'basic_member' },
];

const legacyExcludedRoles: Array<{ label: string; value: MembershipRole }> = [
{ label: 'guest_member', value: 'guest_member' },
];
const { localizeCustomRole } = useLocalizeCustomRoles();

const selectedRole = [...(roles || []), ...legacyRoles, ...legacyExcludedRoles].find(r => r.value === value);
const fetchedRoles = useMemo(() => [...(roles || [])], [roles]);

const localizedOptions = (!shouldDisplayLegacyRoles ? roles : legacyRoles).map(role => ({
value: role.value,
label: localizeCustomRole(role.value) || role.label,
}));
const selectedRole = useMemo(() => fetchedRoles.find(r => r.value === value), [fetchedRoles]);

const localizedOptions = useMemo(
() =>
fetchedRoles.map(role => ({
value: role.value,
label: localizeCustomRole(role.value) || role.label,
})),
[fetchedRoles, localizeCustomRole],
);

return (
<Select
Expand Down
Loading