TeamSettings.tsx 2.4 KB

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