This file contains hidden or 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
| import { generateDoorsContent } from "./utils"; | |
| const generateDoors = () => { | |
| const initialContent = generateDoorsContent(); | |
| return [ | |
| { behind: initialContent[0], isOpen: false }, | |
| { behind: initialContent[1], isOpen: false }, | |
| { behind: initialContent[2], isOpen: false } | |
| ]; | |
| }; |
This file contains hidden or 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
| <PermissionsGate | |
| errorProps={{ disabled: true }} | |
| scopes={[SCOPES.canEdit]} | |
| > | |
| <Input /> | |
| </PermissionsGate> |
This file contains hidden or 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
| export default function PermissionsGate({ | |
| children, | |
| RenderError = () => <></>, | |
| errorProps = null, | |
| scopes = [] | |
| }) { | |
| const { role } = useGetRole(); | |
| const permissions = PERMISSIONS[role]; | |
| const permissionGranted = hasPermission({ permissions, scopes }); |
This file contains hidden or 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
| <PermissionsGate | |
| RenderError={() => <p>You shall not pass!</p>} | |
| scopes={[SCOPES.canCreate]} | |
| > | |
| <img alt="" className="vault-image" src={VAULT} /> | |
| <h1>Private content</h1> | |
| <p>Must be an editor to view</p> | |
| </PermissionsGate> |
This file contains hidden or 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
| export default function PermissionsGate({ | |
| children, | |
| RenderError = () => <></>, | |
| errorProps = null, | |
| scopes = [] | |
| }) { | |
| const { role } = useGetRole(); | |
| const permissions = PERMISSIONS[role]; | |
| const permissionGranted = hasPermission({ permissions, scopes }); |
This file contains hidden or 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
| <PermissionsGate | |
| scopes={[SCOPES.canEdit]} | |
| > | |
| <img alt="" className="vault-image" src={VAULT} /> | |
| <h1>Private content</h1> | |
| <p>Must be an editor to view</p> | |
| </PermissionsGate> |
This file contains hidden or 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
| export const ROLES = { | |
| viewer: "VIEWER", | |
| editor: "EDITOR", | |
| owner: "OWNER" | |
| }; | |
| export const SCOPES = { | |
| canCreate: "can-create", | |
| canEdit: "can-edit", | |
| canDelete: "can-delete", |
This file contains hidden or 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
| import { cloneElement } from "react"; | |
| import { PERMISSIONS } from "./permission-maps"; | |
| import { useGetRole } from "./useGetRole"; | |
| const hasPermission = ({ permissions, scopes }) => { | |
| const scopesMap = {}; | |
| scopes.forEach((scope) => { | |
| scopesMap[scope] = true; | |
| }); |
This file contains hidden or 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
| processInventory = (action, widget) => { | |
| displayLoader(); | |
| return this.updateInventories(action, widget); | |
| }; | |
| updateInventories = (action, widget) => { | |
| switch (action) { | |
| case "REQUEST": { | |
| const { first, inventoryItems } = this.requestInventory( | |
| this.inventoryItems |
This file contains hidden or 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
| processInventory = (widget) => { | |
| displayLoader(); | |
| switch (this.action) { | |
| case "REQUEST": { | |
| const { first, inventoryItems } = this.requestInventory( | |
| this.inventoryItems | |
| ); | |
| this.inventoryItems = inventoryItems; | |
| return first; | |
| } |