subscriptionBox.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import styled from '@emotion/styled';
  2. import Checkbox from 'sentry/components/checkbox';
  3. import FeatureBadge from 'sentry/components/featureBadge';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {Organization} from 'sentry/types';
  8. import withOrganization from 'sentry/utils/withOrganization';
  9. import {
  10. EVENT_CHOICES,
  11. PERMISSIONS_MAP,
  12. } from 'sentry/views/settings/organizationDeveloperSettings/constants';
  13. type Resource = (typeof EVENT_CHOICES)[number];
  14. type Props = {
  15. checked: boolean;
  16. disabledFromPermissions: boolean;
  17. isNew: boolean;
  18. onChange: (resource: Resource, checked: boolean) => void;
  19. organization: Organization;
  20. resource: Resource;
  21. webhookDisabled?: boolean;
  22. };
  23. function SubscriptionBox({
  24. checked,
  25. disabledFromPermissions,
  26. isNew,
  27. onChange,
  28. organization,
  29. resource,
  30. webhookDisabled = false,
  31. }: Props) {
  32. const {features} = organization;
  33. let disabled = disabledFromPermissions || webhookDisabled;
  34. let message = t(
  35. "Must have at least 'Read' permissions enabled for %s",
  36. PERMISSIONS_MAP[resource]
  37. );
  38. if (resource === 'error' && !features.includes('integrations-event-hooks')) {
  39. disabled = true;
  40. message = t(
  41. 'Your organization does not have access to the error subscription resource.'
  42. );
  43. }
  44. if (webhookDisabled) {
  45. message = t('Cannot enable webhook subscription without specifying a webhook url');
  46. }
  47. const DESCRIPTIONS: Record<(typeof EVENT_CHOICES)[number], string> = {
  48. // Swap ignored for archived if the feature is enabled
  49. issue: `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. `;