import React, { RefObject } from 'react'; import { TextValidator, ValidatorForm } from 'react-material-ui-form-validator'; import { Dialog, DialogTitle, DialogContent, DialogActions, Checkbox } from '@material-ui/core'; import { PasswordValidator, BlockFormControlLabel, FormButton } from '../components'; import { User } from './types'; interface UserFormProps { creating: boolean; user: User; uniqueUsername: (value: any) => boolean; handleValueChange: (name: keyof User) => (event: React.ChangeEvent) => void; handleCheckboxChange: (name: keyof User) => (event: React.ChangeEvent, checked: boolean) => void; onDoneEditing: () => void; onCancelEditing: () => void; } class UserForm extends React.Component { formRef: RefObject = React.createRef(); componentDidMount() { ValidatorForm.addValidationRule('uniqueUsername', this.props.uniqueUsername); } submit = () => { this.formRef.current.submit(); } render() { const { user, creating, handleValueChange, handleCheckboxChange, onDoneEditing, onCancelEditing } = this.props; return ( {creating ? 'Add' : 'Modify'} User } label="Admin?" /> Done Cancel ); } } export default UserForm;