notificationSettingsByOrganization.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import Form from 'sentry/components/forms/form';
  2. import Panel from 'sentry/components/panels/panel';
  3. import {t} from 'sentry/locale';
  4. import {OrganizationSummary} from 'sentry/types';
  5. import withOrganizations from 'sentry/utils/withOrganizations';
  6. import {
  7. NotificationSettingsByProviderObject,
  8. NotificationSettingsObject,
  9. } from 'sentry/views/settings/account/notifications/constants';
  10. import {StyledJsonForm} from 'sentry/views/settings/account/notifications/notificationSettingsByProjects';
  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. function NotificationSettingsByOrganization({
  26. notificationType,
  27. notificationSettings,
  28. onChange,
  29. onSubmitSuccess,
  30. organizations,
  31. }: Props) {
  32. return (
  33. <Panel>
  34. <Form
  35. saveOnBlur
  36. apiMethod="PUT"
  37. apiEndpoint="/users/me/notification-settings/"
  38. initialData={getParentData(notificationType, notificationSettings, organizations)}
  39. onSubmitSuccess={onSubmitSuccess}
  40. >
  41. <StyledJsonForm
  42. title={t('Organizations')}
  43. fields={organizations.map(organization => {
  44. return getParentField(
  45. notificationType,
  46. notificationSettings,
  47. organization,
  48. onChange
  49. );
  50. })}
  51. />
  52. </Form>
  53. </Panel>
  54. );
  55. }
  56. export default withOrganizations(NotificationSettingsByOrganization);