accountNotifications.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import styled from '@emotion/styled';
  2. import AlertLink from 'app/components/alertLink';
  3. import Link from 'app/components/links/link';
  4. import {PanelFooter} from 'app/components/panels';
  5. import accountNotificationFields from 'app/data/forms/accountNotificationSettings';
  6. import {IconChevron, IconMail} from 'app/icons';
  7. import {t} from 'app/locale';
  8. import {OrganizationSummary} from 'app/types';
  9. import withOrganizations from 'app/utils/withOrganizations';
  10. import AsyncView from 'app/views/asyncView';
  11. import NotificationSettings from 'app/views/settings/account/notifications/notificationSettings';
  12. import Form from 'app/views/settings/components/forms/form';
  13. import JsonForm from 'app/views/settings/components/forms/jsonForm';
  14. import SettingsPageHeader from 'app/views/settings/components/settingsPageHeader';
  15. const FINE_TUNE_FOOTERS = {
  16. [t('Alerts')]: {
  17. text: t('Fine tune alerts by project'),
  18. path: 'alerts/',
  19. },
  20. [t('Workflow Notifications')]: {
  21. text: t('Fine tune workflow notifications by project'),
  22. path: 'workflow/',
  23. },
  24. [t('Email Routing')]: {
  25. text: t('Fine tune email routing by project'),
  26. path: 'email/',
  27. },
  28. [t('Weekly Reports')]: {
  29. text: t('Fine tune weekly reports by organization'),
  30. path: 'reports/',
  31. },
  32. [t('Deploy Notifications')]: {
  33. text: t('Fine tune deploy notifications by organization'),
  34. path: 'deploy/',
  35. },
  36. };
  37. type Props = AsyncView['props'] & {
  38. organizations: OrganizationSummary[];
  39. };
  40. type State = AsyncView['state'] & {
  41. data: Record<string, unknown> | null;
  42. };
  43. class AccountNotifications extends AsyncView<Props, State> {
  44. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  45. return [['data', '/users/me/notifications/']];
  46. }
  47. getTitle() {
  48. return 'Notifications';
  49. }
  50. renderBody() {
  51. const {organizations} = this.props;
  52. if (
  53. organizations.some(organization =>
  54. organization.features.includes('notification-platform')
  55. )
  56. ) {
  57. return <NotificationSettings />;
  58. }
  59. return (
  60. <div>
  61. <SettingsPageHeader title="Notifications" />
  62. <Form
  63. initialData={this.state.data ?? undefined}
  64. saveOnBlur
  65. apiMethod="PUT"
  66. apiEndpoint="/users/me/notifications/"
  67. >
  68. <JsonForm
  69. forms={accountNotificationFields}
  70. renderFooter={({title}) => {
  71. if (typeof title !== 'string') {
  72. return null;
  73. }
  74. if (FINE_TUNE_FOOTERS[title]) {
  75. return <FineTuningFooter {...FINE_TUNE_FOOTERS[title]} />;
  76. }
  77. return null;
  78. }}
  79. />
  80. <AlertLink to="/settings/account/emails" icon={<IconMail />}>
  81. {t('Looking to add or remove an email address? Use the emails panel.')}
  82. </AlertLink>
  83. </Form>
  84. </div>
  85. );
  86. }
  87. }
  88. const FineTuneLink = styled(Link)`
  89. display: flex;
  90. justify-content: space-between;
  91. padding: 15px 20px;
  92. color: inherit;
  93. `;
  94. type FooterProps = {
  95. path: string;
  96. text: string;
  97. };
  98. const FineTuningFooter = ({path, text}: FooterProps) => (
  99. <PanelFooter css={{borderTop: 'none'}}>
  100. <FineTuneLink to={`/settings/account/notifications/${path}`}>
  101. <span>{text}</span>
  102. <IconChevron direction="right" size="15px" />
  103. </FineTuneLink>
  104. </PanelFooter>
  105. );
  106. export default withOrganizations(AccountNotifications);