firstPartyIntegrationAlertHook.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import styled from '@emotion/styled';
  2. import moment from 'moment-timezone';
  3. import {Alert} from 'sentry/components/core/alert';
  4. import {t} from 'sentry/locale';
  5. import type {Integration} from 'sentry/types/integrations';
  6. import {getUserTimezone} from 'sentry/utils/dates';
  7. import AlertContainer from 'sentry/views/settings/organizationIntegrations/integrationAlertContainer';
  8. import UpsellButton from 'getsentry/components/upsellButton';
  9. type Props = {
  10. integrations: Integration[];
  11. hideCTA?: boolean;
  12. wrapWithContainer?: boolean;
  13. };
  14. function FirstPartyIntegrationAlertHook({
  15. integrations,
  16. wrapWithContainer,
  17. hideCTA,
  18. }: Props) {
  19. const getAlertInfo = () => {
  20. const disabledIntegrations = integrations.filter(
  21. i => i.organizationIntegrationStatus === 'disabled'
  22. );
  23. if (disabledIntegrations.length > 0) {
  24. const integration = disabledIntegrations[0]!;
  25. return [
  26. t('Your %s integration has been disabled', integration.provider.name),
  27. 'disabled-integration',
  28. integration.provider.key,
  29. ];
  30. }
  31. const integrationsWithGracePeriod = integrations.filter(i => !!i.gracePeriodEnd);
  32. if (integrationsWithGracePeriod.length > 0) {
  33. const integration = integrationsWithGracePeriod[0]!;
  34. return [
  35. t(
  36. 'Your %s integration will be disabled after %s',
  37. integration.provider.name,
  38. moment(integration.gracePeriodEnd)
  39. .tz(getUserTimezone())
  40. .format('MMMM Do, YYYY h:mm A z')
  41. ),
  42. 'grace-period',
  43. integration.provider.key,
  44. ];
  45. }
  46. return [null, '', ''];
  47. };
  48. const [alert, alertType, provider] = getAlertInfo();
  49. if (!alert) {
  50. return null;
  51. }
  52. const wrappedAlert = (
  53. <Alert.Container>
  54. <Alert type="warning" showIcon>
  55. <InnerAlertWrapper>
  56. {alert}
  57. {!hideCTA && (
  58. <UpsellButton
  59. source={`integration-alert-hook-${alertType}-${provider}`}
  60. size="xs"
  61. priority="default"
  62. extraAnalyticsParams={{
  63. integration: provider,
  64. integration_type: 'first-party',
  65. }}
  66. />
  67. )}
  68. </InnerAlertWrapper>
  69. </Alert>
  70. </Alert.Container>
  71. );
  72. return wrapWithContainer ? (
  73. <AlertContainer>{wrappedAlert}</AlertContainer>
  74. ) : (
  75. wrappedAlert
  76. );
  77. }
  78. export default FirstPartyIntegrationAlertHook;
  79. const InnerAlertWrapper = styled('div')`
  80. width: 100%;
  81. display: flex;
  82. justify-content: space-between;
  83. `;