sponsorshipAction.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {Component, Fragment} from 'react';
  2. import {Alert} from 'sentry/components/core/alert';
  3. import SelectField from 'sentry/components/forms/fields/selectField';
  4. import type {
  5. AdminConfirmParams,
  6. AdminConfirmRenderProps,
  7. } from 'admin/components/adminConfirmationModal';
  8. import type {Subscription} from 'getsentry/types';
  9. type Props = AdminConfirmRenderProps & {
  10. subscription: Subscription;
  11. };
  12. type State = {
  13. sponsoredType?: string | null;
  14. };
  15. /**
  16. * Rendered as part of a openAdminConfirmModal call
  17. */
  18. class SponsorshipAction extends Component<Props, State> {
  19. state: State = {
  20. sponsoredType: undefined,
  21. };
  22. componentDidMount() {
  23. this.props.setConfirmCallback(this.handleConfirm);
  24. this.props.disableConfirmButton(true);
  25. }
  26. handleChange = (value: string | null) => {
  27. this.props.disableConfirmButton(!value);
  28. this.setState({sponsoredType: value});
  29. };
  30. handleConfirm = (_params: AdminConfirmParams) => {
  31. const {sponsoredType} = this.state;
  32. const {onConfirm} = this.props;
  33. const data = {sponsoredType};
  34. onConfirm?.(data);
  35. };
  36. render() {
  37. const {subscription} = this.props;
  38. const {sponsoredType} = this.state;
  39. if (!subscription) {
  40. return null;
  41. }
  42. return (
  43. <Fragment>
  44. {subscription.isSponsored && (
  45. <Alert.Container>
  46. <Alert type="info" showIcon>
  47. This account is already sponsored.
  48. </Alert>
  49. </Alert.Container>
  50. )}
  51. <SelectField
  52. required
  53. inline={false}
  54. stacked
  55. flexibleControlStateSize
  56. label="Sponsored Type"
  57. name="sponsored-type"
  58. value={sponsoredType}
  59. onChange={(val: any) => val && this.handleChange(val)}
  60. choices={[
  61. ['education', 'Education'],
  62. ['open_source', 'Open source'],
  63. ['non_profit', 'Non-profit'],
  64. ['employee', 'Employee'],
  65. ['friends_and_family', 'Friends and family'],
  66. ]}
  67. />
  68. </Fragment>
  69. );
  70. }
  71. }
  72. export default SponsorshipAction;