member signin redirect

This commit is contained in:
geek 2017-08-14 16:27:51 +09:00
parent efce4ccbe9
commit 3cd9585259
3 changed files with 52 additions and 41 deletions

View File

@ -7,12 +7,12 @@ import {
import State from '../redux/state/SignIn';
import * as signinActions from '../redux/action/signIn';
import { push as routerPush } from 'react-router-redux';
import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest';
export function mapStateToProps(state: any, ownProps?: any): SignInStateProps {
return {
isAuthenticated: state.isAuthenticated,
};
}
@ -22,6 +22,9 @@ export function mapDispatchToProps(dispatch: Dispatch<any>, ownProps?: any): Sig
// dispatch(signinActions.request(signinId, signinPw));
dispatch(asyncRequestActions.request('MemberService', 'signin', signinActions.REQUEST, signinId, signinPw));
},
onRedirectHome: () => {
dispatch(routerPush('/'));
},
};
}

View File

@ -16,12 +16,14 @@ const options = [
{ key: 'unitedstates', value: '1', text: 'United States(1)' },
];
export interface StateProps {
isAuthenticated?:boolean;
}
export interface DispatchProps {
onSignIn?(signinId: string, signinPw: string ): void;
onSignUp?(): void;
onResetPassword?():void;
onRedirectHome():void;
}
export type Props = StateProps & DispatchProps;
@ -46,8 +48,7 @@ export class SignIn extends React.Component<Props, State> {
}
public render(): JSX.Element {
return (
<Form>
let signinElement = <Form>
<Form.Input fluid placeholder='Email' defaultValue={this.state.email} onChange={
(event: React.SyntheticEvent<HTMLInputElement>, data: InputOnChangeData) => {
this.setState({ email: data.value });
@ -92,8 +93,13 @@ export class SignIn extends React.Component<Props, State> {
<Button primary onClick={this.PopupClose}> Ok </Button>
</Modal.Actions>
</Modal>
</Form>
);
</Form>;
if( this.props.isAuthenticated ) {
this.props.onRedirectHome();
} else {
return signinElement;
}
}
private forgotPopupOpen = () => this.setState({ forgotPopup: true });

View File

@ -7,8 +7,10 @@ import SigninState, { defaultState as signinDefaultState } from '../state/SignIn
const reducer: ReducersMapObject = {
[SigninActionTypes.REQUEST_SUCCESS]: (state: SigninState = signinDefaultState, action: Action<Member>): SigninState => {
return state;
return {
...state,
isAuthenticated: true,
};
},
[SigninActionTypes.REQUEST_FAILURE]: (state: SigninState = signinDefaultState, action: Action<Error>): SigninState => {
return state;