getStarted.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import {useContext, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {motion} from 'framer-motion';
  4. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  5. import {Button} from 'sentry/components/button';
  6. import SelectControl from 'sentry/components/forms/controls/selectControl';
  7. import Input from 'sentry/components/input';
  8. import {t} from 'sentry/locale';
  9. import ConfigStore from 'sentry/stores/configStore';
  10. import {space} from 'sentry/styles/space';
  11. import testableTransition from 'sentry/utils/testableTransition';
  12. import useApi from 'sentry/utils/useApi';
  13. import StepHeading from 'sentry/views/relocation/components/stepHeading';
  14. import {RelocationOnboardingContext} from 'sentry/views/relocation/relocationOnboardingContext';
  15. import {StepProps} from './types';
  16. const PROMO_CODE_ERROR_MSG = t(
  17. 'That promotional code has already been claimed, does not have enough remaining uses, is no longer valid, or never existed.'
  18. );
  19. function GetStarted(props: StepProps) {
  20. const api = useApi();
  21. const [regionUrl, setRegionUrl] = useState('');
  22. const [orgSlugs, setOrgSlugs] = useState('');
  23. const [promoCode, setPromoCode] = useState('');
  24. const [showPromoCode, setShowPromoCode] = useState(false);
  25. const relocationOnboardingContext = useContext(RelocationOnboardingContext);
  26. const selectableRegions = ConfigStore.get('relocationConfig')?.selectableRegions || [];
  27. const regions = ConfigStore.get('regions').filter(region =>
  28. selectableRegions.includes(region.name)
  29. );
  30. const handleContinue = async (event: any) => {
  31. event.preventDefault();
  32. if (promoCode) {
  33. try {
  34. await api.requestPromise(`/promocodes-external/${promoCode}`, {
  35. method: 'GET',
  36. });
  37. } catch (error) {
  38. if (error.status === 403) {
  39. addErrorMessage(PROMO_CODE_ERROR_MSG);
  40. return;
  41. }
  42. }
  43. }
  44. relocationOnboardingContext.setData({orgSlugs, regionUrl, promoCode});
  45. props.onComplete();
  46. };
  47. return (
  48. <Wrapper data-test-id="get-started">
  49. <StepHeading step={1}>{t('Basic information needed to get started')}</StepHeading>
  50. <motion.div
  51. transition={testableTransition()}
  52. variants={{
  53. initial: {y: 30, opacity: 0},
  54. animate: {y: 0, opacity: 1},
  55. exit: {opacity: 0},
  56. }}
  57. >
  58. <Form onSubmit={handleContinue}>
  59. <p>
  60. {t(
  61. 'In order to best facilitate the process some basic information will be required to ensure success with the relocation process of you self-hosted instance'
  62. )}
  63. </p>
  64. <RequiredLabel>{t('Organization slugs being relocated')}</RequiredLabel>
  65. <Input
  66. type="text"
  67. name="orgs"
  68. aria-label="org-slugs"
  69. onChange={evt => setOrgSlugs(evt.target.value)}
  70. required
  71. minLength={3}
  72. placeholder="org-slug-1, org-slug-2, ..."
  73. />
  74. <Label>{t('Choose a datacenter region')}</Label>
  75. <RegionSelect
  76. value={regionUrl}
  77. name="region"
  78. aria-label="region"
  79. placeholder="Select Region"
  80. options={regions.map(r => ({label: r.name, value: r.url}))}
  81. onChange={opt => setRegionUrl(opt.value)}
  82. />
  83. {regionUrl && (
  84. <p>{t('This is an important decision and cannot be changed.')}</p>
  85. )}
  86. {showPromoCode ? (
  87. <div>
  88. <Label>{t('Promo Code')}</Label>
  89. <PromoCodeInput
  90. type="text"
  91. name="promocode"
  92. aria-label="promocode"
  93. onChange={evt => setPromoCode(evt.target.value)}
  94. placeholder=""
  95. />
  96. </div>
  97. ) : (
  98. <TogglePromoCode onClick={() => setShowPromoCode(true)}>
  99. Got a promo code? <u>Redeem</u>
  100. </TogglePromoCode>
  101. )}
  102. <ContinueButton
  103. disabled={!orgSlugs || !regionUrl}
  104. priority="primary"
  105. type="submit"
  106. >
  107. {t('Continue')}
  108. </ContinueButton>
  109. </Form>
  110. </motion.div>
  111. </Wrapper>
  112. );
  113. }
  114. export default GetStarted;
  115. const AnimatedContentWrapper = styled(motion.div)`
  116. overflow: hidden;
  117. `;
  118. AnimatedContentWrapper.defaultProps = {
  119. initial: {
  120. height: 0,
  121. },
  122. animate: {
  123. height: 'auto',
  124. },
  125. exit: {
  126. height: 0,
  127. },
  128. };
  129. const DocsWrapper = styled(motion.div)``;
  130. DocsWrapper.defaultProps = {
  131. initial: {opacity: 0, y: 40},
  132. animate: {opacity: 1, y: 0},
  133. exit: {opacity: 0},
  134. };
  135. const Wrapper = styled('div')`
  136. margin-left: auto;
  137. margin-right: auto;
  138. padding: ${space(4)};
  139. background-color: ${p => p.theme.surface400};
  140. z-index: 100;
  141. box-shadow: 0 5px 10px rgba(0, 0, 0, 0.05);
  142. border-radius: 10px;
  143. max-width: 769px;
  144. max-height: 525px;
  145. color: ${p => p.theme.gray300};
  146. h2 {
  147. color: ${p => p.theme.gray500};
  148. }
  149. `;
  150. const ContinueButton = styled(Button)`
  151. margin-top: ${space(4)};
  152. `;
  153. const Form = styled('form')`
  154. position: relative;
  155. `;
  156. const Label = styled('label')`
  157. display: block;
  158. text-transform: uppercase;
  159. color: ${p => p.theme.gray500};
  160. margin-top: ${space(2)};
  161. `;
  162. const RequiredLabel = styled('label')`
  163. display: block;
  164. text-transform: uppercase;
  165. color: ${p => p.theme.gray500};
  166. margin-top: ${space(2)};
  167. &:after {
  168. content: '•';
  169. width: 6px;
  170. color: ${p => p.theme.red300};
  171. }
  172. `;
  173. const RegionSelect = styled(SelectControl)`
  174. button {
  175. width: 709px;
  176. }
  177. `;
  178. const PromoCodeInput = styled(Input)`
  179. padding-bottom: ${space(2)};
  180. `;
  181. const TogglePromoCode = styled('a')`
  182. display: block;
  183. padding-top: ${space(2)};
  184. cursor: pointer;
  185. `;