demoModeGate.tsx 889 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as React from 'react';
  2. import ConfigStore from 'app/stores/configStore';
  3. import {Organization} from 'app/types';
  4. import withOrganization from 'app/utils/withOrganization';
  5. type Props = {
  6. /**
  7. * Current Organization
  8. */
  9. organization: Organization;
  10. /**
  11. * Children can be a node or a function as child.
  12. */
  13. children?: React.ReactNode;
  14. demoComponent?:
  15. | React.ReactNode
  16. | ((props: {children?: React.ReactNode}) => React.ReactNode);
  17. };
  18. /**
  19. * Component to handle demo mode switches
  20. */
  21. function DemoModeGate(props: Props) {
  22. const {organization, children, demoComponent = null} = props;
  23. if (organization?.role === 'member' && ConfigStore.get('demoMode')) {
  24. if (typeof demoComponent === 'function') {
  25. return demoComponent({children});
  26. }
  27. return demoComponent;
  28. }
  29. return children;
  30. }
  31. export default withOrganization(DemoModeGate);