checkMemberPermission.tsx 1017 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React from 'react'
  2. import {
  3. CREATE_ORGANIZATION_PROJECT
  4. } from 'containers/App/constants'
  5. import { IOrganization } from 'containers/Organizations/types'
  6. interface IComponentPermissionProps {
  7. size?: string
  8. type?: string
  9. icon?: string
  10. onClick?: any
  11. className?: string
  12. permission?: IOrganization
  13. }
  14. export default (currentOrganization, code) => (WrapperComponent) => {
  15. class ComponentPermission extends React.PureComponent<IComponentPermissionProps, {}> {
  16. public render () {
  17. let role = void 0
  18. if (currentOrganization && currentOrganization.role) {
  19. role = currentOrganization.role
  20. }
  21. return role && role === 1
  22. ? <WrapperComponent {...this.props}>{this.props.children}</WrapperComponent>
  23. : currentOrganization && currentOrganization.allowCreateProject && code === CREATE_ORGANIZATION_PROJECT
  24. ? <WrapperComponent {...this.props}>{this.props.children}</WrapperComponent>
  25. : (<span/>)
  26. }
  27. }
  28. return ComponentPermission
  29. }