getStarted.tsx 6.3 KB

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