subscriptionBox.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 type {Organization} from 'sentry/types';
  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: `created, resolved, assigned, archived`,
  48. error: 'created',
  49. comment: 'created, edited, deleted',
  50. };
  51. return (
  52. <Tooltip disabled={!disabled} title={message} key={resource}>
  53. <SubscriptionGridItem disabled={disabled}>
  54. <SubscriptionInfo>
  55. <SubscriptionTitle>
  56. {resource}
  57. {isNew && <FeatureBadge type="new" />}
  58. </SubscriptionTitle>
  59. <SubscriptionDescription>{DESCRIPTIONS[resource]}</SubscriptionDescription>
  60. </SubscriptionInfo>
  61. <Checkbox
  62. key={`${resource}${checked}`}
  63. aria-label={resource}
  64. disabled={disabled}
  65. id={resource}
  66. value={resource}
  67. checked={checked}
  68. onChange={evt => onChange(resource, evt.target.checked)}
  69. />
  70. </SubscriptionGridItem>
  71. </Tooltip>
  72. );
  73. }
  74. export default withOrganization(SubscriptionBox);
  75. const SubscriptionGridItem = styled('div')<{disabled: boolean}>`
  76. display: flex;
  77. justify-content: space-between;
  78. background: ${p => p.theme.backgroundSecondary};
  79. opacity: ${p => (p.disabled ? 0.3 : 1)};
  80. border-radius: ${p => p.theme.borderRadius};
  81. margin: ${space(1.5)};
  82. padding: ${space(1.5)};
  83. box-sizing: border-box;
  84. `;
  85. const SubscriptionInfo = styled('div')`
  86. display: flex;
  87. flex-direction: column;
  88. align-self: center;
  89. `;
  90. const SubscriptionDescription = styled('div')`
  91. font-size: ${p => p.theme.fontSizeMedium};
  92. line-height: 1;
  93. color: ${p => p.theme.gray300};
  94. `;
  95. const SubscriptionTitle = styled('div')`
  96. font-size: ${p => p.theme.fontSizeLarge};
  97. line-height: 1;
  98. color: ${p => p.theme.textColor};
  99. white-space: nowrap;
  100. margin-bottom: ${space(0.75)};
  101. `;