getStarted.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. function GetStarted({relocationState, onUpdateRelocationState, onComplete}: StepProps) {
  19. const api = useApi();
  20. const {orgSlugs, regionUrl, promoCode} = relocationState;
  21. const [showPromoCode, setShowPromoCode] = useState(!!promoCode);
  22. const selectableRegions = ConfigStore.get('relocationConfig')?.selectableRegions || [];
  23. const regions = ConfigStore.get('regions').filter(region =>
  24. selectableRegions.includes(region.name)
  25. );
  26. const handleContinue = async (event: any) => {
  27. event.preventDefault();
  28. if (promoCode) {
  29. try {
  30. await api.requestPromise(`/promocodes-external/${promoCode}`, {
  31. method: 'GET',
  32. });
  33. } catch (error) {
  34. if (error.status === 403) {
  35. addErrorMessage(PROMO_CODE_ERROR_MSG);
  36. return;
  37. }
  38. }
  39. }
  40. onComplete();
  41. };
  42. return (
  43. <Wrapper data-test-id="get-started">
  44. <StepHeading step={1}>{t('Basic information needed to get started')}</StepHeading>
  45. <motion.div
  46. transition={testableTransition()}
  47. variants={{
  48. initial: {y: 30, opacity: 0},
  49. animate: {y: 0, opacity: 1},
  50. exit: {opacity: 0},
  51. }}
  52. >
  53. <Form onSubmit={handleContinue}>
  54. <p>
  55. {t(
  56. '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'
  57. )}
  58. </p>
  59. <RequiredLabel>{t('Organization slugs being relocated')}</RequiredLabel>
  60. <Input
  61. type="text"
  62. name="orgs"
  63. aria-label="org-slugs"
  64. onChange={evt => {
  65. onUpdateRelocationState({orgSlugs: evt.target.value});
  66. }}
  67. required
  68. minLength={3}
  69. placeholder="org-slug-1, org-slug-2, ..."
  70. value={orgSlugs}
  71. />
  72. <Label>{t('Choose a datacenter location')}</Label>
  73. <RegionSelect
  74. value={regionUrl}
  75. name="region"
  76. aria-label="region"
  77. placeholder="Select Location"
  78. options={regions.map(r => ({label: r.name, value: r.url}))}
  79. onChange={opt => {
  80. onUpdateRelocationState({regionUrl: opt.value});
  81. }}
  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 => {
  107. onUpdateRelocationState({promoCode: evt.target.value});
  108. }}
  109. placeholder=""
  110. value={promoCode}
  111. />
  112. </div>
  113. ) : (
  114. <TogglePromoCode onClick={() => setShowPromoCode(true)}>
  115. Got a promo code? <u>Redeem</u>
  116. </TogglePromoCode>
  117. )}
  118. <ContinueButton
  119. disabled={!orgSlugs || !regionUrl}
  120. priority="primary"
  121. type="submit"
  122. />
  123. </Form>
  124. </motion.div>
  125. </Wrapper>
  126. );
  127. }
  128. export default GetStarted;
  129. const AnimatedContentWrapper = styled(motion.div)`
  130. overflow: hidden;
  131. `;
  132. AnimatedContentWrapper.defaultProps = {
  133. initial: {
  134. height: 0,
  135. },
  136. animate: {
  137. height: 'auto',
  138. },
  139. exit: {
  140. height: 0,
  141. },
  142. };
  143. const DocsWrapper = styled(motion.div)``;
  144. DocsWrapper.defaultProps = {
  145. initial: {opacity: 0, y: 40},
  146. animate: {opacity: 1, y: 0},
  147. exit: {opacity: 0},
  148. };
  149. const Wrapper = styled('div')`
  150. margin-left: auto;
  151. margin-right: auto;
  152. padding: ${space(4)};
  153. background-color: ${p => p.theme.surface400};
  154. z-index: 100;
  155. box-shadow: 0 5px 10px rgba(0, 0, 0, 0.05);
  156. border-radius: 10px;
  157. max-width: 769px;
  158. max-height: 525px;
  159. color: ${p => p.theme.gray300};
  160. h2 {
  161. color: ${p => p.theme.gray500};
  162. }
  163. `;
  164. const Form = styled('form')`
  165. position: relative;
  166. `;
  167. const Label = styled('label')`
  168. display: block;
  169. text-transform: uppercase;
  170. color: ${p => p.theme.gray500};
  171. margin-top: ${space(2)};
  172. `;
  173. const RequiredLabel = styled('label')`
  174. display: block;
  175. text-transform: uppercase;
  176. color: ${p => p.theme.gray500};
  177. margin-top: ${space(2)};
  178. &:after {
  179. content: '•';
  180. width: 6px;
  181. color: ${p => p.theme.red300};
  182. }
  183. `;
  184. const RegionSelect = styled(SelectControl)`
  185. button {
  186. width: 709px;
  187. }
  188. `;
  189. const PromoCodeInput = styled(Input)`
  190. padding-bottom: ${space(2)};
  191. `;
  192. const TogglePromoCode = styled('a')`
  193. display: block;
  194. cursor: pointer;
  195. padding-bottom: ${space(2)};
  196. `;
  197. const DatacenterTextBlock = styled('p')`
  198. margin-top: ${space(1)};
  199. `;