ssoForm.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {useState} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import Alert from 'sentry/components/alert';
  4. import TextField from 'sentry/components/forms/fields/textField';
  5. import Form from 'sentry/components/forms/form';
  6. import {t, tct} from 'sentry/locale';
  7. import {AuthConfig} from 'sentry/types';
  8. type Props = {
  9. authConfig: AuthConfig;
  10. };
  11. function SsoForm({authConfig}: Props) {
  12. const [error, setError] = useState('');
  13. const {serverHostname} = authConfig;
  14. return (
  15. <Form
  16. apiMethod="POST"
  17. apiEndpoint="/auth/sso-locate/"
  18. onSubmitSuccess={response => {
  19. browserHistory.push({pathname: response.nextUri});
  20. }}
  21. onSubmitError={response => {
  22. setError(response.responseJSON.detail);
  23. }}
  24. submitLabel={t('Continue')}
  25. footerStyle={{
  26. borderTop: 'none',
  27. alignItems: 'center',
  28. marginBottom: 0,
  29. padding: 0,
  30. }}
  31. >
  32. {error && <Alert type="error">{error}</Alert>}
  33. <TextField
  34. name="organization"
  35. placeholder="acme"
  36. label={t('Organization ID')}
  37. required
  38. stacked
  39. inline={false}
  40. hideControlState
  41. help={tct('Your ID is the slug after the hostname. e.g. [example] is [slug].', {
  42. slug: <strong>acme</strong>,
  43. example: <SlugExample slug="acme" hostname={serverHostname} />,
  44. })}
  45. />
  46. </Form>
  47. );
  48. }
  49. type SlugExampleProps = {
  50. hostname: string;
  51. slug: string;
  52. };
  53. const SlugExample = ({hostname, slug}: SlugExampleProps) => (
  54. <code>
  55. {hostname}/<strong>{slug}</strong>
  56. </code>
  57. );
  58. export default SsoForm;