Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #272 from bochaco/allow-switch-accounts
Browse files Browse the repository at this point in the history
feat/Allow switch accounts
  • Loading branch information
bochaco authored Sep 14, 2017
2 parents 2a9a15a + 9f8c966 commit 334e3fd
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions email_app/app/actions/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ACTION_TYPES = {

// Create Account
AUTHORISE_SHARE_MD: 'AUTHORISE_SHARE_MD',
CREATE_ACCOUNT_RESET: 'CREATE_ACCOUNT_RESET',
CREATE_ACCOUNT: 'CREATE_ACCOUNT',
CREATE_ACCOUNT_ERROR: 'SET_CREATE_ACCOUNT_ERROR',

Expand Down
5 changes: 5 additions & 0 deletions email_app/app/actions/create_account_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const createAccount = (emailId) => {
};
};

export const resetCurrentAccount = () => ({
type: ACTION_TYPES.CREATE_ACCOUNT_RESET,
payload: Promise.resolve()
});

export const createAccountError = (error) => ({
type: ACTION_TYPES.CREATE_ACCOUNT,
payload: Promise.reject(error)
Expand Down
15 changes: 14 additions & 1 deletion email_app/app/components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class Home extends Component {
super();

this.reconnect = this.reconnect.bind(this);
this.handleBack = this.handleBack.bind(this);
}

reconnect() {
Expand All @@ -21,6 +22,14 @@ export default class Home extends Component {
(err) => 'failed reconnecting');
}

handleBack(e) {
e.preventDefault();
const { resetCurrentAccount, getEmailIds } = this.props;
return resetCurrentAccount()
.then(() => getEmailIds())
.then(() => this.context.router.push(`/create_account`));
}

render() {
const { router } = this.context;
const { coreData, inboxSize, savedSize, networkStatus, processing } = this.props;
Expand Down Expand Up @@ -67,9 +76,13 @@ export default class Home extends Component {
</div>
<header className="home-head">
<div className="lt-sec">
<button className="mdl-button mdl-js-button mdl-button--icon" title="Switch email ID" onClick={this.handleBack}>
<i className="material-icons">keyboard_arrow_left</i>
</button>
</div>
<div className="rt-sec text-left">
<h3 className="title heading-md"><span className="bold">Email ID: </span>{coreData.id}</h3>
</div>
<div className="rt-sec text-right"></div>
</header>
<div className="home-cnt mdl-layout mdl-js-layout">
<div className="home-nav mdl-list">
Expand Down
5 changes: 4 additions & 1 deletion email_app/app/containers/home_container.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { connect } from 'react-redux';
import Home from '../components/home';
import { reconnectApplication, refreshEmail } from '../actions/initializer_actions';
import { reconnectApplication, refreshEmail, getEmailIds } from '../actions/initializer_actions';
import { resetCurrentAccount } from '../actions/create_account_actions';

const mapStateToProps = state => {
return {
Expand All @@ -17,6 +18,8 @@ const mapDispatchToProps = dispatch => {
return {
reconnectApplication: () => (dispatch(reconnectApplication())),
refreshEmail: (account) => (dispatch(refreshEmail(account))),
getEmailIds: () => (dispatch(getEmailIds())),
resetCurrentAccount: () => (dispatch(resetCurrentAccount()))
};
};

Expand Down
4 changes: 3 additions & 1 deletion email_app/app/less/home.less
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
color: #FFFFFF;
height: 64px;
.lt-sec, .rt-sec {
width: 50%;
padding: 0 16px;
.title {
line-height: 64px;
font-weight: normal;
}
}
.lt-sec {
width: 5%;
float: left;
line-height: 64px;
}
.rt-sec {
width: 95%;
float: right;
}
.clearfix();
Expand Down
3 changes: 3 additions & 0 deletions email_app/app/reducers/create_account.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const initialState = {

const createAccount = (state = initialState, action) => {
switch (action.type) {
case `${ACTION_TYPES.CREATE_ACCOUNT_RESET}_LOADING`:
return initialState;
break;
case `${ACTION_TYPES.CREATE_ACCOUNT}_ERROR`:
return { ...state, error: action.payload };
break;
Expand Down

0 comments on commit 334e3fd

Please sign in to comment.