createTeamForm.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {Component, Fragment} from 'react';
  2. import {t} from 'app/locale';
  3. import {Organization} from 'app/types';
  4. import {callIfFunction} from 'app/utils/callIfFunction';
  5. import slugify from 'app/utils/slugify';
  6. import Form from 'app/views/settings/components/forms/form';
  7. import TextField from 'app/views/settings/components/forms/textField';
  8. type Payload = {
  9. slug: string;
  10. };
  11. type Props = {
  12. organization: Organization;
  13. onSubmit?: (data: Payload, onSuccess: Function, onError: Function) => void;
  14. onSuccess?: (data: Payload) => void;
  15. formProps?: Partial<typeof Form>;
  16. };
  17. export default class CreateTeamForm extends Component<Props> {
  18. handleSubmit = (data: Record<string, any>, onSuccess: Function, onError: Function) => {
  19. callIfFunction(this.props.onSubmit, data as Payload, onSuccess, onError);
  20. };
  21. handleCreateTeamSuccess = (data: Payload) => {
  22. callIfFunction(this.props.onSuccess, data);
  23. };
  24. render() {
  25. const {organization} = this.props;
  26. return (
  27. <Fragment>
  28. <p>
  29. {t(
  30. 'Members of a team have access to specific areas, such as a new release or a new application feature.'
  31. )}
  32. </p>
  33. <Form
  34. submitLabel={t('Create Team')}
  35. apiEndpoint={`/organizations/${organization.slug}/teams/`}
  36. apiMethod="POST"
  37. onSubmit={this.handleSubmit}
  38. onSubmitSuccess={this.handleCreateTeamSuccess}
  39. requireChanges
  40. data-test-id="create-team-form"
  41. {...this.props.formProps}
  42. >
  43. <TextField
  44. name="slug"
  45. label={t('Team Name')}
  46. placeholder={t('e.g. operations, web-frontend, desktop')}
  47. help={t('May contain lowercase letters, numbers, dashes and underscores.')}
  48. required
  49. stacked
  50. flexibleControlStateSize
  51. inline={false}
  52. transformInput={slugify}
  53. />
  54. </Form>
  55. </Fragment>
  56. );
  57. }
  58. }