import React from "react" import * as antd from "antd" import { Icons } from "components/Icons" import config from "config" import "./index.less" const LoginSteps = { "username": (props) => { const handleUpdate = (e) => { props.onUpdate(e.target.value) } return
Username or Email
}, "password": (props) => { const handleUpdate = (e) => { props.onUpdate(e.target.value) } return
Password
} } const phasesToSteps = { 0: "username", 1: "password", } export default class Login extends React.Component { static pageStatement = { bottomBarAllowed: false } state = { loading: false, loginInputs: {}, error: null, phase: 0, } handleFinish = async () => { const payload = { username: this.state.loginInputs.username, password: this.state.loginInputs.password, } this.clearError() this.toogleLoading(true) this.props.sessionController.login(payload, (error, response) => { this.toogleLoading(false) if (error) { return this.onError(error) } else { if (response.status === 200) { this.onDone() } } }) } onDone = () => { if (typeof this.props.onDone === "function") { this.props.onDone() } if (typeof this.props.close === "function") { this.props.close() } } onClickRegister = () => { if (typeof this.props.close === "function") { this.props.close() } app.eventBus.emit("app.createRegister") } toogleLoading = (to) => { if (typeof to === "undefined") { to = !this.state.loading } this.setState({ loading: to }) } clearError = () => { this.setState({ error: null }) } onError = (error) => { this.setState({ error: error }) } onUpdateInput = (input, value) => { this.setState({ loginInputs: { ...this.state.loginInputs, [input]: value } }) } renderCurrentInput = () => { const { phase } = this.state const step = phasesToSteps[phase] return React.createElement(LoginSteps[step], { onUpdate: (...props) => this.onUpdateInput(step, ...props), next: this.nextStep, defaultValue: this.state.loginInputs[step], }) } nextStep = () => { const to = this.state.phase + 1 if (!phasesToSteps[to]) { return this.handleFinish() } this.setState({ phase: to }) } prevStep = () => { const to = this.state.phase - 1 if (!phasesToSteps[to]) { console.warn("No step found for phase", to) return } this.setState({ phase: to }) } canNext = () => { if (this.state.loading) { return false } const { phase } = this.state const step = phasesToSteps[phase] return !!this.state.loginInputs[step] } render() { return

Sign in

To continue to {config.app.siteName}

{this.renderCurrentInput()}
{ this.state.phase > 0 && Back } Continue
{this.state.error}
You need a account?
} }