TeamSettings.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { FormLabel } from '@grafana/ui';
  4. import { SharedPreferences } from 'app/core/components/SharedPreferences/SharedPreferences';
  5. import { updateTeam } from './state/actions';
  6. import { getRouteParamsId } from 'app/core/selectors/location';
  7. import { getTeam } from './state/selectors';
  8. import { Team } from 'app/types';
  9. export interface Props {
  10. team: Team;
  11. updateTeam: typeof updateTeam;
  12. }
  13. interface State {
  14. name: string;
  15. email: string;
  16. }
  17. export class TeamSettings extends React.Component<Props, State> {
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. name: props.team.name,
  22. email: props.team.email,
  23. };
  24. }
  25. onChangeName = event => {
  26. this.setState({ name: event.target.value });
  27. };
  28. onChangeEmail = event => {
  29. this.setState({ email: event.target.value });
  30. };
  31. onUpdate = event => {
  32. const { name, email } = this.state;
  33. event.preventDefault();
  34. this.props.updateTeam(name, email);
  35. };
  36. render() {
  37. const { team } = this.props;
  38. const { name, email } = this.state;
  39. return (
  40. <div>
  41. <h3 className="page-sub-heading">Team Settings</h3>
  42. <form name="teamDetailsForm" className="gf-form-group" onSubmit={this.onUpdate}>
  43. <div className="gf-form max-width-30">
  44. <FormLabel>Name</FormLabel>
  45. <input
  46. type="text"
  47. required
  48. value={name}
  49. className="gf-form-input max-width-22"
  50. onChange={this.onChangeName}
  51. />
  52. </div>
  53. <div className="gf-form max-width-30">
  54. <FormLabel tooltip="This is optional and is primarily used to set the team profile avatar (via gravatar service)">
  55. Email
  56. </FormLabel>
  57. <input
  58. type="email"
  59. className="gf-form-input max-width-22"
  60. value={email}
  61. placeholder="team@email.com"
  62. onChange={this.onChangeEmail}
  63. />
  64. </div>
  65. <div className="gf-form-button-row">
  66. <button type="submit" className="btn btn-primary">
  67. Update
  68. </button>
  69. </div>
  70. </form>
  71. <SharedPreferences resourceUri={`teams/${team.id}`} />
  72. </div>
  73. );
  74. }
  75. }
  76. function mapStateToProps(state) {
  77. const teamId = getRouteParamsId(state.location);
  78. return {
  79. team: getTeam(state.team, teamId),
  80. };
  81. }
  82. const mapDispatchToProps = {
  83. updateTeam,
  84. };
  85. export default connect(mapStateToProps, mapDispatchToProps)(TeamSettings);