37 lines
977 B
TypeScript
37 lines
977 B
TypeScript
import {Connector} from '../redux/Connector'
|
|
import {ICredentials} from '@rondo/common'
|
|
import {ILoginState} from './LoginReducer'
|
|
import {IStateSelector} from '../redux'
|
|
import {LoginActions} from './LoginActions'
|
|
import {LoginForm} from './LoginForm'
|
|
import {bindActionCreators} from 'redux'
|
|
import {withForm} from './withForm'
|
|
|
|
const defaultCredentials: ICredentials = {
|
|
username: '',
|
|
password: '',
|
|
}
|
|
|
|
export class LoginConnector extends Connector<ILoginState> {
|
|
|
|
constructor(protected readonly loginActions: LoginActions) {
|
|
super()
|
|
}
|
|
|
|
connect<State>(getLocalState: IStateSelector<State, ILoginState>) {
|
|
return this.wrap(
|
|
getLocalState,
|
|
state => ({
|
|
error: state.error,
|
|
user: state.user,
|
|
redirectTo: state.redirectTo,
|
|
}),
|
|
dispatch => ({
|
|
onSubmit: bindActionCreators(this.loginActions.logIn, dispatch),
|
|
clearOnSuccess: true,
|
|
}),
|
|
withForm(LoginForm, defaultCredentials),
|
|
)
|
|
}
|
|
}
|