notificationSettingsByOrganization.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {Component} from 'react';
  2. import Form from 'sentry/components/forms/form';
  3. import JsonForm from 'sentry/components/forms/jsonForm';
  4. import {t} from 'sentry/locale';
  5. import {OrganizationSummary} from 'sentry/types';
  6. import withOrganizations from 'sentry/utils/withOrganizations';
  7. import {
  8. NotificationSettingsByProviderObject,
  9. NotificationSettingsObject,
  10. } from 'sentry/views/settings/account/notifications/constants';
  11. import {
  12. getParentData,
  13. getParentField,
  14. } from 'sentry/views/settings/account/notifications/utils';
  15. type Props = {
  16. notificationSettings: NotificationSettingsObject;
  17. notificationType: string;
  18. onChange: (
  19. changedData: NotificationSettingsByProviderObject,
  20. parentId: string
  21. ) => NotificationSettingsObject;
  22. onSubmitSuccess: () => void;
  23. organizations: OrganizationSummary[];
  24. };
  25. type State = {};
  26. class NotificationSettingsByOrganization extends Component<Props, State> {
  27. render() {
  28. const {
  29. notificationType,
  30. notificationSettings,
  31. onChange,
  32. onSubmitSuccess,
  33. organizations,
  34. } = this.props;
  35. return (
  36. <Form
  37. saveOnBlur
  38. apiMethod="PUT"
  39. apiEndpoint="/users/me/notification-settings/"
  40. initialData={getParentData(notificationType, notificationSettings, organizations)}
  41. onSubmitSuccess={onSubmitSuccess}
  42. >
  43. <JsonForm
  44. title={t('Organizations')}
  45. fields={organizations.map(organization =>
  46. getParentField(notificationType, notificationSettings, organization, onChange)
  47. )}
  48. />
  49. </Form>
  50. );
  51. }
  52. }
  53. export default withOrganizations(NotificationSettingsByOrganization);