startTrialButton.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {Button} from 'sentry/components/button';
  2. import {t} from 'sentry/locale';
  3. import IndicatorStore from 'sentry/stores/indicatorStore';
  4. import type {Organization} from 'sentry/types/organization';
  5. import TrialStarter from 'getsentry/components/trialStarter';
  6. type ButtonProps = React.ComponentProps<typeof Button>;
  7. type Props = React.PropsWithChildren<
  8. {
  9. organization: Organization;
  10. source: string;
  11. analyticsData?: Record<string, any>;
  12. handleClick?: () => void;
  13. onTrialFailed?: () => void;
  14. onTrialStarted?: () => void;
  15. requestData?: Record<string, unknown>;
  16. } & ButtonProps
  17. >;
  18. function StartTrialButton({
  19. children,
  20. organization,
  21. source,
  22. onTrialStarted,
  23. onTrialFailed,
  24. handleClick,
  25. requestData,
  26. analyticsData: _,
  27. ...buttonProps
  28. }: Props) {
  29. return (
  30. <TrialStarter
  31. source={source}
  32. organization={organization}
  33. onTrialFailed={() => {
  34. IndicatorStore.addError(t('Error starting trial. Please try again.'));
  35. onTrialFailed?.();
  36. }}
  37. onTrialStarted={onTrialStarted}
  38. requestData={requestData}
  39. >
  40. {({startTrial, trialStarting, trialStarted}) => (
  41. <Button
  42. disabled={trialStarting || trialStarted}
  43. data-test-id="start-trial-button"
  44. onClick={() => {
  45. handleClick?.();
  46. startTrial();
  47. }}
  48. {...buttonProps}
  49. >
  50. {children || t('Start trial')}
  51. </Button>
  52. )}
  53. </TrialStarter>
  54. );
  55. }
  56. export default StartTrialButton;