import * as React from "react"; import { auth } from "../../firebase"; interface InterfaceProps { error?: any; history?: any; passwordOne?: string; passwordTwo?: string; } interface InterfaceState { error?: any; passwordOne?: string; passwordTwo?: string; } export class PasswordChangeForm extends React.Component< InterfaceProps, InterfaceState > { private static INITIAL_STATE = { error: null, passwordOne: "", passwordTwo: "" }; private static propKey(propertyName: string, value: string): object { return { [propertyName]: value }; } constructor(props: any) { super(props); this.state = { ...PasswordChangeForm.INITIAL_STATE }; } onSubmit = (event: any) => { const { passwordOne }: any = this.state; auth .doPasswordUpdate(passwordOne) .then(() => { this.setState(() => ({ ...PasswordChangeForm.INITIAL_STATE })); }) .catch(error => { this.setState(PasswordChangeForm.propKey("error", error)); }); event.preventDefault(); }; render() { const { passwordOne, passwordTwo, error }: any = this.state; const isInvalid = passwordOne !== passwordTwo || passwordOne === ""; return (
); } private setStateWithEvent(event: any, columnType: string): void { this.setState( PasswordChangeForm.propKey(columnType, (event.target as any).value) ); } }