getStarted.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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({regionUrl, onChangeRegionUrl, onComplete}: StepProps) {
  20. const api = useApi();
  21. const relocationOnboardingContext = useContext(RelocationOnboardingContext);
  22. const {orgSlugs, promoCode} = relocationOnboardingContext.data;
  23. const [showPromoCode, setShowPromoCode] = useState(
  24. !!relocationOnboardingContext.data.promoCode
  25. );
  26. const selectableRegions = ConfigStore.get('relocationConfig')?.selectableRegions || [];
  27. const regions = ConfigStore.get('regions').filter(region =>
  28. selectableRegions.includes(region.name)
  29. );
  30. onChangeRegionUrl(relocationOnboardingContext.data.regionUrl);
  31. const handleContinue = async (event: any) => {
  32. event.preventDefault();
  33. if (promoCode) {
  34. try {
  35. await api.requestPromise(`/promocodes-external/${promoCode}`, {
  36. method: 'GET',
  37. });
  38. } catch (error) {
  39. if (error.status === 403) {
  40. addErrorMessage(PROMO_CODE_ERROR_MSG);
  41. return;
  42. }
  43. }
  44. }
  45. relocationOnboardingContext.setData({orgSlugs, regionUrl, promoCode});
  46. onComplete();
  47. };
  48. return (
  49. <Wrapper data-test-id="get-started">
  50. <StepHeading step={1}>{t('Basic information needed to get started')}</StepHeading>
  51. <motion.div
  52. transition={testableTransition()}
  53. variants={{
  54. initial: {y: 30, opacity: 0},
  55. animate: {y: 0, opacity: 1},
  56. exit: {opacity: 0},
  57. }}
  58. >
  59. <Form onSubmit={handleContinue}>
  60. <p>
  61. {t(
  62. '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'
  63. )}
  64. </p>
  65. <RequiredLabel>{t('Organization slugs being relocated')}</RequiredLabel>
  66. <Input
  67. type="text"
  68. name="orgs"
  69. aria-label="org-slugs"
  70. onChange={evt => {
  71. relocationOnboardingContext.setData({
  72. orgSlugs: evt.target.value,
  73. regionUrl,
  74. promoCode,
  75. });
  76. }}
  77. required
  78. minLength={3}
  79. placeholder="org-slug-1, org-slug-2, ..."
  80. value={orgSlugs}
  81. />
  82. <Label>{t('Choose a datacenter location')}</Label>
  83. <RegionSelect
  84. value={regionUrl}
  85. name="region"
  86. aria-label="region"
  87. placeholder="Select Location"
  88. options={regions.map(r => ({label: r.name, value: r.url}))}
  89. onChange={opt => onChangeRegionUrl(opt.value)}
  90. />
  91. {regionUrl && (
  92. <p>{t('This is an important decision and cannot be changed.')}</p>
  93. )}
  94. <DatacenterTextBlock>
  95. {t(
  96. "Choose where to store your organization's data. Please note, you won't be able to change locations once your relocation has been initiated. "
  97. )}
  98. <a
  99. href="https://docs.sentry.io/product/accounts/choose-your-data-center"
  100. target="_blank"
  101. rel="noreferrer"
  102. >
  103. Learn more
  104. </a>
  105. .
  106. </DatacenterTextBlock>
  107. {showPromoCode ? (
  108. <div>
  109. <Label>{t('Promo Code')}</Label>
  110. <PromoCodeInput
  111. type="text"
  112. name="promocode"
  113. aria-label="promocode"
  114. onChange={evt => {
  115. relocationOnboardingContext.setData({
  116. orgSlugs,
  117. regionUrl,
  118. promoCode: evt.target.value,
  119. });
  120. }}
  121. placeholder=""
  122. value={promoCode}
  123. />
  124. </div>
  125. ) : (
  126. <TogglePromoCode onClick={() => setShowPromoCode(true)}>
  127. Got a promo code? <u>Redeem</u>
  128. </TogglePromoCode>
  129. )}
  130. <ContinueButton
  131. disabled={!orgSlugs || !regionUrl}
  132. priority="primary"
  133. type="submit"
  134. />
  135. </Form>
  136. </motion.div>
  137. </Wrapper>
  138. );
  139. }
  140. export default GetStarted;
  141. const AnimatedContentWrapper = styled(motion.div)`
  142. overflow: hidden;
  143. `;
  144. AnimatedContentWrapper.defaultProps = {
  145. initial: {
  146. height: 0,
  147. },
  148. animate: {
  149. height: 'auto',
  150. },
  151. exit: {
  152. height: 0,
  153. },
  154. };
  155. const DocsWrapper = styled(motion.div)``;
  156. DocsWrapper.defaultProps = {
  157. initial: {opacity: 0, y: 40},
  158. animate: {opacity: 1, y: 0},
  159. exit: {opacity: 0},
  160. };
  161. const Wrapper = styled('div')`
  162. margin-left: auto;
  163. margin-right: auto;
  164. padding: ${space(4)};
  165. background-color: ${p => p.theme.surface400};
  166. z-index: 100;
  167. box-shadow: 0 5px 10px rgba(0, 0, 0, 0.05);
  168. border-radius: 10px;
  169. max-width: 769px;
  170. max-height: 525px;
  171. color: ${p => p.theme.gray300};
  172. h2 {
  173. color: ${p => p.theme.gray500};
  174. }
  175. `;
  176. const Form = styled('form')`
  177. position: relative;
  178. `;
  179. const Label = styled('label')`
  180. display: block;
  181. text-transform: uppercase;
  182. color: ${p => p.theme.gray500};
  183. margin-top: ${space(2)};
  184. `;
  185. const RequiredLabel = styled('label')`
  186. display: block;
  187. text-transform: uppercase;
  188. color: ${p => p.theme.gray500};
  189. margin-top: ${space(2)};
  190. &:after {
  191. content: '•';
  192. width: 6px;
  193. color: ${p => p.theme.red300};
  194. }
  195. `;
  196. const RegionSelect = styled(SelectControl)`
  197. button {
  198. width: 709px;
  199. }
  200. `;
  201. const PromoCodeInput = styled(Input)`
  202. padding-bottom: ${space(2)};
  203. `;
  204. const TogglePromoCode = styled('a')`
  205. display: block;
  206. cursor: pointer;
  207. padding-bottom: ${space(2)};
  208. `;
  209. const DatacenterTextBlock = styled('p')`
  210. margin-top: ${space(1)};
  211. `;