registerForm.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import {useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Alert} from 'sentry/components/alert';
  4. import RadioBooleanField from 'sentry/components/forms/fields/radioField';
  5. import SecretField from 'sentry/components/forms/fields/secretField';
  6. import TextField from 'sentry/components/forms/fields/textField';
  7. import Form from 'sentry/components/forms/form';
  8. import ExternalLink from 'sentry/components/links/externalLink';
  9. import {t, tct} from 'sentry/locale';
  10. import ConfigStore from 'sentry/stores/configStore';
  11. import type {AuthConfig} from 'sentry/types';
  12. import {browserHistory} from 'sentry/utils/browserHistory';
  13. type Props = {
  14. authConfig: AuthConfig;
  15. };
  16. function RegisterForm({authConfig}: Props) {
  17. const {hasNewsletter} = authConfig;
  18. const [error, setError] = useState('');
  19. return (
  20. <Form
  21. apiMethod="POST"
  22. apiEndpoint="/auth/register/"
  23. initialData={{subscribe: true}}
  24. submitLabel={t('Continue')}
  25. onSubmitSuccess={response => {
  26. ConfigStore.set('user', response.user);
  27. browserHistory.push({pathname: response.nextUri});
  28. }}
  29. onSubmitError={response => {
  30. setError(response.responseJSON.detail);
  31. }}
  32. extraButton={
  33. <PrivacyPolicyLink href="https://sentry.io/privacy/">
  34. {t('Privacy Policy')}
  35. </PrivacyPolicyLink>
  36. }
  37. >
  38. {error && <Alert type="error">{error}</Alert>}
  39. <TextField
  40. name="name"
  41. placeholder={t('Jane Bloggs')}
  42. label={t('Name')}
  43. stacked
  44. inline={false}
  45. required
  46. />
  47. <TextField
  48. name="username"
  49. placeholder={t('you@example.com')}
  50. label={t('Email')}
  51. stacked
  52. inline={false}
  53. required
  54. />
  55. <SecretField
  56. name="password"
  57. placeholder={t('something super secret')}
  58. label={t('Password')}
  59. stacked
  60. inline={false}
  61. required
  62. />
  63. {hasNewsletter && (
  64. <RadioBooleanField
  65. name="subscribe"
  66. choices={[
  67. ['true', t('Yes, I would like to receive updates via email')],
  68. ['flase', t("No, I'd prefer not to receive these updates")],
  69. ]}
  70. help={tct(
  71. `We'd love to keep you updated via email with product and feature
  72. announcements, promotions, educational materials, and events. Our
  73. updates focus on relevant information, and we'll never sell your data
  74. to third parties. See our [link] for more details.`,
  75. {
  76. link: <a href="https://sentry.io/privacy/">Privacy Policy</a>,
  77. }
  78. )}
  79. stacked
  80. inline={false}
  81. />
  82. )}
  83. </Form>
  84. );
  85. }
  86. const PrivacyPolicyLink = styled(ExternalLink)`
  87. color: ${p => p.theme.gray300};
  88. &:hover {
  89. color: ${p => p.theme.textColor};
  90. }
  91. `;
  92. export default RegisterForm;