onDemandSpend.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import styled from '@emotion/styled';
  2. import {Button} from 'sentry/components/button';
  3. import {Input} from 'sentry/components/core/input';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import Panel from 'sentry/components/panels/panel';
  6. import PanelBody from 'sentry/components/panels/panelBody';
  7. import PanelFooter from 'sentry/components/panels/panelFooter';
  8. import {Tooltip} from 'sentry/components/tooltip';
  9. import {t, tct} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  12. import {listDisplayNames} from 'getsentry/utils/dataCategory';
  13. import StepHeader from 'getsentry/views/amCheckout/steps/stepHeader';
  14. import type {StepProps} from 'getsentry/views/amCheckout/types';
  15. type Props = StepProps;
  16. function coerceValue(value: any) {
  17. const intValue = parseInt(value, 10);
  18. if (isNaN(intValue)) {
  19. return undefined;
  20. }
  21. return Math.abs(intValue) * 100;
  22. }
  23. function OnDemandSpend({
  24. subscription,
  25. isActive,
  26. stepNumber,
  27. isCompleted,
  28. activePlan,
  29. formData,
  30. onEdit,
  31. onUpdate,
  32. onCompleteStep,
  33. }: Props) {
  34. const dollars = Number(formData.onDemandMaxSpend) / 100;
  35. const onDemandDollars = isNaN(dollars) ? '' : dollars.toString();
  36. const disabled = !(activePlan.allowOnDemand && subscription.supportsOnDemand);
  37. const title = t('On-Demand Max Spend');
  38. const oxfordCategories = listDisplayNames({
  39. plan: activePlan,
  40. categories: activePlan.checkoutCategories,
  41. });
  42. return (
  43. <Panel>
  44. <StepHeader
  45. canSkip
  46. title={title}
  47. isActive={isActive}
  48. stepNumber={stepNumber}
  49. isCompleted={isCompleted}
  50. onEdit={onEdit}
  51. />
  52. {isActive && (
  53. <PanelBody data-test-id={title}>
  54. <OnDemandRow>
  55. <Header>
  56. <div>{title}</div>
  57. <Description>
  58. {t(
  59. "On-Demand spend allows you to pay for additional data beyond your subscription's reserved event volume. Applies to %s.",
  60. oxfordCategories
  61. )}
  62. </Description>
  63. </Header>
  64. <InputContainer>
  65. <InputHeader>{t('Monthly Max')}</InputHeader>
  66. <Tooltip
  67. disabled={!disabled}
  68. title={t('On-demand is not supported for your account.')}
  69. data-test-id="ondemand-disabled-tooltip"
  70. >
  71. <Currency>
  72. <OnDemandInput
  73. aria-label="Monthly Max"
  74. autoFocus
  75. disabled={disabled}
  76. name="ondemand"
  77. type="text"
  78. inputMode="numeric"
  79. pattern="[0-9]*"
  80. maxLength={7}
  81. placeholder="e.g. 50"
  82. value={onDemandDollars}
  83. onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
  84. const cents = coerceValue(event.target.value);
  85. onUpdate({onDemandMaxSpend: cents});
  86. }}
  87. />
  88. </Currency>
  89. </Tooltip>
  90. </InputContainer>
  91. </OnDemandRow>
  92. </PanelBody>
  93. )}
  94. {isActive && (
  95. <StepFooter data-test-id={title}>
  96. <div>
  97. {tct('Need more info? [link:See on-demand pricing chart]', {
  98. link: (
  99. <ExternalLink href="https://docs.sentry.io/pricing/legacy-pricing/#per-category-pricing" />
  100. ),
  101. })}
  102. </div>
  103. <Button priority="primary" onClick={() => onCompleteStep(stepNumber)}>
  104. {t('Continue')}
  105. </Button>
  106. </StepFooter>
  107. )}
  108. </Panel>
  109. );
  110. }
  111. // body
  112. const OnDemandRow = styled('div')`
  113. display: grid;
  114. grid-template-columns: minmax(auto, 65%) minmax(auto, 25%);
  115. justify-content: space-between;
  116. gap: ${space(1)};
  117. padding: ${space(2)};
  118. align-items: center;
  119. `;
  120. const Header = styled('div')`
  121. display: inline-grid;
  122. gap: ${space(1)};
  123. font-size: ${p => p.theme.fontSizeExtraLarge};
  124. color: ${p => p.theme.textColor};
  125. `;
  126. const Description = styled(TextBlock)`
  127. font-size: ${p => p.theme.fontSizeMedium};
  128. color: ${p => p.theme.gray300};
  129. margin: 0;
  130. `;
  131. const InputContainer = styled('div')`
  132. display: grid;
  133. grid-template-rows: repeat(2, auto);
  134. gap: ${space(1.5)};
  135. align-items: center;
  136. justify-items: end;
  137. color: ${p => p.theme.textColor};
  138. `;
  139. const InputHeader = styled('div')`
  140. color: ${p => p.theme.gray300};
  141. font-size: ${p => p.theme.fontSizeSmall};
  142. text-transform: uppercase;
  143. font-weight: bold;
  144. `;
  145. const Currency = styled('span')`
  146. &::before {
  147. padding: 11px 10px 9px;
  148. position: absolute;
  149. content: '$';
  150. }
  151. `;
  152. const OnDemandInput = styled(Input)`
  153. padding-left: ${space(4)};
  154. color: ${p => p.theme.textColor};
  155. text-align: right;
  156. height: 36px;
  157. `;
  158. // footer
  159. const StepFooter = styled(PanelFooter)`
  160. padding: ${space(2)};
  161. display: grid;
  162. grid-template-columns: auto max-content;
  163. gap: ${space(1)};
  164. align-items: center;
  165. `;
  166. export default OnDemandSpend;