platformSelection.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {useEffect, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {motion} from 'framer-motion';
  4. import PlatformPicker from 'sentry/components/platformPicker';
  5. import {PlatformKey} from 'sentry/data/platformCategories';
  6. import {t} from 'sentry/locale';
  7. import testableTransition from 'sentry/utils/testableTransition';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import StepHeading from 'sentry/views/onboarding/components/stepHeading';
  10. import CreateProjectsFooter from './components/createProjectsFooter';
  11. import {StepProps} from './types';
  12. import {usePersistedOnboardingState} from './utils';
  13. export function PlatformSelection(props: StepProps) {
  14. const organization = useOrganization();
  15. const [selectedPlatform, setSelectedPlatform] = useState<PlatformKey | undefined>(
  16. undefined
  17. );
  18. const [clientState, _setClientState] = usePersistedOnboardingState();
  19. const disabledPlatforms = Object.keys(clientState?.platformToProjectIdMap ?? {}).reduce(
  20. (acc, key) => {
  21. if (!acc[key]) {
  22. acc[key] = t('Project already created');
  23. }
  24. return acc;
  25. },
  26. {}
  27. );
  28. useEffect(() => {
  29. if (!clientState) {
  30. return;
  31. }
  32. const selectedprojectCreated = disabledPlatforms[clientState.selectedPlatforms[0]];
  33. if (selectedPlatform === undefined && !selectedprojectCreated) {
  34. setSelectedPlatform(clientState.selectedPlatforms[0]);
  35. }
  36. }, [clientState, disabledPlatforms, selectedPlatform]);
  37. return (
  38. <Wrapper>
  39. <StepHeading step={props.stepIndex}>
  40. {t('Select the platform you want to monitor')}
  41. </StepHeading>
  42. <motion.div
  43. transition={testableTransition()}
  44. variants={{
  45. initial: {y: 30, opacity: 0},
  46. animate: {y: 0, opacity: 1},
  47. exit: {opacity: 0},
  48. }}
  49. >
  50. <p>
  51. {t(
  52. // TODO(Priscila): Shall we create a doc for this onboarding and link it here too?
  53. 'Set up a separate project for each part of your application (for example, your API server and frontend client), to quickly pinpoint which part of your application errors are coming from.'
  54. )}
  55. </p>
  56. <PlatformPicker
  57. noAutoFilter
  58. source="targeted-onboarding"
  59. platform={selectedPlatform}
  60. setPlatform={platformKey => {
  61. setSelectedPlatform(platformKey ?? undefined);
  62. }}
  63. disabledPlatforms={disabledPlatforms}
  64. organization={organization}
  65. />
  66. </motion.div>
  67. <CreateProjectsFooter
  68. {...props}
  69. organization={organization}
  70. clearPlatforms={() => setSelectedPlatform(undefined)}
  71. platforms={selectedPlatform ? [selectedPlatform] : []}
  72. />
  73. </Wrapper>
  74. );
  75. }
  76. const Wrapper = styled('div')`
  77. max-width: 850px;
  78. margin-left: auto;
  79. margin-right: auto;
  80. width: 100%;
  81. `;