mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* ChangePassword to React, created PasswordInput component, attempting UserProvider wrapper component, adding flex to btn row * UserAPI interface, force classes on PasswordInput, remove api call from ChangePassword * refactored out form * clean up * removed unnecessary bind, added loading state and loading component to change password form * should be OR * arrow funcs instead of binds, inline-block instead of flex, isSaving instead of isLoading, disabled button instead of spinner * inline-flex on the react btn * change state instatiatiation
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import React, { PureComponent, MouseEvent } from 'react';
|
|
import config from 'app/core/config';
|
|
import { Button, LinkButton } from '@grafana/ui';
|
|
import { ChangePasswordFields } from 'app/core/utils/UserProvider';
|
|
import { PasswordInput } from 'app/core/components/PasswordInput/PasswordInput';
|
|
|
|
export interface Props {
|
|
isSaving: boolean;
|
|
onChangePassword: (payload: ChangePasswordFields) => void;
|
|
}
|
|
|
|
export interface State {
|
|
oldPassword: string;
|
|
newPassword: string;
|
|
confirmNew: string;
|
|
}
|
|
|
|
export class ChangePasswordForm extends PureComponent<Props, State> {
|
|
constructor(props: Props) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
oldPassword: '',
|
|
newPassword: '',
|
|
confirmNew: '',
|
|
};
|
|
}
|
|
|
|
onOldPasswordChange = (oldPassword: string) => {
|
|
this.setState({ oldPassword });
|
|
};
|
|
|
|
onNewPasswordChange = (newPassword: string) => {
|
|
this.setState({ newPassword });
|
|
};
|
|
|
|
onConfirmPasswordChange = (confirmNew: string) => {
|
|
this.setState({ confirmNew });
|
|
};
|
|
|
|
onSubmitChangePassword = (event: MouseEvent<HTMLInputElement>) => {
|
|
event.preventDefault();
|
|
this.props.onChangePassword({ ...this.state });
|
|
};
|
|
|
|
render() {
|
|
const { oldPassword, newPassword, confirmNew } = this.state;
|
|
const { isSaving } = this.props;
|
|
const { ldapEnabled, authProxyEnabled } = config;
|
|
|
|
if (ldapEnabled || authProxyEnabled) {
|
|
return <p>You cannot change password when ldap or auth proxy authentication is enabled.</p>;
|
|
}
|
|
|
|
return (
|
|
<form name="userForm" className="gf-form-group">
|
|
<div className="gf-form max-width-30">
|
|
<PasswordInput label="Old Password" onChange={this.onOldPasswordChange} value={oldPassword} />
|
|
</div>
|
|
<div className="gf-form max-width-30">
|
|
<PasswordInput label="New Password" onChange={this.onNewPasswordChange} value={newPassword} />
|
|
</div>
|
|
<div className="gf-form max-width-30">
|
|
<PasswordInput label="Confirm Password" onChange={this.onConfirmPasswordChange} value={confirmNew} />
|
|
</div>
|
|
<div className="gf-form-button-row">
|
|
<Button variant="primary" onClick={this.onSubmitChangePassword} disabled={isSaving}>
|
|
Change Password
|
|
</Button>
|
|
<LinkButton variant="transparent" href={`${config.appSubUrl}/profile`}>
|
|
Cancel
|
|
</LinkButton>
|
|
</div>
|
|
</form>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default ChangePasswordForm;
|