disabledAllProjectsSelect.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {Button} from 'sentry/components/button';
  2. import {IconBusiness} from 'sentry/icons';
  3. import {t} from 'sentry/locale';
  4. import UpsellProvider from 'getsentry/components/upsellProvider';
  5. type RenderShowAllButtonProps = {
  6. canShowAllProjects: boolean;
  7. onButtonClick: () => void;
  8. };
  9. type ChildRenderProps = {
  10. renderShowAllButton?: (p: RenderShowAllButtonProps) => React.ReactNode;
  11. };
  12. type ChildRenderFunction = (options: ChildRenderProps) => React.ReactNode;
  13. type Props = {
  14. children: React.ReactNode | ChildRenderFunction;
  15. };
  16. const DisabledAllProjectsSelect: React.FC<Props> = ({children}: Props) => {
  17. return typeof children === 'function'
  18. ? children({
  19. renderShowAllButton: ({onButtonClick}) => {
  20. const getButtonText = (hasBillingScope: boolean, canTrial: boolean) => {
  21. // if the user has billing scope, they can always see all projects
  22. if (hasBillingScope) {
  23. return canTrial
  24. ? t('Start Free Trial to Select All')
  25. : t('Upgrade to Select All');
  26. }
  27. return canTrial
  28. ? t('Request Free Trial to Select All')
  29. : t('Request Upgrade to Select All');
  30. };
  31. // if free plan, show the upsell for upgrade or trial if it's available
  32. return (
  33. <UpsellProvider
  34. source="all-projects-select"
  35. onTrialStarted={onButtonClick}
  36. showConfirmation
  37. triggerMemberRequests
  38. >
  39. {({canTrial, onClick, hasBillingScope}) => {
  40. return (
  41. <Button
  42. priority="primary"
  43. size="xs"
  44. onClick={onClick}
  45. icon={<IconBusiness />}
  46. >
  47. {getButtonText(hasBillingScope, canTrial)}
  48. </Button>
  49. );
  50. }}
  51. </UpsellProvider>
  52. );
  53. },
  54. })
  55. : children;
  56. };
  57. export default DisabledAllProjectsSelect;