genAiAccess.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {t} from 'sentry/locale';
  2. import {defined} from 'sentry/utils';
  3. import {getRegionDataFromOrganization} from 'sentry/utils/regions';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. import {useUser} from 'sentry/utils/useUser';
  6. import {BillingType, type Subscription} from 'getsentry/types';
  7. export function useGenAiConsentButtonAccess({
  8. subscription,
  9. }: {
  10. subscription: Subscription;
  11. }) {
  12. const user = useUser();
  13. const organization = useOrganization();
  14. const regionData = getRegionDataFromOrganization(organization);
  15. const isUsRegion = regionData?.name === 'us';
  16. const isTouchCustomer = subscription.type === BillingType.INVOICED;
  17. const hasMsaUpdated =
  18. defined(subscription.msaUpdatedForDataConsent) &&
  19. subscription.msaUpdatedForDataConsent;
  20. const isTouchCustomerAndNeedsMsaUpdate = isTouchCustomer && !hasMsaUpdated;
  21. const hasBillingAccess = organization.access.includes('org:billing');
  22. const fieldsToExport = {
  23. hasBillingAccess,
  24. isTouchCustomerAndNeedsMsaUpdate,
  25. isUsRegion,
  26. hasMsaUpdated,
  27. isSuperuser: user?.isSuperuser,
  28. };
  29. const conditions = [
  30. {
  31. check: !isUsRegion,
  32. message: t('This feature is not available in your region.'),
  33. },
  34. {
  35. check: isTouchCustomerAndNeedsMsaUpdate,
  36. message: t(
  37. 'These changes require updates to your account. Please contact your customer success manager to learn more.'
  38. ),
  39. },
  40. {
  41. check: !hasBillingAccess && !user?.isSuperuser,
  42. message: t(
  43. "You don't have access to manage these billing and subscription details."
  44. ),
  45. },
  46. ];
  47. const matchingCondition = conditions.find(condition => condition.check);
  48. return {
  49. ...fieldsToExport,
  50. isDisabled: !!matchingCondition,
  51. message: matchingCondition?.message ?? null,
  52. };
  53. }