Skip to content

Commit

Permalink
Merge pull request #7439 from alkem-io/hotfix-create-space-entitlements
Browse files Browse the repository at this point in the history
Create Space Link - entitlements check added
  • Loading branch information
bobbykolev authored Jan 14, 2025
2 parents 8b41210 + 7ec232c commit e30fd65
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alkemio/client-web",
"version": "0.79.6",
"version": "0.79.7",
"description": "Alkemio client, enabling users to interact with Challenges hosted on the Alkemio platform.",
"repository": {
"type": "git",
Expand Down
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 e30fd65

Please sign in to comment.