dataConsentForm.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  2. import {updateOrganization} from 'sentry/actionCreators/organizations';
  3. import Form from 'sentry/components/forms/form';
  4. import JsonForm from 'sentry/components/forms/jsonForm';
  5. import {t} from 'sentry/locale';
  6. import type {Organization} from 'sentry/types/organization';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. import withSubscription from 'getsentry/components/withSubscription';
  9. import {useGenAiConsentButtonAccess} from 'getsentry/hooks/genAiAccess';
  10. import type {Subscription} from 'getsentry/types';
  11. import trackGetsentryAnalytics from 'getsentry/utils/trackGetsentryAnalytics';
  12. import DataConsentFields from 'getsentry/views/legalAndCompliance/dataConsent';
  13. function DataConsentForm({subscription}: {subscription: Subscription}) {
  14. const organization = useOrganization();
  15. const endpoint = `/organizations/${organization.slug}/data-consent/`;
  16. const {
  17. isDisabled: isGenAiButtonDisabled,
  18. message: genAiButtonMessage,
  19. isUsRegion,
  20. hasBillingAccess,
  21. isSuperuser,
  22. hasMsaUpdated,
  23. } = useGenAiConsentButtonAccess({
  24. subscription,
  25. });
  26. const initialData = {
  27. genAIConsent: organization.genAIConsent,
  28. aggregatedDataConsent: organization.aggregatedDataConsent,
  29. };
  30. return (
  31. <Form
  32. data-test-id="data-consent"
  33. apiMethod="PUT"
  34. apiEndpoint={endpoint}
  35. saveOnBlur
  36. allowUndo
  37. initialData={initialData}
  38. onSubmitError={() => {
  39. addErrorMessage(t('Unable to save change'));
  40. }}
  41. onSubmitSuccess={(updatedOrganization: Partial<Organization>) => {
  42. updateOrganization({id: organization.id, ...updatedOrganization});
  43. }}
  44. onFieldChange={(name, value) => {
  45. if (name === 'genAIConsent') {
  46. trackGetsentryAnalytics('gen_ai_consent.settings_clicked', {
  47. organization,
  48. value,
  49. });
  50. }
  51. trackGetsentryAnalytics('data_consent_settings.updated', {
  52. organization,
  53. setting: name,
  54. value,
  55. });
  56. }}
  57. >
  58. <JsonForm
  59. additionalFieldProps={{
  60. isGenAiButtonDisabled,
  61. genAiButtonMessage,
  62. isUsRegion,
  63. hasBillingAccess,
  64. isSuperuser,
  65. hasMsaUpdated,
  66. }}
  67. forms={DataConsentFields}
  68. />
  69. </Form>
  70. );
  71. }
  72. export default withSubscription(DataConsentForm);