Skip to content

Commit 9c96214

Browse files
Merge pull request #18 from leapfrogtechnology/LFG-180
Lfg 180: Fetched employee list from API
2 parents 43af024 + 0dd1cfb commit 9c96214

File tree

18 files changed

+333
-57
lines changed

18 files changed

+333
-57
lines changed

App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { startSplashScreen } from './app/navigator/splashScreenNavigator';
1515
import screens from 'App/constants/screens';
1616
import { registerScreens, registerScreenVisibilityListener } from './screenRegistry';
1717

18-
const store = configureStore();
18+
export const store = configureStore();
1919

2020
registerScreens(store, Provider);
2121
registerScreenVisibilityListener()

app/actions/fetchActions.js

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,86 @@
1-
import uri from 'App/config/uri';
2-
import {VALIDATE_EMAIL} from 'App/constants/actionsType';
1+
import { uri } from 'App/config/uri';
2+
import * as util from 'App/utils/dataNormalization';
3+
import * as Resource from 'App/utils/networkResource';
4+
import * as ActionType from 'App/constants/actionsType';
5+
import { store } from './../../App';
36

4-
validateLeapfrogEmail = (dispatch) => {
7+
export const validateEmail = (token) => {
8+
console.log('11111', Resource.emailValidation(token));
9+
return (dispatch) => {
10+
dispatch(networkFetching())
11+
fetch(uri.EMAIL_VALIDATION, Resource.emailValidation(token))
12+
.then(data => data.json())
13+
.then(json => {
14+
console.log('json:', json)
15+
dispatch(validateLFEmail())
16+
})
17+
.catch(err => dispatch(networkFetchError(err)))
18+
}
19+
}
20+
21+
export const fetchEmployeeFromAPI = (apiKey) => {
22+
console.log('77777');
23+
return (dispatch) => {
24+
dispatch(networkFetching())
25+
fetch(uri.EMPLOYEES_LIST, Resource.employeesList(apiKey))
26+
.then(data => data.json())
27+
.then(jsonResponse => {
28+
console.log('json:', jsonResponse);
29+
var myProfile = util.myInformation(jsonResponse, store.getState().rootReducer.auth.user.email)[0];
30+
dispatch(myProfileInfo(myProfile));
31+
dispatch(getEmployeeList(jsonResponse));
32+
})
33+
.catch(err => {dispatch(networkFetchError(err))
34+
console.log("9999", err)
35+
})
36+
}
37+
}
38+
39+
fetchAction = (uri, completion) => {
40+
console.log('22222');
41+
return
42+
dispatch(networkFetching())
43+
fetch(uri)
44+
.then(data => data.json())
45+
.then(data => dispatch(completion(data)))
46+
.catch(error => dispatch(networkFetchError()));
47+
}
48+
49+
networkFetching = () => {
50+
console.log('33333');
51+
return {
52+
type: ActionType.NETWORK_FETCHING,
53+
}
54+
}
55+
56+
networkFetchError = () => {
57+
console.log('44444');
58+
return {
59+
type: ActionType.NETWORK_FETCH_ERROR,
60+
}
61+
}
62+
63+
validateLFEmail = () => {
64+
console.log('55555');
65+
return {
66+
type: ActionType.VALIDATE_EMAIL,
67+
payload: {
68+
valid: true,
69+
}
70+
}
71+
}
72+
73+
getEmployeeList = (employees) => {
74+
console.log('88888');
575
return {
6-
76+
type: ActionType.EMPLOYEES_LIST,
77+
employees
778
}
879
}
980

10-
validateEmail = () => {
81+
myProfileInfo = (myProfile) => {
1182
return {
12-
type: VALIDATE_EMAIL,
83+
type: ActionType.MY_PROFILE,
84+
myProfile
1385
}
1486
}

app/config/uri.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
export const BASE_URI = 'https://lms.lftechnology.com';
1+
const BASE_URI = 'https://lms.lftechnology.com';
22
const api = '/api';
33

44
export const uri = {
5-
EMAIL_VALIDATION = `${api}/emailvalidation`,
6-
5+
EMAIL_VALIDATION: `${BASE_URI}${api}/emailvalidation`,
6+
EMPLOYEES_LIST: `${BASE_URI}${api}/employeelist`,
77
};
8-
9-
export default uri;

app/constants/actionsType.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export const LOGIN = 'LOGIN';
22
export const LOGOUT = 'LOGOUT';
3+
export const MY_PROFILE = 'MY_PROFILE';
34
export const VALIDATE_EMAIL = 'VALIDATE_EMAIL';
5+
export const EMPLOYEES_LIST = 'EMPLOYEES_LIST';
6+
export const NETWORK_FETCHING = 'NETWORK_FETCHING';
7+
export const NETWORK_FETCH_ERROR = 'NETWORK_FETCH_ERROR';

app/reducers/auth.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as ActionType from 'App/constants/actionsType';
2-
import { ActionSheetCustom } from 'react-native-actionsheet';
32

43
const initialState = {
54
user: null,

app/reducers/contactReducer.js

Whitespace-only changes.

app/reducers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { combineReducers } from 'redux';
22
import auth from './auth';
3+
import user from './user';
34

45
const rootReducer = combineReducers({
5-
auth
6+
auth,
7+
user,
68
});
79

810
export default { rootReducer };

app/reducers/user.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as actionType from 'App/constants/actionsType';
2+
3+
const initialState = {
4+
isValid: false,
5+
}
6+
7+
const user = (state = initialState, action) => {
8+
switch (action.type) {
9+
case actionType.VALIDATE_EMAIL:
10+
console.log('VALIDATE_EMAIL');
11+
return {
12+
...state,
13+
isValid: true,
14+
};
15+
16+
case actionType.EMPLOYEES_LIST:
17+
console.log('EMPLOYEES_LIST', action.employees);
18+
return {
19+
...state,
20+
employees: action.employees
21+
};
22+
23+
case actionType.MY_PROFILE:
24+
console.log('MY_PROFILE', action.myProfile);
25+
return {
26+
...state,
27+
myProfile: action.myProfile
28+
}
29+
default:
30+
return state;
31+
}
32+
};
33+
34+
export default user;

app/screens/contact/contact.js

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import {
33
View,
44
Text,
55
Image,
6-
SectionList
6+
SectionList,
7+
ActivityIndicator,
78
} from 'react-native';
89
import Swiper from 'react-native-swiper';
910
import Search from 'react-native-search-box';
1011
import ParallaxScrollView from 'react-native-parallax-scroll-view';
1112

13+
import * as util from 'App/utils/dataNormalization';
1214
import colors from 'App/config/colors';
1315
import ContactCell from './contactCell';
1416
import screens from 'App/constants/screens';
@@ -62,6 +64,10 @@ const DEPARTMENT_LIST = [{
6264
}
6365
}
6466

67+
componentDidMount() {
68+
this.props.employees ? null : this.props.fetchEmployees()
69+
}
70+
6571
_onSearchBarTextChange = () => {
6672
console.log('bigno');
6773
}
@@ -173,35 +179,61 @@ const DEPARTMENT_LIST = [{
173179
})
174180
}
175181

182+
_renderStatusBar = () => {
183+
return (
184+
<View style={[style.statusBar, {height: 20}]}/>
185+
)
186+
}
187+
188+
_renderSearchBar = () => {
189+
return (
190+
<Search
191+
ref={component => this.searchBar = component}
192+
backgroundColor={colors.LF_DARK_GRREEN}
193+
titleCancelColor='white'
194+
onChangeText={this._onSearchBarTextChange}
195+
onFocus={this._onSearchBarFocus}
196+
afterSearch={this.onSearch}
197+
afterCancel={this.onCancel}
198+
keyboardDismissOnSubmit={true}
199+
blurOnSubmit={true}
200+
/>
201+
)
202+
}
203+
204+
_renderSwiper = () => {
205+
return (
206+
<Swiper
207+
style={style.wrapper}
208+
loop={false}
209+
onIndexChanged ={this._onMomentumScrollEnd}
210+
activeDotStyle={{marginBottom: DOT_MARGIN}}
211+
activeDotColor={colors.LF_DARK_GRREEN}
212+
dotStyle={{marginBottom: DOT_MARGIN}}>
213+
{
214+
DEPARTMENT_LIST.map((data, index) => this._renderTableView(data, index))
215+
}
216+
</Swiper>
217+
)
218+
}
219+
220+
_renderActivityIndicator = () => {
221+
return (
222+
<View style={[style.container, style.horizontal]}>
223+
<ActivityIndicator size="large" color={colors.GRAY} />
224+
</View>
225+
)
226+
}
227+
176228
render() {
177229
return (
178230
<View style={ style.mainContainer }>
179-
<View style={[style.statusBar, {height: 20}]}/>
231+
{ this._renderStatusBar() }
180232
<View style={style.searchContainer}>
181-
<Search
182-
ref={component => this.searchBar = component}
183-
backgroundColor={colors.LF_DARK_GRREEN}
184-
titleCancelColor='white'
185-
onChangeText={this._onSearchBarTextChange}
186-
onFocus={this._onSearchBarFocus}
187-
afterSearch={this.onSearch}
188-
afterCancel={this.onCancel}
189-
keyboardDismissOnSubmit={true}
190-
blurOnSubmit={true}
191-
/>
233+
{ this._renderSearchBar() }
192234
</View>
193235
<View style={style.tableContainer}>
194-
<Swiper
195-
style={style.wrapper}
196-
loop={false}
197-
onIndexChanged ={this._onMomentumScrollEnd}
198-
activeDotStyle={{marginBottom: DOT_MARGIN}}
199-
activeDotColor={colors.LF_DARK_GRREEN}
200-
dotStyle={{marginBottom: DOT_MARGIN}}>
201-
{
202-
DEPARTMENT_LIST.map((data, index) => this._renderTableView(data, index))
203-
}
204-
</Swiper>
236+
{ this.props.employees ? this._renderSwiper() : this._renderActivityIndicator() }
205237
</View>
206238
</View>
207239
);
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { connect } from 'react-redux';
22

33
import ContactScreen from './contact';
4+
import { LF_API_KEY } from 'App/constants/credentials';
5+
import * as fetchActions from 'App/actions/fetchActions';
46

57
const mapStateToProps = (state) => ({
6-
loggedIn: state.rootReducer.auth.loggedIn,
7-
user: state.rootReducer.auth.user,
8+
employees: state.rootReducer.user.employees,
9+
});
10+
11+
const mapDispatchToProps = (dispatch) => ({
12+
fetchEmployees: () => { dispatch(fetchActions.fetchEmployeeFromAPI(LF_API_KEY)) }
813
});
914

1015
export default connect(
1116
mapStateToProps,
17+
mapDispatchToProps
1218
)(ContactScreen);

0 commit comments

Comments
 (0)