ssoForm.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {useState} from 'react';
  2. import {Alert} from 'sentry/components/alert';
  3. import TextField from 'sentry/components/forms/fields/textField';
  4. import Form from 'sentry/components/forms/form';
  5. import {t, tct} from 'sentry/locale';
  6. import type {AuthConfig} from 'sentry/types';
  7. import {browserHistory} from 'sentry/utils/browserHistory';
  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. function SlugExample({hostname, slug}: SlugExampleProps) {
  54. return (
  55. <code>
  56. {hostname}/<strong>{slug}</strong>
  57. </code>
  58. );
  59. }
  60. export default SsoForm;