memberListHeader.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import styled from '@emotion/styled';
  2. import {Button} from 'sentry/components/button';
  3. import PanelHeader from 'sentry/components/panels/panelHeader';
  4. import {IconBusiness, IconClose} from 'sentry/icons';
  5. import {t, tct} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {Member, Organization} from 'sentry/types/organization';
  8. import isMemberDisabledFromLimit from 'sentry/utils/isMemberDisabledFromLimit';
  9. import UpsellProvider from 'getsentry/components/upsellProvider';
  10. import withSubscription from 'getsentry/components/withSubscription';
  11. import {useBillingConfig} from 'getsentry/hooks/useBillingConfig';
  12. import type {Subscription} from 'getsentry/types';
  13. import {displayPlanName, getBestPlanForUnlimitedMembers} from 'getsentry/utils/billing';
  14. type Props = {
  15. members: Member[];
  16. organization: Organization;
  17. subscription: Subscription;
  18. };
  19. function MemberListHeader({members, organization, subscription}: Props) {
  20. const hasDisabledMembers = !!members.find(isMemberDisabledFromLimit);
  21. const {data: billingConfig} = useBillingConfig({organization, subscription});
  22. const getDefaultView = () => <PanelHeader>{t('Members')}</PanelHeader>;
  23. if (!hasDisabledMembers) {
  24. return getDefaultView();
  25. }
  26. if (!billingConfig) {
  27. return getDefaultView();
  28. }
  29. // the best plan is the first one that has unlimited members
  30. const bestPlan = getBestPlanForUnlimitedMembers(billingConfig, subscription);
  31. if (!bestPlan) {
  32. return getDefaultView();
  33. }
  34. return (
  35. <PanelHeader hasButtons>
  36. {t('Members')}
  37. <Wrapper>
  38. <IconClose isCircled color="red300" />
  39. {tct('Multiple members requires [planName] Plan or above', {
  40. planName: displayPlanName(bestPlan),
  41. })}
  42. <UpsellProvider source="member-settings-table-header">
  43. {({canTrial, onClick}) => (
  44. <Button
  45. priority="default"
  46. size="xs"
  47. onClick={onClick}
  48. icon={<IconBusiness />}
  49. data-test-id="member-settings-table-header-upsell-button"
  50. >
  51. {canTrial ? t('Start Trial') : t('Upgrade')}
  52. </Button>
  53. )}
  54. </UpsellProvider>
  55. </Wrapper>
  56. </PanelHeader>
  57. );
  58. }
  59. export default withSubscription(MemberListHeader);
  60. const Wrapper = styled('div')`
  61. text-transform: none;
  62. display: grid;
  63. grid-auto-flow: column;
  64. gap: ${space(1)};
  65. align-items: center;
  66. `;