useOnboardingQueryParams.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {useCallback} from 'react';
  2. import {decodeBoolean, decodeList} from 'sentry/utils/queryString';
  3. import useLocationQuery from 'sentry/utils/url/useLocationQuery';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import {useNavigate} from 'sentry/utils/useNavigate';
  6. type QueryValues = {
  7. /**
  8. * Used to show product selection (error monitoring, tracing, profiling and session replay) for certain platforms, e.g. javascript-react
  9. */
  10. product: string[];
  11. /**
  12. * Used to show or not the integration onboarding for certain platforms, e.g. AWS (python)
  13. */
  14. showManualSetup: boolean;
  15. };
  16. export function useOnboardingQueryParams(): [
  17. params: Partial<QueryValues>,
  18. setParams: (newValues: Partial<QueryValues>) => void,
  19. ] {
  20. const location = useLocation();
  21. const navigate = useNavigate();
  22. const params = useLocationQuery({
  23. fields: {
  24. product: decodeList,
  25. showManualSetup: decodeBoolean,
  26. },
  27. });
  28. const setParams = useCallback(
  29. (newValues: Partial<QueryValues>) => {
  30. const updatedQuery = {...location.query};
  31. for (const key in newValues) {
  32. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  33. updatedQuery[key] = newValues[key];
  34. }
  35. navigate(
  36. {
  37. ...location,
  38. query: updatedQuery,
  39. },
  40. {replace: true}
  41. );
  42. },
  43. [location, navigate]
  44. );
  45. return [params, setParams];
  46. }