messagingIntegrationModal.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {Fragment, useEffect, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  4. import type {ModalRenderProps} from 'sentry/actionCreators/modal';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {Project} from 'sentry/types';
  8. import type {Organization} from 'sentry/types/organization';
  9. import AddIntegrationRow from 'sentry/views/alerts/rules/issue/addIntegrationRow';
  10. type Props = ModalRenderProps & {
  11. headerContent: React.ReactElement<any, any>;
  12. organization: Organization;
  13. project: Project;
  14. providerKeys: string[];
  15. bodyContent?: React.ReactElement<any, any>;
  16. };
  17. function MessagingIntegrationModal({
  18. closeModal,
  19. Header,
  20. Body,
  21. headerContent,
  22. bodyContent,
  23. providerKeys,
  24. organization,
  25. project,
  26. }: Props) {
  27. const [hasError, setHasError] = useState(false);
  28. useEffect(() => {
  29. if (hasError) {
  30. closeModal();
  31. addErrorMessage(t('Failed to load integration data'));
  32. }
  33. }, [hasError, closeModal]);
  34. return (
  35. <Fragment>
  36. <Header closeButton>{headerContent}</Header>
  37. <Body>
  38. {bodyContent}
  39. <IntegrationsWrapper>
  40. {providerKeys.map((value: string) => {
  41. return (
  42. <AddIntegrationRow
  43. key={value}
  44. providerKey={value}
  45. organization={organization}
  46. project={project}
  47. onClickHandler={closeModal}
  48. setHasError={setHasError}
  49. />
  50. );
  51. })}
  52. </IntegrationsWrapper>
  53. </Body>
  54. </Fragment>
  55. );
  56. }
  57. const IntegrationsWrapper = styled('div')`
  58. display: flex;
  59. flex-direction: column;
  60. gap: ${space(2)};
  61. `;
  62. export default MessagingIntegrationModal;