index.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import {Component} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  5. import EmailField from 'sentry/components/forms/fields/emailField';
  6. import Form from 'sentry/components/forms/form';
  7. import NarrowLayout from 'sentry/components/narrowLayout';
  8. import {IconMegaphone} from 'sentry/icons';
  9. import {t, tct} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. type Props = RouteComponentProps<{orgId: string}, {}>;
  12. type State = {
  13. submitSuccess: boolean | null;
  14. };
  15. class OrganizationJoinRequest extends Component<Props, State> {
  16. state: State = {
  17. submitSuccess: null,
  18. };
  19. handleSubmitSuccess = () => {
  20. this.setState({submitSuccess: true});
  21. };
  22. handleSubmitError() {
  23. addErrorMessage(t('Request to join failed'));
  24. }
  25. handleCancel = e => {
  26. e.preventDefault();
  27. const {params} = this.props;
  28. window.location.assign(`/auth/login/${params.orgId}/`);
  29. };
  30. render() {
  31. const {params} = this.props;
  32. const {submitSuccess} = this.state;
  33. if (submitSuccess) {
  34. return (
  35. <NarrowLayout maxWidth="550px">
  36. <SuccessModal>
  37. <StyledIconMegaphone size="xxl" />
  38. <StyledHeader>{t('Request Sent')}</StyledHeader>
  39. <StyledText>{t('Your request to join has been sent.')}</StyledText>
  40. <ReceiveEmailMessage>
  41. {t('You will receive an email when your request is approved.')}
  42. </ReceiveEmailMessage>
  43. </SuccessModal>
  44. </NarrowLayout>
  45. );
  46. }
  47. return (
  48. <NarrowLayout maxWidth="650px">
  49. <StyledIconMegaphone size="xxl" />
  50. <StyledHeader data-test-id="join-request">{t('Request to Join')}</StyledHeader>
  51. <StyledText>
  52. {tct('Ask the admins if you can join the [orgId] organization.', {
  53. orgId: params.orgId,
  54. })}
  55. </StyledText>
  56. <Form
  57. requireChanges
  58. apiEndpoint={`/organizations/${params.orgId}/join-request/`}
  59. apiMethod="POST"
  60. submitLabel={t('Request to Join')}
  61. onSubmitSuccess={this.handleSubmitSuccess}
  62. onSubmitError={this.handleSubmitError}
  63. onCancel={this.handleCancel}
  64. >
  65. <StyledEmailField
  66. name="email"
  67. inline={false}
  68. label={t('Email Address')}
  69. placeholder="name@example.com"
  70. />
  71. </Form>
  72. </NarrowLayout>
  73. );
  74. }
  75. }
  76. const SuccessModal = styled('div')`
  77. display: grid;
  78. justify-items: center;
  79. text-align: center;
  80. padding-top: 10px;
  81. padding-bottom: ${space(4)};
  82. `;
  83. const StyledIconMegaphone = styled(IconMegaphone)`
  84. padding-bottom: ${space(3)};
  85. `;
  86. const StyledHeader = styled('h3')`
  87. margin-bottom: ${space(1)};
  88. `;
  89. const StyledText = styled('p')`
  90. margin-bottom: 0;
  91. `;
  92. const ReceiveEmailMessage = styled(StyledText)`
  93. max-width: 250px;
  94. `;
  95. const StyledEmailField = styled(EmailField)`
  96. padding-top: ${space(2)};
  97. padding-left: 0;
  98. `;
  99. export default OrganizationJoinRequest;