demoModeGate.tsx 759 B

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