-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'typescript-snippets' of github.com:commercetools/mercha…
…nt-center-application-kit into typescript-snippets
- Loading branch information
Showing
13 changed files
with
112 additions
and
55 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
website/src/code-examples/api-reference/application-config/environment-prop.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; | ||
|
||
const MyComponent = () => { | ||
const applicationName = useApplicationContext( | ||
(context) => context.environment.applicationName | ||
); | ||
return <div>{`Welcome to the application ${applicationName}!`}</div>; | ||
}; |
8 changes: 8 additions & 0 deletions
8
website/src/code-examples/api-reference/application-config/environment-prop.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors'; | ||
|
||
const MyComponent = () => { | ||
const applicationName = useApplicationContext( | ||
(context) => context.environment.applicationName | ||
); | ||
return <div>{`Welcome to the application ${applicationName}!`}</div>; | ||
}; |
13 changes: 13 additions & 0 deletions
13
...e/src/code-examples/api-reference/commercetools-frontend-permissions/use-is-authorized.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useIsAuthorized } from '@commercetools-frontend/permissions'; | ||
|
||
const CreateButton = () => { | ||
const canManage = useIsAuthorized({ | ||
demandedPermissions: ['ManageAvengers'], | ||
}); | ||
return ( | ||
<PrimaryButton | ||
isDisabled={!canManage} | ||
// ... | ||
/> | ||
); | ||
}; |
13 changes: 13 additions & 0 deletions
13
.../src/code-examples/api-reference/commercetools-frontend-permissions/use-is-authorized.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useIsAuthorized } from '@commercetools-frontend/permissions'; | ||
|
||
const CreateButton = () => { | ||
const canManage = useIsAuthorized({ | ||
demandedPermissions: ['ManageAvengers'], | ||
}); | ||
return ( | ||
<PrimaryButton | ||
isDisabled={!canManage} | ||
// ... | ||
/> | ||
); | ||
}; |
5 changes: 5 additions & 0 deletions
5
website/src/code-examples/migrating-from-project-level-custom-applications/constants.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { entryPointUriPathToPermissionKeys } from '@commercetools-frontend/application-shell/ssr'; | ||
|
||
export const entryPointUriPath = 'avengers'; | ||
|
||
export const PERMISSIONS = entryPointUriPathToPermissionKeys(entryPointUriPath); |
5 changes: 5 additions & 0 deletions
5
website/src/code-examples/migrating-from-project-level-custom-applications/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { entryPointUriPathToPermissionKeys } from '@commercetools-frontend/application-shell/ssr'; | ||
|
||
export const entryPointUriPath = 'avengers'; | ||
|
||
export const PERMISSIONS = entryPointUriPathToPermissionKeys(entryPointUriPath); |
11 changes: 11 additions & 0 deletions
11
...de-examples/migrating-from-project-level-custom-applications/custom-application-config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { entryPointUriPath, PERMISSIONS } from './src/constants'; | ||
|
||
const config = { | ||
entryPointUriPath, | ||
mainMenuLink: { | ||
// ... | ||
permissions: [PERMISSIONS.View], | ||
}, | ||
// ... | ||
}; | ||
export default config; |
12 changes: 12 additions & 0 deletions
12
...de-examples/migrating-from-project-level-custom-applications/custom-application-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { entryPointUriPath, PERMISSIONS } from './src/constants'; | ||
import type { ConfigOptions } from '@commercetools-frontend/application-config'; | ||
|
||
const config: ConfigOptions = { | ||
entryPointUriPath, | ||
mainMenuLink: { | ||
// ... | ||
permissions: [PERMISSIONS.View], | ||
}, | ||
// ... | ||
}; | ||
export default config; |
8 changes: 8 additions & 0 deletions
8
website/src/code-examples/migrating-from-project-level-custom-applications/permissions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useIsAuthorized } from '@commercetools-frontend/permissions'; | ||
import { PERMISSIONS } from '../../constants'; | ||
|
||
const MyComponent = () => { | ||
const canView = useIsAuthorized({ | ||
demandedPermissions: [PERMISSIONS.View], | ||
}); | ||
}; |
8 changes: 8 additions & 0 deletions
8
website/src/code-examples/migrating-from-project-level-custom-applications/permissions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useIsAuthorized } from '@commercetools-frontend/permissions'; | ||
import { PERMISSIONS } from '../../constants'; | ||
|
||
const MyComponent = () => { | ||
const canView = useIsAuthorized({ | ||
demandedPermissions: [PERMISSIONS.View], | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters