accountNotifications.tsx 2.8 KB

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