Skip to content

Commit

Permalink
check for entitlements in the CreateSpaceLink
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbykolev committed Jan 14, 2025
1 parent 8b41210 commit aed1830
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useTranslation } from 'react-i18next';
import { useUserContext } from '@/domain/community/user';
import { AuthorizationPrivilege } from '@/core/apollo/generated/graphql-schema';
import { AuthorizationPrivilege, LicenseEntitlementType } from '@/core/apollo/generated/graphql-schema';
import { TopLevelRoutePath } from '@/main/routing/TopLevelRoutePath';
import { useMemo } from 'react';

export const useCreateSpaceLink = () => {
const { t } = useTranslation();
const { accountPrivileges, loading } = useUserContext();
const { accountPrivileges, loading, accountEntitlements } = useUserContext();

const STATIC_PAGE_LINK = t('pages.home.sections.startingSpace.url');

Expand All @@ -15,12 +15,18 @@ export const useCreateSpaceLink = () => {
return STATIC_PAGE_LINK;
}

if (accountPrivileges.includes(AuthorizationPrivilege.CreateSpace)) {
const isEntitledToCreateSpace = [
LicenseEntitlementType.AccountSpaceFree,
LicenseEntitlementType.AccountSpacePlus,
LicenseEntitlementType.AccountSpacePremium,
].some(entitlement => accountEntitlements.includes(entitlement));

if (accountPrivileges.includes(AuthorizationPrivilege.CreateSpace) && isEntitledToCreateSpace) {
return `/${TopLevelRoutePath.CreateSpace}`;
}

return STATIC_PAGE_LINK;
}, [accountPrivileges, loading, t]);
}, [accountPrivileges, accountEntitlements, loading, t]);

return { loading, link };
};

0 comments on commit aed1830

Please sign in to comment.