Skip to content

Commit

Permalink
chore(shared,clerk-js): Drop organizationList from `useOrganization…
Browse files Browse the repository at this point in the history
…List` hook
  • Loading branch information
dimkl committed Nov 9, 2023
1 parent 892f0ef commit 88b715b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export const UserMembershipList = (props: UserMembershipListProps) => {

const { hidePersonal } = useOrganizationSwitcherContext();
const { organization: currentOrg } = useCoreOrganization();
const { organizationList } = useCoreOrganizationList();
const { userMemberships } = useCoreOrganizationList();
const user = useCoreUser();

const otherOrgs = (organizationList || []).map(e => e.organization).filter(o => o.id !== currentOrg?.id);
const otherOrgs = (userMemberships.data || []).map(e => e.organization).filter(o => o.id !== currentOrg?.id);

const { username, primaryEmailAddress, primaryPhoneNumber, ...userWithoutIdentifiers } = user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ export const UserMembershipList = (props: UserMembershipListProps) => {

const { hidePersonal } = useOrganizationSwitcherContext();
const { organization: currentOrg } = useCoreOrganization();
const { organizationList } = useCoreOrganizationList();
const { userMemberships } = useCoreOrganizationList();
const user = useCoreUser();

const otherOrgs = (organizationList || []).map(e => e.organization).filter(o => o.id !== currentOrg?.id);
const otherOrgs = (userMemberships.data || []).map(e => e.organization).filter(o => o.id !== currentOrg?.id);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { username, primaryEmailAddress, primaryPhoneNumber, ...userWithoutIdentifiers } = user;

return (
Expand Down
24 changes: 1 addition & 23 deletions packages/shared/src/react/hooks/useOrganizationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
UserOrganizationInvitationResource,
} from '@clerk/types';

import { deprecatedObjectProperty } from '../../deprecated';
import { useClerkInstanceContext, useUserContext } from '../contexts';
import type { PaginatedResources, PaginatedResourcesWithDefault } from '../types';
import { usePagesOrInfinite, useWithSafeValues } from './usePagesOrInfinite';
Expand All @@ -37,7 +36,6 @@ type UseOrganizationListParams = {
});
};

type OrganizationList = ReturnType<typeof createOrganizationList>;
const undefinedPaginatedResource = {
data: undefined,
count: undefined,
Expand All @@ -60,10 +58,6 @@ type UseOrganizationList = <T extends UseOrganizationListParams>(
) =>
| {
isLoaded: false;
/**
* @deprecated Use userMemberships instead
*/
organizationList: undefined;
createOrganization: undefined;
setActive: undefined;
userMemberships: PaginatedResourcesWithDefault<OrganizationMembershipResource>;
Expand All @@ -72,10 +66,6 @@ type UseOrganizationList = <T extends UseOrganizationListParams>(
}
| {
isLoaded: boolean;
/**
* @deprecated Use userMemberships instead
*/
organizationList: OrganizationList;
createOrganization: (params: CreateOrganizationParams) => Promise<OrganizationResource>;
setActive: SetActive;
userMemberships: PaginatedResources<
Expand Down Expand Up @@ -208,7 +198,6 @@ export const useOrganizationList: UseOrganizationList = params => {
if (!isClerkLoaded) {
return {
isLoaded: false,
organizationList: undefined,
createOrganization: undefined,
setActive: undefined,
userMemberships: undefinedPaginatedResource,
Expand All @@ -217,23 +206,12 @@ export const useOrganizationList: UseOrganizationList = params => {
};
}

const result = {
return {
isLoaded: isClerkLoaded,
organizationList: createOrganizationList(user.organizationMemberships),
setActive: clerk.setActive,
createOrganization: clerk.createOrganization,
userMemberships: memberships,
userInvitations: invitations,
userSuggestions: suggestions,
};
deprecatedObjectProperty(result, 'organizationList', 'Use `userMemberships` instead.');

return result;
};

function createOrganizationList(organizationMemberships: OrganizationMembershipResource[]) {
return organizationMemberships.map(organizationMembership => ({
membership: organizationMembership,
organization: organizationMembership.organization,
}));
}

0 comments on commit 88b715b

Please sign in to comment.