subscriptionBox.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import styled from '@emotion/styled';
  2. import FeatureBadge from 'sentry/components/badge/featureBadge';
  3. import Checkbox from 'sentry/components/checkbox';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {Organization} from 'sentry/types/organization';
  8. import withOrganization from 'sentry/utils/withOrganization';
  9. import type {EVENT_CHOICES} from 'sentry/views/settings/organizationDeveloperSettings/constants';
  10. import {PERMISSIONS_MAP} from 'sentry/views/settings/organizationDeveloperSettings/constants';
  11. type Resource = (typeof EVENT_CHOICES)[number];
  12. type Props = {
  13. checked: boolean;
  14. disabledFromPermissions: boolean;
  15. isNew: boolean;
  16. onChange: (resource: Resource, checked: boolean) => void;
  17. organization: Organization;
  18. resource: Resource;
  19. webhookDisabled?: boolean;
  20. };
  21. function SubscriptionBox({
  22. checked,
  23. disabledFromPermissions,
  24. isNew,
  25. onChange,
  26. organization,
  27. resource,
  28. webhookDisabled = false,
  29. }: Props) {
  30. const {features} = organization;
  31. let disabled = disabledFromPermissions || webhookDisabled;
  32. let message = t(
  33. "Must have at least 'Read' permissions enabled for %s",
  34. PERMISSIONS_MAP[resource]
  35. );
  36. if (resource === 'error' && !features.includes('integrations-event-hooks')) {
  37. disabled = true;
  38. message = t(
  39. 'Your organization does not have access to the error subscription resource.'
  40. );
  41. }
  42. if (webhookDisabled) {
  43. message = t('Cannot enable webhook subscription without specifying a webhook url');
  44. }
  45. const DESCRIPTIONS: Record<(typeof EVENT_CHOICES)[number], string> = {
  46. // Swap ignored for archived if the feature is enabled
  47. issue: organization.features.includes('webhooks-unresolved')
  48. ? `created, resolved, assigned, archived, unresolved`
  49. : `created, resolved, assigned, archived`,
  50. error: 'created',
  51. comment: 'created, edited, deleted',
  52. };
  53. return (
  54. <Tooltip disabled={!disabled} title={message} key={resource}>
  55. <SubscriptionGridItem disabled={disabled}>
  56. <SubscriptionInfo>
  57. <SubscriptionTitle>
  58. {resource}
  59. {isNew && <FeatureBadge type="new" />}
  60. </SubscriptionTitle>
  61. <SubscriptionDescription>{DESCRIPTIONS[resource]}</SubscriptionDescription>
  62. </SubscriptionInfo>
  63. <Checkbox
  64. key={`${resource}${checked}`}
  65. aria-label={resource}
  66. disabled={disabled}
  67. id={resource}
  68. value={resource}
  69. checked={checked}
  70. onChange={evt => onChange(resource, evt.target.checked)}
  71. />
  72. </SubscriptionGridItem>
  73. </Tooltip>
  74. );
  75. }
  76. export default withOrganization(SubscriptionBox);
  77. const SubscriptionGridItem = styled('div')<{disabled: boolean}>`
  78. display: flex;
  79. justify-content: space-between;
  80. background: ${p => p.theme.backgroundSecondary};
  81. opacity: ${p => (p.disabled ? 0.3 : 1)};
  82. border-radius: ${p => p.theme.borderRadius};
  83. margin: ${space(1.5)};
  84. padding: ${space(1.5)};
  85. box-sizing: border-box;
  86. `;
  87. const SubscriptionInfo = styled('div')`
  88. display: flex;
  89. flex-direction: column;
  90. align-self: center;
  91. `;
  92. const SubscriptionDescription = styled('div')`
  93. font-size: ${p => p.theme.fontSizeMedium};
  94. line-height: 1;
  95. color: ${p => p.theme.gray300};
  96. `;
  97. const SubscriptionTitle = styled('div')`
  98. font-size: ${p => p.theme.fontSizeLarge};
  99. line-height: 1;
  100. color: ${p => p.theme.textColor};
  101. white-space: nowrap;
  102. margin-bottom: ${space(0.75)};
  103. `;