import React, { PureComponent, SyntheticEvent, ChangeEvent } from 'react'; import { Tooltip } from '@grafana/ui'; import appEvents from 'app/core/app_events'; interface Props { onSubmit: (pw: string) => void; onSkip: Function; focus?: boolean; } interface State { newPassword: string; confirmNew: string; valid: boolean; } export class ChangePassword extends PureComponent { private userInput: HTMLInputElement; constructor(props: Props) { super(props); this.state = { newPassword: '', confirmNew: '', valid: false, }; } componentDidUpdate(prevProps: Props) { if (!prevProps.focus && this.props.focus) { this.focus(); } } focus() { this.userInput.focus(); } onSubmit = (e: SyntheticEvent) => { e.preventDefault(); const { newPassword, valid } = this.state; if (valid) { this.props.onSubmit(newPassword); } else { appEvents.emit('alert-warning', ['New passwords do not match', '']); } }; onNewPasswordChange = (e: ChangeEvent) => { this.setState({ newPassword: e.target.value, valid: this.validate('newPassword', e.target.value), }); }; onConfirmPasswordChange = (e: ChangeEvent) => { this.setState({ confirmNew: e.target.value, valid: this.validate('confirmNew', e.target.value), }); }; onSkip = (e: SyntheticEvent) => { this.props.onSkip(); }; validate(changed: string, pw: string) { if (changed === 'newPassword') { return this.state.confirmNew === pw; } else if (changed === 'confirmNew') { return this.state.newPassword === pw; } return false; } render() { return (
Change Password
Before you can get started with awesome dashboards we need you to make your account more secure by changing your password.
You can change your password again later.
{ this.userInput = input; }} />
Skip
); } }