Skip to content

Commit

Permalink
add logout #58
Browse files Browse the repository at this point in the history
  • Loading branch information
mydu committed Jul 1, 2019
1 parent c03868b commit 1035588
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
17 changes: 13 additions & 4 deletions importApp/src/containers/DataPrep/DataPrep.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
fetchDatapackage
} from '../../redux/modules/repoData';

import {loginCreateBranch} from '../../redux/modules/repoData';
import {loginCreateBranch, logoutUser} from '../../redux/modules/repoData';

import GithubAuthModal from '../../components/GithubAuthModal';

Expand Down Expand Up @@ -73,7 +73,7 @@ class DataPrep extends React.Component {

render () {
const {repoData} = this.props;
const {selectedBranch} = repoData;
const {selectedBranch, isLogined} = repoData;

return (
<div>
Expand All @@ -88,9 +88,17 @@ class DataPrep extends React.Component {
}
</Select>
<Button isColor="info" onClick={handleGetTables}>Fetch</Button> */}
<Button isColor="info" onClick={this.handleShowLogin}>
{ !isLogined &&
<Button isColor="info" onClick={this.handleShowLogin}>
<span>Login to get branch</span>
</Button>
</Button>
}
{
isLogined &&
<Button isColor="info" onClick={this.props.logoutUser}>
<span>Logout</span>
</Button>
}
{selectedBranch && this.renderFetchTable()}
<GithubAuthModal
isActive={this.state.isModalShow}
Expand All @@ -107,6 +115,7 @@ const mapStateToProps = state => ({
})

export default connect(mapStateToProps, {
logoutUser,
loginCreateBranch,
fetchAllTables,
fetchDatapackage
Expand Down
21 changes: 20 additions & 1 deletion importApp/src/redux/modules/repoData.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const CREATE_BRANCH_REQUEST = 'CREATE_BRANCH_REQUEST';
export const CREATE_BRANCH_SUCCESS = 'CREATE_BRANCH_SUCCESS';
export const CREATE_BRANCH_FAILURE = 'CREATE_BRANCH_FAILURE';

export const LOGOUT_USER = "LOGOUT_USER";

export const LOGIN_CREATE_BRANCH_REQUEST = 'LOGIN_CREATE_BRANCH_REQUEST';
export const LOGIN_CREATE_BRANCH_SUCCESS = 'LOGIN_CREATE_BRANCH_SUCCESS';
export const LOGIN_CREATE_BRANCH_FAILURE = 'LOGIN_CREATE_BRANCH_FAILURE';
Expand Down Expand Up @@ -237,6 +239,11 @@ export const createBranch = (payload) => (dispatch) => {
}))
}

export const logoutUser = () => ({
type: LOGOUT_USER
})


export const loginCreateBranch = (payload) => (dispatch) => {
dispatch({
type: LOGIN_CREATE_BRANCH_REQUEST,
Expand Down Expand Up @@ -287,11 +294,21 @@ export const loginCreateBranch = (payload) => (dispatch) => {
* REDUCER
*/

const initialState = {}
const initialState = {

}

export default function reducer(state = initialState, action){
const {payload} = action;
switch (action.type){
case LOGOUT_USER:
return {
...state,
isLogined: false,
tables: null,
selectedBranch:null,
isBranchCreated: false
}
case INIT_TABLES:
return {
...state,
Expand Down Expand Up @@ -322,12 +339,14 @@ export default function reducer(state = initialState, action){
case LOGIN_CREATE_BRANCH_SUCCESS:
return {
...state,
isLogined: true,
selectedBranch: payload,
isBranchCreated: true,
}
case LOGIN_CREATE_BRANCH_FAILURE:
return {
...state,
isLogined: false,
selectedBranch: null,
isBranchCreated: false
}
Expand Down

0 comments on commit 1035588

Please sign in to comment.