disabledAuthProvider.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import type {ChildrenRenderFn} from 'sentry/components/acl/feature';
  2. import {Button} from 'sentry/components/button';
  3. import {Tag} from 'sentry/components/core/badge/tag';
  4. import {IconBusiness} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import type {Organization} from 'sentry/types/organization';
  7. import {openUpsellModal} from 'getsentry/actionCreators/modal';
  8. import {displayPlanName} from 'getsentry/utils/billing';
  9. import PlanFeature from './planFeature';
  10. type ChildRenderProps = Parameters<ChildrenRenderFn>[0] & {
  11. renderInstallButton: (props: any) => React.ReactNode;
  12. };
  13. type ChildRenderFunction = (options: ChildRenderProps) => React.ReactNode;
  14. type Props = {
  15. children: React.ReactNode | ChildRenderFunction;
  16. features: string[];
  17. hasFeature: boolean;
  18. organization: Organization;
  19. };
  20. function DisabledAuthProvider({organization, features, children, ...props}: Props) {
  21. return (
  22. <PlanFeature {...{organization, features}}>
  23. {({plan}) =>
  24. typeof children === 'function'
  25. ? children({
  26. ...props,
  27. organization,
  28. features,
  29. renderDisabled: () => (
  30. <Tag icon={<IconBusiness />}>{t('%s Plan', displayPlanName(plan))}</Tag>
  31. ),
  32. renderInstallButton: p => (
  33. <Button
  34. size="sm"
  35. priority="primary"
  36. icon={<IconBusiness />}
  37. onClick={() =>
  38. openUpsellModal({
  39. organization,
  40. source: `feature.auth_provider.${p.provider.key}`,
  41. defaultSelection: 'sso',
  42. })
  43. }
  44. >
  45. {t('Learn More')}
  46. </Button>
  47. ),
  48. })
  49. : children
  50. }
  51. </PlanFeature>
  52. );
  53. }
  54. export default DisabledAuthProvider;