Files
grafana/public/app/core/utils/UserProvider.tsx
Shavonn Brown 874b8abcc0 ChangePassword: Rewrite change password page to react (#17811)
* 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
2019-07-03 17:02:11 +02:00

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;