diff --git a/packages/client/components/DashNavList/DashNavList.tsx b/packages/client/components/DashNavList/DashNavList.tsx index 5bd00159117..2d4e6584154 100644 --- a/packages/client/components/DashNavList/DashNavList.tsx +++ b/packages/client/components/DashNavList/DashNavList.tsx @@ -3,10 +3,10 @@ import {ManageAccounts} from '@mui/icons-material' import graphql from 'babel-plugin-relay/macro' import {useFragment} from 'react-relay' import {DashNavList_organization$key} from '../../__generated__/DashNavList_organization.graphql' -import {TierEnum} from '../../__generated__/OrganizationSubscription.graphql' import {Tooltip} from '../../ui/Tooltip/Tooltip' import {TooltipContent} from '../../ui/Tooltip/TooltipContent' import {TooltipTrigger} from '../../ui/Tooltip/TooltipTrigger' +import sortByTier from '../../utils/sortByTier' import DashNavListTeams from './DashNavListTeams' const EmptyTeams = styled('div')({ @@ -43,14 +43,7 @@ const DashNavList = (props: Props) => { organizationsRef ) - const TierEnumValues: TierEnum[] = ['enterprise', 'team', 'starter'] - - const sortedOrgs = organizations.toSorted((a, b) => { - const aTier = TierEnumValues.indexOf(a.tier) - const bTier = TierEnumValues.indexOf(b.tier) - return aTier < bTier ? -1 : aTier > bTier ? 1 : a.name.localeCompare(b.name) - }) - + const sortedOrgs = sortByTier(organizations) const teams = organizations.flatMap((org) => org.viewerTeams) return ( diff --git a/packages/server/graphql/public/types/User.ts b/packages/server/graphql/public/types/User.ts index 21654b9d13e..963c1d5c905 100644 --- a/packages/server/graphql/public/types/User.ts +++ b/packages/server/graphql/public/types/User.ts @@ -6,6 +6,7 @@ import MeetingMemberId from 'parabol-client/shared/gqlIds/MeetingMemberId' import isTaskPrivate from 'parabol-client/utils/isTaskPrivate' import {isNotNull} from 'parabol-client/utils/predicates' import toTeamMemberId from 'parabol-client/utils/relay/toTeamMemberId' +import sortByTier from 'parabol-client/utils/sortByTier' import { AUTO_GROUPING_THRESHOLD, MAX_REDUCTION_PERCENTAGE, @@ -430,14 +431,14 @@ const User: ReqResolvers<'User'> = { const organizationUsers = await dataLoader.get('organizationUsersByUserId').load(userId) const orgIds = organizationUsers.map(({orgId}) => orgId) const organizations = (await dataLoader.get('organizations').loadMany(orgIds)).filter(isValid) - organizations.sort((a, b) => (a.name > b.name ? 1 : -1)) + const sortedOrgs = sortByTier(organizations) const viewerId = getUserId(authToken) if (viewerId === userId || isSuperUser(authToken)) { - return organizations + return sortedOrgs } const viewerOrganizationUsers = await dataLoader.get('organizationUsersByUserId').load(viewerId) const viewerOrgIds = viewerOrganizationUsers.map(({orgId}) => orgId) - return organizations.filter((organization) => viewerOrgIds.includes(organization.id)) + return sortedOrgs.filter((organization) => viewerOrgIds.includes(organization.id)) }, overLimitCopy: async ({id: userId, overLimitCopy}, _args, {dataLoader}) => {