relocationUnpauseModal.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {Fragment} from 'react';
  2. import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
  3. import type {ModalRenderProps} from 'sentry/actionCreators/modal';
  4. import ApiForm from 'sentry/components/forms/apiForm';
  5. import SelectField from 'sentry/components/forms/fields/selectField';
  6. import type {Relocation} from 'admin/types';
  7. import {RelocationSteps} from 'admin/types';
  8. import titleCase from 'getsentry/utils/titleCase';
  9. type Props = ModalRenderProps & {
  10. relocation: Relocation;
  11. onSuccess?: (relocation: Relocation) => void;
  12. };
  13. function RelocationUnpauseModal({
  14. Body,
  15. Header,
  16. relocation,
  17. onSuccess,
  18. closeModal,
  19. }: Props) {
  20. const currentStep = RelocationSteps[relocation.step];
  21. const choices = Object.keys(RelocationSteps)
  22. // @ts-expect-error TS(7015): Element implicitly has an 'any' type because index... Remove this comment to see the full error message
  23. .filter(step => RelocationSteps[step] > currentStep && step !== 'COMPLETED')
  24. .map(step => [step, titleCase(step)]);
  25. choices.unshift(['NONE', 'Completion']);
  26. return (
  27. <Fragment>
  28. <Header closeButton>Unpause Relocation</Header>
  29. <Body>
  30. <ApiForm
  31. apiMethod="PUT"
  32. apiEndpoint={`/relocations/${relocation.uuid}/unpause/`}
  33. hostOverride={relocation.region.url}
  34. onSubmit={(data: Record<string, any>) => {
  35. const payload: Record<string, any> = {};
  36. if (data.untilStep !== 'NONE') {
  37. payload.untilStep = data.untilStep;
  38. }
  39. return payload;
  40. }}
  41. onSubmitSuccess={(rawRelocation: Relocation) => {
  42. if (onSuccess) {
  43. onSuccess(rawRelocation);
  44. }
  45. closeModal();
  46. addSuccessMessage(
  47. 'All current or future pauses for this relocation have been removed.'
  48. );
  49. }}
  50. onSubmitError={error => {
  51. addErrorMessage(error.responseJSON?.detail);
  52. }}
  53. initialData={relocation || {untilStep: 'NONE'}}
  54. submitLabel="Unpause"
  55. >
  56. <SelectField
  57. choices={choices}
  58. flexibleControlStateSize={false}
  59. help="Optionally select another future step to pause at:"
  60. inline={false}
  61. label="Until"
  62. name="untilStep"
  63. stacked
  64. />
  65. </ApiForm>
  66. </Body>
  67. </Fragment>
  68. );
  69. }
  70. export default RelocationUnpauseModal;