UserProfileEditForm.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import React, { PureComponent, ChangeEvent, MouseEvent } from 'react';
  2. import { Button, FormLabel, Input, Tooltip } from '@grafana/ui';
  3. import { User } from 'app/types';
  4. import config from 'app/core/config';
  5. import { ProfileUpdateFields } from 'app/core/utils/UserProvider';
  6. export interface Props {
  7. user: User;
  8. isSavingUser: boolean;
  9. updateProfile: (payload: ProfileUpdateFields) => void;
  10. }
  11. export interface State {
  12. name: string;
  13. email: string;
  14. login: string;
  15. }
  16. export class UserProfileEditForm extends PureComponent<Props, State> {
  17. constructor(props: Props) {
  18. super(props);
  19. const {
  20. user: { name, email, login },
  21. } = this.props;
  22. this.state = {
  23. name,
  24. email,
  25. login,
  26. };
  27. }
  28. onNameChange = (event: ChangeEvent<HTMLInputElement>) => {
  29. this.setState({ name: event.target.value });
  30. };
  31. onEmailChange = (event: ChangeEvent<HTMLInputElement>) => {
  32. this.setState({ email: event.target.value });
  33. };
  34. onLoginChange = (event: ChangeEvent<HTMLInputElement>) => {
  35. this.setState({ login: event.target.value });
  36. };
  37. onSubmitProfileUpdate = (event: MouseEvent<HTMLInputElement>) => {
  38. event.preventDefault();
  39. this.props.updateProfile({ ...this.state });
  40. };
  41. render() {
  42. const { name, email, login } = this.state;
  43. const { isSavingUser } = this.props;
  44. const { disableLoginForm } = config;
  45. return (
  46. <>
  47. <h3 className="page-sub-heading">Edit Profile</h3>
  48. <form name="userForm" className="gf-form-group">
  49. <div className="gf-form max-width-30">
  50. <FormLabel className="width-8">Name</FormLabel>
  51. <Input className="gf-form-input max-width-22" type="text" onChange={this.onNameChange} value={name} />
  52. </div>
  53. <div className="gf-form max-width-30">
  54. <FormLabel className="width-8">Email</FormLabel>
  55. <Input
  56. className="gf-form-input max-width-22"
  57. type="text"
  58. onChange={this.onEmailChange}
  59. value={email}
  60. disabled={disableLoginForm}
  61. />
  62. {disableLoginForm && (
  63. <Tooltip content="Login Details Locked - managed in another system.">
  64. <i className="fa fa-lock gf-form-icon--right-absolute" />
  65. </Tooltip>
  66. )}
  67. </div>
  68. <div className="gf-form max-width-30">
  69. <FormLabel className="width-8">Username</FormLabel>
  70. <Input
  71. className="gf-form-input max-width-22"
  72. type="text"
  73. onChange={this.onLoginChange}
  74. value={login}
  75. disabled={disableLoginForm}
  76. />
  77. {disableLoginForm && (
  78. <Tooltip content="Login Details Locked - managed in another system.">
  79. <i className="fa fa-lock gf-form-icon--right-absolute" />
  80. </Tooltip>
  81. )}
  82. </div>
  83. <div className="gf-form-button-row">
  84. <Button variant="primary" onClick={this.onSubmitProfileUpdate} disabled={isSavingUser}>
  85. Save
  86. </Button>
  87. </div>
  88. </form>
  89. </>
  90. );
  91. }
  92. }
  93. export default UserProfileEditForm;