useOnboardingQueryParams.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. updatedQuery[key] = newValues[key];
  33. }
  34. navigate(
  35. {
  36. ...location,
  37. query: updatedQuery,
  38. },
  39. {replace: true}
  40. );
  41. },
  42. [location, navigate]
  43. );
  44. return [params, setParams];
  45. }