nextBillingPeriodAction.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {Fragment} from 'react';
  2. import {addSuccessMessage} from 'sentry/actionCreators/indicator';
  3. import {type ModalRenderProps, openModal} from 'sentry/actionCreators/modal';
  4. import Form from 'sentry/components/deprecatedforms/form';
  5. import useApi from 'sentry/utils/useApi';
  6. import type {Subscription} from 'getsentry/types';
  7. type Props = {
  8. onSuccess: () => void;
  9. orgId: string;
  10. subscription: Subscription;
  11. };
  12. type ModalProps = Props & ModalRenderProps;
  13. function EndPeriodEarlyModal({orgId, onSuccess, closeModal, Header, Body}: ModalProps) {
  14. const api = useApi();
  15. async function onSubmit(_: any, _onSubmitSuccess: any, onSubmitError: any) {
  16. try {
  17. const postData = {
  18. endPeriodEarly: true,
  19. };
  20. await api.requestPromise(`/customers/${orgId}/`, {
  21. method: 'PUT',
  22. data: postData,
  23. success: () => {
  24. addSuccessMessage('Currrent period ended successfully');
  25. onSuccess();
  26. },
  27. });
  28. closeModal();
  29. } catch (err) {
  30. onSubmitError({
  31. responseJSON: err.responseJSON,
  32. });
  33. }
  34. }
  35. return (
  36. <Fragment>
  37. <Header>End Current Period Immediately</Header>
  38. <Body>
  39. <Form
  40. onSubmit={onSubmit}
  41. onCancel={closeModal}
  42. submitLabel="Submit"
  43. cancelLabel="Cancel"
  44. >
  45. <p>End the current billing period immediately and start a new one.</p>
  46. </Form>
  47. </Body>
  48. </Fragment>
  49. );
  50. }
  51. type Options = Pick<Props, 'orgId' | 'subscription' | 'onSuccess'>;
  52. const triggerEndPeriodEarlyModal = (opts: Options) =>
  53. openModal(deps => <EndPeriodEarlyModal {...deps} {...opts} />);
  54. export default triggerEndPeriodEarlyModal;