issue.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import {Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import Alert from 'sentry/components/alert';
  4. import ApiForm from 'sentry/components/forms/apiForm';
  5. import HiddenField from 'sentry/components/forms/fields/hiddenField';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import Link from 'sentry/components/links/link';
  8. import LoadingIndicator from 'sentry/components/loadingIndicator';
  9. import NarrowLayout from 'sentry/components/narrowLayout';
  10. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  11. import {t, tct} from 'sentry/locale';
  12. import {useApiQuery} from 'sentry/utils/queryClient';
  13. import {decodeScalar} from 'sentry/utils/queryString';
  14. import {useParams} from 'sentry/utils/useParams';
  15. type RouteParams = {
  16. id: string;
  17. orgId: string;
  18. };
  19. type Props = RouteComponentProps<RouteParams, {}>;
  20. function UnsubscribeIssue({location}: Props) {
  21. const signature = decodeScalar(location.query._);
  22. const params = useParams();
  23. return (
  24. <SentryDocumentTitle title={t('Issue Notification Unsubscribe')}>
  25. <NarrowLayout>
  26. <h3>{t('Issue Notification Unsubscribe')}</h3>
  27. <UnsubscribeBody
  28. signature={signature}
  29. orgSlug={params.orgId}
  30. issueId={params.id}
  31. />
  32. </NarrowLayout>
  33. </SentryDocumentTitle>
  34. );
  35. }
  36. interface UnsubscribeResponse {
  37. displayName: string;
  38. type: string;
  39. viewUrl: string;
  40. }
  41. type BodyProps = {
  42. issueId: string;
  43. orgSlug: string;
  44. signature?: string;
  45. };
  46. function UnsubscribeBody({orgSlug, issueId, signature}: BodyProps) {
  47. const endpoint = `/organizations/${orgSlug}/unsubscribe/issue/${issueId}/`;
  48. const {isLoading, isError, data} = useApiQuery<UnsubscribeResponse>(
  49. [endpoint, {query: {_: signature}}],
  50. {staleTime: 0}
  51. );
  52. if (isLoading) {
  53. return <LoadingIndicator />;
  54. }
  55. if (isError) {
  56. return (
  57. <Alert type="error">
  58. {t('There was an error loading unsubscribe data. Your link may have expired.')}
  59. </Alert>
  60. );
  61. }
  62. return (
  63. <Fragment>
  64. <p>
  65. <strong>{t('Account')}</strong>: {data.displayName}
  66. </p>
  67. <p>
  68. {tct('You are about to unsubscribe from [docsLink] for the [viewLink].', {
  69. docsLink: (
  70. <ExternalLink href="https://docs.sentry.io/workflow/notifications/workflow/">
  71. {t('workflow notifications')}
  72. </ExternalLink>
  73. ),
  74. viewLink: <Link to={data.viewUrl}>{t('selected %s', data.type)}</Link>,
  75. })}
  76. </p>
  77. <ApiForm
  78. apiEndpoint={`${endpoint}?_=${signature}`}
  79. apiMethod="POST"
  80. submitLabel={t('Unsubscribe')}
  81. cancelLabel={t('Cancel')}
  82. onCancel={() => {
  83. // Use window.location as we're going to an HTML view
  84. window.location.assign('/auth/login/');
  85. }}
  86. onSubmitSuccess={() => {
  87. // Use window.location as we're going to an HTML view
  88. window.location.assign('/auth/login/');
  89. }}
  90. initialData={{cancel: 1}}
  91. >
  92. <HiddenField name="cancel" />
  93. </ApiForm>
  94. </Fragment>
  95. );
  96. }
  97. export default UnsubscribeIssue;