getStarted.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 SelectControl from 'sentry/components/forms/controls/selectControl';
  6. import Input from 'sentry/components/input';
  7. import {t} from 'sentry/locale';
  8. import ConfigStore from 'sentry/stores/configStore';
  9. import {space} from 'sentry/styles/space';
  10. import testableTransition from 'sentry/utils/testableTransition';
  11. import useApi from 'sentry/utils/useApi';
  12. import ContinueButton from 'sentry/views/relocation/components/continueButton';
  13. import StepHeading from 'sentry/views/relocation/components/stepHeading';
  14. import {RelocationOnboardingContext} from 'sentry/views/relocation/relocationOnboardingContext';
  15. import type {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 location')}</Label>
  75. <RegionSelect
  76. value={regionUrl}
  77. name="region"
  78. aria-label="region"
  79. placeholder="Select Location"
  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. <DatacenterTextBlock>
  87. {t(
  88. "Choose where to store your organization's data. Please note, you won't be able to change locations once your relocation has been initiated. "
  89. )}
  90. <a
  91. href="https://docs.sentry.io/product/accounts/choose-your-data-center"
  92. target="_blank"
  93. rel="noreferrer"
  94. >
  95. Learn more
  96. </a>
  97. .
  98. </DatacenterTextBlock>
  99. {showPromoCode ? (
  100. <div>
  101. <Label>{t('Promo Code')}</Label>
  102. <PromoCodeInput
  103. type="text"
  104. name="promocode"
  105. aria-label="promocode"
  106. onChange={evt => setPromoCode(evt.target.value)}
  107. placeholder=""
  108. />
  109. </div>
  110. ) : (
  111. <TogglePromoCode onClick={() => setShowPromoCode(true)}>
  112. Got a promo code? <u>Redeem</u>
  113. </TogglePromoCode>
  114. )}
  115. <ContinueButton
  116. disabled={!orgSlugs || !regionUrl}
  117. priority="primary"
  118. type="submit"
  119. />
  120. </Form>
  121. </motion.div>
  122. </Wrapper>
  123. );
  124. }
  125. export default GetStarted;
  126. const AnimatedContentWrapper = styled(motion.div)`
  127. overflow: hidden;
  128. `;
  129. AnimatedContentWrapper.defaultProps = {
  130. initial: {
  131. height: 0,
  132. },
  133. animate: {
  134. height: 'auto',
  135. },
  136. exit: {
  137. height: 0,
  138. },
  139. };
  140. const DocsWrapper = styled(motion.div)``;
  141. DocsWrapper.defaultProps = {
  142. initial: {opacity: 0, y: 40},
  143. animate: {opacity: 1, y: 0},
  144. exit: {opacity: 0},
  145. };
  146. const Wrapper = styled('div')`
  147. margin-left: auto;
  148. margin-right: auto;
  149. padding: ${space(4)};
  150. background-color: ${p => p.theme.surface400};
  151. z-index: 100;
  152. box-shadow: 0 5px 10px rgba(0, 0, 0, 0.05);
  153. border-radius: 10px;
  154. max-width: 769px;
  155. max-height: 525px;
  156. color: ${p => p.theme.gray300};
  157. h2 {
  158. color: ${p => p.theme.gray500};
  159. }
  160. `;
  161. const Form = styled('form')`
  162. position: relative;
  163. `;
  164. const Label = styled('label')`
  165. display: block;
  166. text-transform: uppercase;
  167. color: ${p => p.theme.gray500};
  168. margin-top: ${space(2)};
  169. `;
  170. const RequiredLabel = styled('label')`
  171. display: block;
  172. text-transform: uppercase;
  173. color: ${p => p.theme.gray500};
  174. margin-top: ${space(2)};
  175. &:after {
  176. content: '•';
  177. width: 6px;
  178. color: ${p => p.theme.red300};
  179. }
  180. `;
  181. const RegionSelect = styled(SelectControl)`
  182. button {
  183. width: 709px;
  184. }
  185. `;
  186. const PromoCodeInput = styled(Input)`
  187. padding-bottom: ${space(2)};
  188. `;
  189. const TogglePromoCode = styled('a')`
  190. display: block;
  191. cursor: pointer;
  192. padding-bottom: ${space(2)};
  193. `;
  194. const DatacenterTextBlock = styled('p')`
  195. margin-top: ${space(1)};
  196. `;