Skip to content

Commit

Permalink
New tab, routing and navigation (dexlab-io#78)
Browse files Browse the repository at this point in the history
Created a new tab in desktop mode called "Tip", where the Tip
component will be displayed in a modal, just like the Payment
modal. Also, created routing so that it is possible to navigate to
/address/:id/tip and make this modal open, both from desktop and from
mobile. Finally, added a "lastTab" state entry so the dapp knows which
tab to open once it is closed by a user. Created a dummy QR code
inside the Tip modal.
  • Loading branch information
Emilio Silva Schlenker committed Feb 28, 2019
1 parent e7fb8b8 commit 82ddcd3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ const Header = props => {
>
Recent Transactions
</MenuItem>
<MenuItem
className={`navbar-item ${activeNavItem ===
'tip' && 'is-active'}`}
onClick={() => onNavItemClick('tip')}
>
Tip
</MenuItem>
</div>
</div>
</Nav>
Expand Down
15 changes: 15 additions & 0 deletions src/pages/Dashboard/components/Tip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, { Component } from 'react';
import Modal from 'react-responsive-modal';
import QrCode from '../../Payment/components/QrCode';

class Tip extends Component {
render() {
return (
<Modal open={true} onClose={this.props.onClose}>
<QrCode valueCrypto="0" />
</Modal>
);
};
};

export default Tip;
4 changes: 4 additions & 0 deletions src/pages/Dashboard/desktop.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import GenerateBillBtn from './components/GenerateBillBtn';
import Keypad from './components/Keypad';
import RecentPayments from './components/RecentPayments';
import ProductItems from './components/ProductItems';
import Tip from './components/Tip';

const Section = styled.div`
grid-area: content;
Expand Down Expand Up @@ -61,6 +62,9 @@ export default function() {
}
/>
)}
{activeTab === 'tip' && (
<Tip onClose={this.onCloseTip} />
)}
</RightSide>
<LeftSide>
<NumberWrapper>
Expand Down
21 changes: 18 additions & 3 deletions src/pages/Dashboard/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import { withRouter, matchPath } from 'react-router-dom';

import { checkWindowSize } from '../../utils/helpers';
import { store } from '../../store';
Expand All @@ -15,14 +15,25 @@ class Dashboard extends Component {

this.state = {
isMobile: checkWindowSize(),
activeTab: 'numberPad',
activeTab: this.getActiveTab(),
lastTab: 'numberPad',
totalAmount: '0',
paymentModalOpen: false,
setupModalOpen: false,
pos: { address: null }
};
}

getActiveTab() {
const match = matchPath(window.location.pathname, {
path: '/address/:id/:activeTab'
});
if(match && match.params.activeTab === 'tip') {
return 'tip';
}
else return 'numberPad';
}

componentDidMount() {
// on screen resize
checkWindowSize(false, isMobile => {
Expand Down Expand Up @@ -62,7 +73,11 @@ class Dashboard extends Component {
) {
this.setState({ totalAmount: '0' });
}
this.setState({ activeTab });
this.setState({ activeTab, lastTab: currentTab });
};

onCloseTip = () => {
this.handleNavItemChange(this.state.lastTab);
};

render() {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Dashboard/mobile.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import GenerateBillBtn from './components/GenerateBillBtn';
import NumberInput from './components/Keypad/NumberInput';
import Keypad from './components/Keypad';
import RecentPayments from './components/RecentPayments';
import Tip from './components/Tip';

const Section = styled.div`
padding: 0.5rem 1.5rem;
Expand Down Expand Up @@ -35,6 +36,7 @@ export default function() {
</React.Fragment>
)}
{activeTab === 'recentPayments' && <RecentPayments />}
{activeTab === 'tip' && <Tip onClose={this.onCloseTip} />}
</div>
) : (
<div>Pos address is empty</div>
Expand Down

0 comments on commit 82ddcd3

Please sign in to comment.