CreateTeam.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'react-redux';
  3. import { NavModel } from '@grafana/data';
  4. import { getBackendSrv, locationService } from '@grafana/runtime';
  5. import { Button, Form, Field, Input, FieldSet } from '@grafana/ui';
  6. import Page from 'app/core/components/Page/Page';
  7. import { contextSrv } from 'app/core/core';
  8. import { getNavModel } from 'app/core/selectors/navModel';
  9. import { StoreState } from 'app/types';
  10. export interface Props {
  11. navModel: NavModel;
  12. }
  13. interface TeamDTO {
  14. name: string;
  15. email: string;
  16. }
  17. export class CreateTeam extends PureComponent<Props> {
  18. create = async (formModel: TeamDTO) => {
  19. const result = await getBackendSrv().post('/api/teams', formModel);
  20. if (result.teamId) {
  21. await contextSrv.fetchUserPermissions();
  22. locationService.push(`/org/teams/edit/${result.teamId}`);
  23. }
  24. };
  25. render() {
  26. const { navModel } = this.props;
  27. return (
  28. <Page navModel={navModel}>
  29. <Page.Contents>
  30. <Form onSubmit={this.create}>
  31. {({ register, errors }) => (
  32. <FieldSet label="New Team">
  33. <Field label="Name" required invalid={!!errors.name} error="Team name is required">
  34. <Input {...register('name', { required: true })} id="team-name" width={60} />
  35. </Field>
  36. <Field
  37. label={'Email'}
  38. description={'This is optional and is primarily used for allowing custom team avatars.'}
  39. >
  40. <Input {...register('email')} type="email" id="team-email" placeholder="email@test.com" width={60} />
  41. </Field>
  42. <div className="gf-form-button-row">
  43. <Button type="submit" variant="primary">
  44. Create
  45. </Button>
  46. </div>
  47. </FieldSet>
  48. )}
  49. </Form>
  50. </Page.Contents>
  51. </Page>
  52. );
  53. }
  54. }
  55. function mapStateToProps(state: StoreState) {
  56. return {
  57. navModel: getNavModel(state.navIndex, 'teams'),
  58. };
  59. }
  60. export default connect(mapStateToProps)(CreateTeam);