mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import { getBackendSrv } from '@grafana/runtime';
|
|
|
|
export interface UserAPI {
|
|
changePassword: (ChangePassword: ChangePasswordFields) => void;
|
|
}
|
|
|
|
interface LoadingStates {
|
|
changePassword: boolean;
|
|
}
|
|
|
|
export interface ChangePasswordFields {
|
|
oldPassword: string;
|
|
newPassword: string;
|
|
confirmNew: string;
|
|
}
|
|
|
|
export interface Props {
|
|
children: (api: UserAPI, states: LoadingStates) => JSX.Element;
|
|
}
|
|
|
|
export interface State {
|
|
loadingStates: LoadingStates;
|
|
}
|
|
|
|
export class UserProvider extends PureComponent<Props, State> {
|
|
state: State = {
|
|
loadingStates: {
|
|
changePassword: false,
|
|
},
|
|
};
|
|
|
|
changePassword = async (payload: ChangePasswordFields) => {
|
|
this.setState({ loadingStates: { ...this.state.loadingStates, changePassword: true } });
|
|
await getBackendSrv().put('/api/user/password', payload);
|
|
this.setState({ loadingStates: { ...this.state.loadingStates, changePassword: false } });
|
|
};
|
|
|
|
render() {
|
|
const { children } = this.props;
|
|
const { loadingStates } = this.state;
|
|
|
|
const api = {
|
|
changePassword: this.changePassword,
|
|
};
|
|
|
|
return <>{children(api, loadingStates)}</>;
|
|
}
|
|
}
|
|
|
|
export default UserProvider;
|