notificationSettingsByOrganization.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import Form from 'sentry/components/forms/form';
  2. import JsonForm from 'sentry/components/forms/jsonForm';
  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 {
  11. getParentData,
  12. getParentField,
  13. } from 'sentry/views/settings/account/notifications/utils';
  14. type Props = {
  15. notificationSettings: NotificationSettingsObject;
  16. notificationType: string;
  17. onChange: (
  18. changedData: NotificationSettingsByProviderObject,
  19. parentId: string
  20. ) => NotificationSettingsObject;
  21. onSubmitSuccess: () => void;
  22. organizations: OrganizationSummary[];
  23. };
  24. function NotificationSettingsByOrganization({
  25. notificationType,
  26. notificationSettings,
  27. onChange,
  28. onSubmitSuccess,
  29. organizations,
  30. }: Props) {
  31. return (
  32. <Form
  33. saveOnBlur
  34. apiMethod="PUT"
  35. apiEndpoint="/users/me/notification-settings/"
  36. initialData={getParentData(notificationType, notificationSettings, organizations)}
  37. onSubmitSuccess={onSubmitSuccess}
  38. >
  39. <JsonForm
  40. title={t('Organizations')}
  41. fields={organizations.map(organization =>
  42. getParentField(notificationType, notificationSettings, organization, onChange)
  43. )}
  44. />
  45. </Form>
  46. );
  47. }
  48. export default withOrganizations(NotificationSettingsByOrganization);