issue.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import {Fragment} from 'react';
  2. import {Alert} from 'sentry/components/core/alert';
  3. import ApiForm from 'sentry/components/forms/apiForm';
  4. import HiddenField from 'sentry/components/forms/fields/hiddenField';
  5. import ExternalLink from 'sentry/components/links/externalLink';
  6. import Link from 'sentry/components/links/link';
  7. import LoadingIndicator from 'sentry/components/loadingIndicator';
  8. import NarrowLayout from 'sentry/components/narrowLayout';
  9. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  10. import {t, tct} from 'sentry/locale';
  11. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  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 {isPending, isError, data} = useApiQuery<UnsubscribeResponse>(
  49. [endpoint, {query: {_: signature}}],
  50. {staleTime: 0}
  51. );
  52. if (isPending) {
  53. return <LoadingIndicator />;
  54. }
  55. if (isError) {
  56. return (
  57. <Alert.Container>
  58. <Alert type="error">
  59. {t('There was an error loading unsubscribe data. Your link may have expired.')}
  60. </Alert>
  61. </Alert.Container>
  62. );
  63. }
  64. return (
  65. <Fragment>
  66. <p>
  67. <strong>{t('Account')}</strong>: {data.displayName}
  68. </p>
  69. <p>
  70. {tct('You are about to unsubscribe from [docsLink] for the [viewLink].', {
  71. docsLink: (
  72. <ExternalLink href="https://docs.sentry.io/workflow/notifications/workflow/">
  73. {t('workflow notifications')}
  74. </ExternalLink>
  75. ),
  76. viewLink: <Link to={data.viewUrl}>{t('selected %s', data.type)}</Link>,
  77. })}
  78. </p>
  79. <ApiForm
  80. apiEndpoint={`${endpoint}?_=${signature}`}
  81. apiMethod="POST"
  82. submitLabel={t('Unsubscribe')}
  83. cancelLabel={t('Cancel')}
  84. onCancel={() => {
  85. // Use window.location as we're going to an HTML view
  86. window.location.assign('/auth/login/');
  87. }}
  88. onSubmitSuccess={() => {
  89. // Use window.location as we're going to an HTML view
  90. window.location.assign('/auth/login/');
  91. }}
  92. initialData={{cancel: 1}}
  93. >
  94. <HiddenField name="cancel" />
  95. </ApiForm>
  96. </Fragment>
  97. );
  98. }
  99. export default UnsubscribeIssue;