demoModeGate.tsx 865 B

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