// @flow import React from "react"; import {translate} from "react-i18next"; import type {User} from "../types/User"; import {Checkbox, InputField} from "../../components/forms"; import {SubmitButton} from "../../components/buttons"; type Props = { submitForm: User => void, user?: User, t: string => string }; class UserForm extends React.Component { constructor(props: Props) { super(props); this.state = { name: "", displayName: "", mail: "", password: "", admin: false, active: false, _links: {} }; } componentDidMount() { this.setState({ ...this.props.user }); } submit = (event: Event) => { event.preventDefault(); this.props.submitForm(this.state); }; render() { const { t } = this.props; const user = this.state; let nameField = null; if (!this.props.user) { nameField = ( ); } return (
{nameField} ); } handleUsernameChange = (name: string) => { this.setState({ name }); }; handleDisplayNameChange = (displayName: string) => { this.setState({ displayName }); }; handleEmailChange = (mail: string) => { this.setState({ mail }); }; handlePasswordChange = (password: string) => { this.setState({ password }); }; handleAdminChange = (admin: boolean) => { this.setState({ admin }); }; handleActiveChange = (active: boolean) => { this.setState({ active }); }; } export default translate("users")(UserForm);