Skip to content

Commit 9330073

Browse files
committed
refactoring, usage of constants, currency dropdown impl in TransferPage.
1 parent a6552e9 commit 9330073

File tree

29 files changed

+162
-110
lines changed

29 files changed

+162
-110
lines changed
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
1-
// TODO: Soft-coded action types.
2-
// export const ADD_TODO = 'ADD_TODO'
1+
import {
2+
ACTIONTYPE_SHOWDIALOG,
3+
ACTIONTYPE_HIDEDIALOG,
4+
ACTIONTYPE_LOGIN,
5+
ACTIONTYPE_LOGOUT,
6+
ACTIONTYPE_CURRENCIESOBSOLETE,
7+
ACTIONTYPE_CURRENCIESUPTODATE
8+
} from '../config/constants'
39

410
export const showDialog = (titleEnum, message, callback) => ({
5-
type: 'SHOW_DIALOG',
11+
type: ACTIONTYPE_SHOWDIALOG,
612
titleEnum,
713
message,
814
callback
915
})
1016

1117
export const closeDialog = {
12-
type: 'HIDE_DIALOG'
18+
type: ACTIONTYPE_HIDEDIALOG
1319
}
1420

1521
export const login = (username) => ({
16-
type: 'LOGIN',
22+
type: ACTIONTYPE_LOGIN,
1723
username
1824
})
1925

2026
export const logout = {
21-
type: 'LOGOUT'
27+
type: ACTIONTYPE_LOGOUT
2228
}
2329

2430
export const currenciesObsolete = {
25-
type: 'CURRENCIES_OBSOLETE'
31+
type: ACTIONTYPE_CURRENCIESOBSOLETE
2632
}
2733

2834
export const currenciesUptodate = {
29-
type: 'CURRENCIES_UPTODATE'
35+
type: ACTIONTYPE_CURRENCIESUPTODATE
3036
}

BankApplicationFrontend/src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React from 'react';
44
import ReactDOM from 'react-dom';
55

6-
import MainPage from './pages/MainPage/MainPage';
6+
import MainPage from './components/pages/MainPage/MainPage';
77

88
import 'bootstrap/dist/css/bootstrap.min.css';
99

BankApplicationFrontend/src/components/MoneyBar/MoneyBar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import { Alert } from 'react-bootstrap'
33
import { connect } from 'react-redux'
4-
54
import Request from '../../services/Request'
65
import { showDialog, currenciesUptodate } from '../../actions';
6+
import { URL_RETRIEVEWEALTH } from '../../config/constants'
77

88
const mapStateToProps = state => ({
99
loggedInUsername: state.login,
@@ -46,7 +46,7 @@ class MoneyBar extends React.Component {
4646
this.setState({ isProcessing: true });
4747

4848
const request = new Request().getRequestInstance();
49-
request.post('wealth/retrieve', { username: this.props.loggedInUsername })
49+
request.post(URL_RETRIEVEWEALTH, { username: this.props.loggedInUsername })
5050
.then((response) => {
5151
Object.keys(response.data.wealthMap).map((key) => {
5252
if (response.data.wealthMap[key] == 0) delete response.data.wealthMap[key];

BankApplicationFrontend/src/components/NavigationBar/NavigationBar.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react';
2-
import { Link, Redirect } from 'react-router-dom';
1+
import React from 'react'
2+
import { Link, Redirect } from 'react-router-dom'
33
import { connect } from 'react-redux'
4-
import { Navbar, Nav, NavItem } from 'react-bootstrap';
5-
6-
import { showDialog, logout } from '../../actions';
4+
import { Navbar, Nav, NavItem } from 'react-bootstrap'
5+
import { showDialog, logout } from '../../actions'
6+
import { LSKEY_USERNAME } from '../../config/constants'
77

88
const mapStateToProps = state => ({
99
loggedInUsername: state.login
@@ -34,7 +34,7 @@ class NavBarTop extends React.Component {
3434
}
3535

3636
onLoggedOut() {
37-
localStorage.removeItem('username');
37+
localStorage.removeItem(LSKEY_USERNAME);
3838
this.props.logout();
3939
this.setState({ hasJustLoggedOut: true });
4040
}
@@ -46,11 +46,10 @@ class NavBarTop extends React.Component {
4646
return <Redirect to="/" />
4747
}
4848

49-
5049
const loginLogout = this.props.loggedInUsername == null ?
5150
<NavItem style={navbarStyling} componentclass="span"><Link to="/login">Login</Link></NavItem> :
5251
<NavItem style={navbarStyling} onClick={() =>
53-
this.props.showPopup(1, 'Are sure you want to logout ' + this.props.loggedInUsername + '?', this.onLoggedOut())}>Logout</NavItem>
52+
this.props.showPopup(1, 'Are sure you want to logout ' + this.props.loggedInUsername + '?', this.onLoggedOut)}>Logout</NavItem>
5453

5554
return (
5655
<Navbar bg="light" expand="lg" >

BankApplicationFrontend/src/pages/CurrencyPage/CurrencyList/Currency/BuySellModal/BuySellModal.js renamed to BankApplicationFrontend/src/components/pages/CurrencyPage/CurrencyList/Currency/BuySellModal/BuySellModal.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React from 'react';
2-
import NumberFormat from 'react-number-format';
3-
import { Modal, InputGroup, FormControl, Button } from 'react-bootstrap';
4-
import Request from '../../../../../services/Request';
1+
import React from 'react'
2+
import NumberFormat from 'react-number-format'
3+
import { Modal, InputGroup, FormControl, Button } from 'react-bootstrap'
4+
import Request from '../../../../../../services/Request'
5+
import {URL_MAKETRANSACTION} from '../../../../../../config/constants'
56

67
class BuySellModal extends React.Component {
78

@@ -32,7 +33,7 @@ class BuySellModal extends React.Component {
3233
});
3334

3435
const request = new Request().getRequestInstance();
35-
request.post('transaction/make',
36+
request.post(URL_MAKETRANSACTION,
3637
{
3738
username: this.props.username,
3839
buying: this.props.isBuying,

BankApplicationFrontend/src/pages/CurrencyPage/CurrencyList/Currency/Currency.js renamed to BankApplicationFrontend/src/components/pages/CurrencyPage/CurrencyList/Currency/Currency.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { ButtonToolbar, Button } from 'react-bootstrap';
33
import { connect } from 'react-redux'
4-
import { showDialog, currenciesObsolete } from '../../../../actions';
4+
import { showDialog, currenciesObsolete } from '../../../../../actions';
55

66
import BuySellModal from './BuySellModal/BuySellModal'
77

BankApplicationFrontend/src/pages/CurrencyPage/CurrencyPage.js renamed to BankApplicationFrontend/src/components/pages/CurrencyPage/CurrencyPage.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
2-
import CurrencyList from './CurrencyList/CurrencyList'
3-
import Request from '../../services/Request'
4-
52
import { connect } from 'react-redux'
6-
import { showDialog } from '../../actions';
3+
import CurrencyList from './CurrencyList/CurrencyList'
4+
import Request from '../../../services/Request';
5+
import { BASEURL_EXCHANGERATES, URL_EXCHANGERATES } from '../../../config/constants'
6+
import { showDialog } from '../../../actions'
77

88
const mapDispatchToProps = dispatch => ({
99
showPopup: (title, message) => dispatch(showDialog(title, message))
@@ -17,8 +17,8 @@ class CurrencyPage extends React.Component {
1717
}
1818

1919
componentDidMount() {
20-
const request = new Request().getRequestInstance('https://api.exchangeratesapi.io');
21-
request.get('/latest?base=TRY').then((response) => {
20+
const request = new Request().getRequestInstance(BASEURL_EXCHANGERATES);
21+
request.get(URL_EXCHANGERATES).then((response) => {
2222
this.setState({ currencies: response.data.rates });
2323
}).catch((error) => {
2424
console.log(error);

BankApplicationFrontend/src/pages/HistoryPage/HistoryPage.js renamed to BankApplicationFrontend/src/components/pages/HistoryPage/HistoryPage.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React from 'react';
1+
import React from 'react'
22
import { connect } from 'react-redux'
3-
import Request from '../../services/Request'
4-
import { showDialog } from '../../actions';
3+
import { showDialog } from '../../../actions'
4+
import Request from '../../../services/Request';
5+
import { URL_RETRIEVEHISTORY } from '../../../config/constants'
56
import EmptyListWrapper from './EmptyListWrapper/EmptyListWrapper'
67
import HistoryList from './HistoryList/HistoryList'
78

@@ -30,7 +31,7 @@ class HistoryPage extends React.Component {
3031
this.setState({ isRetrievingRecords: true });
3132

3233
const request = new Request().getRequestInstance();
33-
request.post('transaction/findAllByUsername', {
34+
request.post(URL_RETRIEVEHISTORY, {
3435
username: this.props.loggedInUsername
3536
}).then((response) => {
3637
console.log(response);

BankApplicationFrontend/src/pages/LoginPage/LoginPage.js renamed to BankApplicationFrontend/src/components/pages/LoginPage/LoginPage.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import React from 'react';
2-
import { Form, Button } from 'react-bootstrap';
3-
import { Redirect } from 'react-router-dom';
1+
import React from 'react'
2+
import { Form, Button } from 'react-bootstrap'
3+
import { Redirect } from 'react-router-dom'
44
import { connect } from 'react-redux'
5-
6-
import FormElement from '../../components/FormElement/FormElement';
7-
import Request from '../../services/Request';
8-
import { login, showDialog } from '../../actions';
9-
10-
const ERROR_ALLFIELDSMANDATORY = 'All fields are mandatory.';
5+
import FormElement from '../../FormElement/FormElement'
6+
import Request from '../../../services/Request'
7+
import { login, showDialog } from '../../../actions'
8+
import { ERROR_ALLFIELDSMANDATORY, URL_LOGIN, LSKEY_USERNAME } from '../../../config/constants'
119

1210
const mapStateToProps = state => ({
1311
isLoggedIn: state.login != null
@@ -51,12 +49,12 @@ class LoginPage extends React.Component {
5149
});
5250

5351
const request = new Request().getRequestInstance();
54-
request.post('user/login', {
52+
request.post(URL_LOGIN, {
5553
username: this.state.username,
5654
password: this.state.password
5755
}).then((response) => {
5856
console.log(response);
59-
localStorage.setItem('username', response.data.username);
57+
localStorage.setItem(LSKEY_USERNAME, response.data.username);
6058
this.setState({ isLoggedIn: true });
6159
}).catch((error) => {
6260
console.log(error);

BankApplicationFrontend/src/pages/MainPage/MainPage.js renamed to BankApplicationFrontend/src/components/pages/MainPage/MainPage.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import { Container } from 'react-bootstrap'
33
import { BrowserRouter as Router, Route } from 'react-router-dom'
44
import { connect } from 'react-redux'
55

6-
import NavBarTop from '../../components/NavigationBar/NavigationBar';
7-
import PopupDialog from '../../components/PopupDialog/PopupDialog';
6+
import NavBarTop from '../../NavigationBar/NavigationBar'
7+
import PopupDialog from '../../PopupDialog/PopupDialog'
8+
import MoneyBar from '../../MoneyBar/MoneyBar'
89

9-
import HomePage from '../HomePage/HomePage';
10-
import UsersPage from '../UsersPage/UsersPage';
11-
import CurrencyPage from '../CurrencyPage/CurrencyPage';
12-
import TransferPage from '../TransferPage/TransferPage';
13-
import HistoryPage from '../HistoryPage/HistoryPage';
10+
import HomePage from '../HomePage/HomePage'
11+
import UsersPage from '../UsersPage/UsersPage'
12+
import CurrencyPage from '../CurrencyPage/CurrencyPage'
13+
import TransferPage from '../TransferPage/TransferPage'
14+
import HistoryPage from '../HistoryPage/HistoryPage'
1415

15-
import RegisterPage from '../RegisterPage/RegisterPage';
16-
import LoginPage from '../LoginPage/LoginPage';
16+
import RegisterPage from '../RegisterPage/RegisterPage'
17+
import LoginPage from '../LoginPage/LoginPage'
1718

18-
import MoneyBar from '../../components/MoneyBar/MoneyBar';
19-
20-
import { login } from '../../actions';
19+
import { login } from '../../../actions'
20+
import { LSKEY_USERNAME } from '../../../config/constants'
2121

2222
const mapDispatchToProps = dispatch => ({
2323
login: (username) => dispatch(login(username))
@@ -28,7 +28,7 @@ class MainPage extends React.Component {
2828
constructor(props) {
2929
super(props);
3030

31-
const storedUsername = localStorage.getItem('username');
31+
const storedUsername = localStorage.getItem(LSKEY_USERNAME);
3232
if (storedUsername != null) {
3333
this.props.login(storedUsername);
3434
}

BankApplicationFrontend/src/pages/RegisterPage/RegisterPage.js renamed to BankApplicationFrontend/src/components/pages/RegisterPage/RegisterPage.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ import React from 'react';
22
import { Redirect } from 'react-router-dom';
33
import { Form, Button } from 'react-bootstrap';
44
import { connect } from 'react-redux'
5-
import FormElement from '../../components/FormElement/FormElement';
6-
import Request from '../../services/Request';
7-
import { login, showDialog } from '../../actions';
8-
9-
const ERROR_ALLFIELDSMANDATORY = 'All fields are mandatory.';
10-
const ERROR_DIFFPASS = 'Password fields should be same.';
11-
const ERROR_TCNOLENGTH = 'Length of TC No must be 11. Currently it is: ';
5+
import FormElement from '../../FormElement/FormElement';
6+
import Request from '../../../services/Request';
7+
import { ERROR_ALLFIELDSMANDATORY, ERROR_DIFFPASS, ERROR_TCNOLENGTH, URL_REGISTER, LSKEY_USERNAME } from '../../../config/constants'
8+
import { login, showDialog } from '../../../actions';
129

1310
const mapStateToProps = state => ({
1411
isLoggedIn: state.login != null
@@ -59,7 +56,7 @@ class RegisterPage extends React.Component {
5956

6057
if (this.state.firstPass != this.state.secondPass) {
6158
this.props.showPopup(1, ERROR_DIFFPASS);
62-
} else if (this.state.username == '' || this.tcno == '' || this.state.firstPass == '') {
59+
} else if (this.state.username == '' || this.state.tcno == '' || this.state.firstPass == '') {
6360
this.props.showPopup(1, ERROR_ALLFIELDSMANDATORY);
6461
} else if (this.state.tcno.length != 11) {
6562
this.props.showPopup(1, ERROR_TCNOLENGTH + this.state.tcno.length);
@@ -70,14 +67,14 @@ class RegisterPage extends React.Component {
7067
});
7168

7269
const request = new Request().getRequestInstance();
73-
request.post('user/new', {
70+
request.post(URL_REGISTER, {
7471
username: this.state.username,
7572
password: this.state.firstPass,
7673
tcno: this.state.tcno
7774
}).then((response) => {
7875
console.log(response);
79-
localStorage.setItem('username', response.data.username);
80-
this.props.login(localStorage.getItem('username'));
76+
localStorage.setItem(LSKEY_USERNAME, response.data.username);
77+
this.props.login(localStorage.getItem(LSKEY_USERNAME));
8178
}).catch((error) => {
8279
console.log(error);
8380
var errorMessage = 'Network error';

BankApplicationFrontend/src/pages/TransferPage/CurrencyDropdown/CurrencyDropdown.js renamed to BankApplicationFrontend/src/components/pages/TransferPage/CurrencyDropdown/CurrencyDropdown.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { Form } from 'react-bootstrap';
3-
import Request from '../../../services/Request';
3+
import Request from '../../../../services/Request';
44
import CurrencyDropdownItem from './CurrencyDropdownItem/CurrencyDropdownItem'
55

66
class CurrencyDropdown extends React.Component {
@@ -13,6 +13,10 @@ class CurrencyDropdown extends React.Component {
1313
}
1414
}
1515

16+
onPickCurrency() {
17+
this.props.onDropdownChanged(this.inputEl.value);
18+
}
19+
1620
componentDidMount() {
1721
const request = new Request().getRequestInstance('https://api.exchangeratesapi.io');
1822
request.get('/latest?base=TRY')
@@ -30,7 +34,8 @@ class CurrencyDropdown extends React.Component {
3034
);
3135

3236
return (
33-
<Form.Control as="select">
37+
<Form.Control as="select" onChange={this.onPickCurrency.bind(this)} ref={el => this.inputEl = el}>
38+
<option value="">Select</option>
3439
{currencies}
3540
</Form.Control>
3641
)

0 commit comments

Comments
 (0)