import React from 'react'; // @ts-ignore import {Field, reduxForm} from "redux-form"; import { History, LocationState } from 'history'; import {Link} from 'react-router-dom'; import routes from '../../../constants/routes.json'; import SecondLogin from "./index"; interface Props { authStore: { UsersId: string }; history: History; getUsers: any; authError: string; secondLogin: any; users: any; match: any; handleSubmit: any; } interface State { user: any } class LoginUser extends React.Component { constructor(props:Props) { super(props); this.state = { user: {} } } componentDidMount(): void { this.props.getUsers(this.props.authStore.UsersId); this.setUpUser(); } componentDidUpdate(prevProps: any): void { if(prevProps.users.users !== this.props.users.users) { this.setUpUser(); } } setUpUser = () => { const { match, history, users } = this.props; const id = match.params.id; if(users.users) { const user = users.users.filter((user: any) => user.PharmacyUsersId == id); if(user.length > 0) { this.setState({user: user[0]}); } else { history.push("/store") } } }; renderError(){ if (this.props.authError) { return (
{/*{error}*/} {this.props.authError}
) } return ''; } renderInput = (args: any) => { const {icon, type, placeholder, name, input, meta} = args; const styleClass = meta.touched && meta.error ? "input-group input-lg": "input-group no-border input-lg"; return ( <>
{/*{this.renderError(meta)}*/} ) }; submitHandle = (formValues: any) => { this.props.secondLogin({...formValues, username: this.state.user.UserName, id: this.props.authStore.UsersId}, () =>{ this.props.history.push(routes.DASHBOARD); }) }; render() { return (

{this.state.user && this.state.user.UserName}

{this.renderError()}
Go Back
); } } const validate = (formValues: {password: string}) => { let error = { password: '' }; if(!formValues.password) { error.password = "you must enter the password" } return error; }; export default reduxForm({form: "signUser", validate: validate})(LoginUser);