getStarted.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 Wrapper = styled('div')`
  140. margin-left: auto;
  141. margin-right: auto;
  142. padding: ${space(4)};
  143. background-color: ${p => p.theme.surface400};
  144. z-index: 100;
  145. box-shadow: 0 5px 10px rgba(0, 0, 0, 0.05);
  146. border-radius: 10px;
  147. max-width: 769px;
  148. max-height: 525px;
  149. color: ${p => p.theme.gray300};
  150. h2 {
  151. color: ${p => p.theme.gray500};
  152. }
  153. `;
  154. const Form = styled('form')`
  155. position: relative;
  156. `;
  157. const Label = styled('label')`
  158. display: block;
  159. text-transform: uppercase;
  160. color: ${p => p.theme.gray500};
  161. margin-top: ${space(2)};
  162. `;
  163. const RequiredLabel = styled('label')`
  164. display: block;
  165. text-transform: uppercase;
  166. color: ${p => p.theme.gray500};
  167. margin-top: ${space(2)};
  168. &:after {
  169. content: '•';
  170. width: 6px;
  171. color: ${p => p.theme.red300};
  172. }
  173. `;
  174. const RegionSelect = styled(SelectControl)`
  175. button {
  176. width: 709px;
  177. }
  178. `;
  179. const PromoCodeInput = styled(Input)`
  180. padding-bottom: ${space(2)};
  181. `;
  182. const TogglePromoCode = styled('a')`
  183. display: block;
  184. cursor: pointer;
  185. padding-bottom: ${space(2)};
  186. `;
  187. const DatacenterTextBlock = styled('p')`
  188. margin-top: ${space(1)};
  189. `;