forcedTrialModal.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import {Fragment} from 'react';
  2. import {css} from '@emotion/react';
  3. import styled from '@emotion/styled';
  4. import type {ModalRenderProps} from 'sentry/actionCreators/modal';
  5. import {Button} from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent';
  8. import HighlightModalContainer from 'sentry/components/highlightModalContainer';
  9. import {t} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import type {Integration} from 'sentry/types/integrations';
  12. import type {Organization} from 'sentry/types/organization';
  13. import UpgradeOrTrialButton from 'getsentry/components/upgradeOrTrialButton';
  14. import withSubscription from 'getsentry/components/withSubscription';
  15. import type {Subscription} from 'getsentry/types';
  16. import {getTrialDaysLeft, getTrialLength} from 'getsentry/utils/billing';
  17. const INTEGRATIONS_TO_CHECK = ['slack'];
  18. type Props = Pick<ModalRenderProps, 'closeModal'> &
  19. DeprecatedAsyncComponent['props'] & {
  20. organization: Organization;
  21. subscription: Subscription;
  22. };
  23. type State = DeprecatedAsyncComponent['state'] & {
  24. configurations: Integration[] | null;
  25. };
  26. class ForcedTrialModal extends DeprecatedAsyncComponent<Props, State> {
  27. getEndpoints(): ReturnType<DeprecatedAsyncComponent['getEndpoints']> {
  28. const {organization} = this.props;
  29. return [
  30. [
  31. 'configurations',
  32. `/organizations/${organization.slug}/integrations/?includeConfig=0`,
  33. ],
  34. ];
  35. }
  36. getDefaultState(): State {
  37. return {
  38. ...super.getDefaultState(),
  39. configurations: null,
  40. };
  41. }
  42. get hasBillingScope() {
  43. const {organization} = this.props;
  44. return organization.access.includes('org:billing');
  45. }
  46. get getTrialDaysLeft() {
  47. const {subscription} = this.props;
  48. return getTrialDaysLeft(subscription);
  49. }
  50. get disallowedIntegration() {
  51. const {configurations} = this.state;
  52. return (configurations || []).find(config =>
  53. INTEGRATIONS_TO_CHECK.includes(config.provider.slug)
  54. );
  55. }
  56. get mainHeader() {
  57. const daysLeft = this.getTrialDaysLeft;
  58. const configuration = this.disallowedIntegration;
  59. if (configuration) {
  60. return t(
  61. 'Your %s integration will stop working in %s days',
  62. configuration.provider.name,
  63. daysLeft
  64. );
  65. }
  66. return this.hasBillingScope
  67. ? t('Members may lose access to Sentry in %s days', daysLeft)
  68. : t('You may lose access to Sentry in %s days', daysLeft);
  69. }
  70. get firstParagraph() {
  71. const {organization} = this.props;
  72. const configuration = this.disallowedIntegration;
  73. if (configuration) {
  74. return t(
  75. `Your %s organization is on the Developer plan and does not support the %s integration.`,
  76. organization.slug,
  77. configuration.provider.name
  78. );
  79. }
  80. return t(
  81. `Your %s organization is on the Developer plan and does not allow for multiple members.`,
  82. organization.slug
  83. );
  84. }
  85. get secondParagraph() {
  86. const configuration = this.disallowedIntegration;
  87. if (configuration) {
  88. return (
  89. <Fragment>
  90. {t(
  91. 'In %s days, your %s integration will be disabled.',
  92. this.getTrialDaysLeft,
  93. configuration.provider.name
  94. )}{' '}
  95. {t(
  96. 'Upgrade to our Team or Business plan so you can keep using %s.',
  97. configuration.provider.name
  98. )}
  99. </Fragment>
  100. );
  101. }
  102. return (
  103. <Fragment>
  104. {t(
  105. 'In %s days, your organization will be limited to 1 user.',
  106. this.getTrialDaysLeft
  107. )}{' '}
  108. {this.hasBillingScope
  109. ? t('Upgrade to our Team or Business plan so your members can retain access.')
  110. : t(
  111. 'Ask your organization owner to upgrade to our Team or Business plan to retain access.'
  112. )}
  113. </Fragment>
  114. );
  115. }
  116. renderBody() {
  117. const {organization, subscription, closeModal} = this.props;
  118. const daysLeft = getTrialDaysLeft(subscription);
  119. if (daysLeft < 0) {
  120. return null;
  121. }
  122. // TODO: add explicit check that org has additional members if no restricted integrations
  123. const hasBillingScope = organization.access.includes('org:billing');
  124. return (
  125. <HighlightModalContainer>
  126. <div>
  127. <TrialCheckInfo>
  128. <Subheader>
  129. {t('%s-day Business Trial', getTrialLength(organization))}
  130. </Subheader>
  131. <h2>{this.mainHeader}</h2>
  132. <p>{this.firstParagraph}</p>
  133. <br />
  134. <p>{this.secondParagraph}</p>
  135. </TrialCheckInfo>
  136. <StyledButtonBar gap={2}>
  137. <UpgradeOrTrialButton
  138. source="force_trial_modal"
  139. action="upgrade"
  140. subscription={subscription}
  141. organization={organization}
  142. onSuccess={closeModal}
  143. >
  144. {hasBillingScope ? t('Upgrade') : t('Request Upgrade')}
  145. </UpgradeOrTrialButton>
  146. <Button data-test-id="maybe-later" priority="default" onClick={closeModal}>
  147. {t('Continue with Trial')}
  148. </Button>
  149. </StyledButtonBar>
  150. </div>
  151. </HighlightModalContainer>
  152. );
  153. }
  154. }
  155. const TrialCheckInfo = styled('div')`
  156. padding: ${space(3)} 0;
  157. p {
  158. font-size: ${p => p.theme.fontSizeMedium};
  159. margin: 0;
  160. }
  161. h2 {
  162. font-size: 1.5em;
  163. }
  164. `;
  165. export const modalCss = css`
  166. width: 100%;
  167. max-width: 730px;
  168. [role='document'] {
  169. position: relative;
  170. padding: 70px 80px;
  171. overflow: hidden;
  172. }
  173. `;
  174. const Subheader = styled('h4')`
  175. margin-bottom: ${space(2)};
  176. text-transform: uppercase;
  177. font-weight: bold;
  178. color: ${p => p.theme.purple300};
  179. font-size: ${p => p.theme.fontSizeExtraSmall};
  180. `;
  181. const StyledButtonBar = styled(ButtonBar)`
  182. margin-top: ${space(2)};
  183. max-width: fit-content;
  184. `;
  185. export default withSubscription(ForcedTrialModal);