-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99ab8fa
commit 5589b3a
Showing
15 changed files
with
266 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import _ from 'lodash'; | ||
import firebase from 'firebase'; | ||
import { PROJECT_LIST_FETCH_SUCCESS, PROJECT_LIST_VALIDATING, | ||
PROJECT_LIST_VALIDATED } from './types'; | ||
|
||
export const projectListFetch = () => { | ||
return (dispatch) => { | ||
firebase.database().ref('/projects/') | ||
.on('value', snapshot => { | ||
const projects = _.map(snapshot.val(), (val, projectId) => { | ||
return { ...val, projectId }; | ||
}); | ||
|
||
_.remove(projects, (item) => { | ||
if ('isValid' in item) { | ||
return item; | ||
} | ||
}); | ||
|
||
dispatch({ type: PROJECT_LIST_FETCH_SUCCESS, payload: projects }); | ||
}); | ||
}; | ||
}; | ||
|
||
export const projectListValidating = (isValid, id) => { | ||
return (dispatch) => { | ||
dispatch({ type: PROJECT_LIST_VALIDATING }); | ||
|
||
firebase.database().ref(`/projects/${id}/`) | ||
.update({ isValid }) | ||
.then(() => { | ||
projectValidated(dispatch); | ||
}); | ||
}; | ||
}; | ||
|
||
const projectValidated = (dispatch) => { | ||
dispatch({ type: PROJECT_LIST_VALIDATED }); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import React, { Component } from 'react'; | ||
import { DrawerLayoutAndroid, ScrollView, RefreshControl, Alert } from 'react-native'; | ||
import { Container, List, Content, Button, Text, ListItem } from 'native-base'; | ||
import Swipeable from 'react-native-swipeable'; | ||
import { connect } from 'react-redux'; | ||
import { CustomHeader, MyDrawer } from '../commons/'; | ||
import { projectListFetch, projectListValidating } from '../../actions'; | ||
import { DRAWER_MENU } from '../commons/ButtonConst'; | ||
|
||
|
||
class ProjectList extends Component { | ||
componentWillMount() { | ||
this.props.projectListFetch(); | ||
} | ||
|
||
onRefresh() { | ||
this.props.projectListFetch(); | ||
} | ||
|
||
openDrawer() { | ||
this.refs['.DRAWER'].openDrawer(); | ||
} | ||
|
||
renderContent() { | ||
if (!this.props.loading) { | ||
return ( | ||
<List | ||
dataArray={this.props.project} | ||
renderRow={this.renderRow.bind(this)} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
renderRow(project) { | ||
const rightButtons = [ | ||
<Button | ||
full | ||
light | ||
style={{ alignItems: 'flex-start', flexDirection: 'column', flex: 1 }} | ||
onPress={() => | ||
Alert.alert('Info', `Project: ${project.project} \nTanggal: ${project.date} \nNama: ${project.fullName} \nPerusahaan: ${project.company}`) | ||
} | ||
> | ||
<Text>Info</Text> | ||
</Button>, | ||
<Button | ||
full | ||
success | ||
style={{ alignItems: 'flex-start', flexDirection: 'column', flex: 1 }} | ||
onPress={() => | ||
Alert.alert( | ||
'Validate', | ||
'Apakah project ini valid ?', | ||
[ | ||
{ text: 'Ya', onPress: () => this.props.projectListValidating(true, project.projectId) }, | ||
{ text: 'Tidak', onPress: () => this.props.projectListValidating(false, project.projectId) }, | ||
{ text: 'Kembali' } | ||
] | ||
) | ||
} | ||
|
||
> | ||
<Text>Validate</Text> | ||
</Button> | ||
]; | ||
|
||
return ( | ||
<Swipeable | ||
rightButtons={rightButtons} | ||
rightButtonWidth={125} | ||
|
||
> | ||
<ListItem> | ||
<Text>{project.project}</Text> | ||
</ListItem> | ||
</Swipeable> | ||
); | ||
} | ||
|
||
render() { | ||
const navigationView = (<MyDrawer />); | ||
|
||
return ( | ||
|
||
<DrawerLayoutAndroid | ||
drawerWidth={300} | ||
drawerPosition={DrawerLayoutAndroid.positions.Left} | ||
renderNavigationView={() => navigationView} | ||
ref={'.DRAWER'} | ||
> | ||
<Container> | ||
<CustomHeader | ||
headerText="Project List" | ||
leftButton={DRAWER_MENU} | ||
drawerOpen={() => this.openDrawer.bind(this)} | ||
/> | ||
<ScrollView | ||
refreshControl={ | ||
<RefreshControl | ||
refreshing={this.props.loading} | ||
onRefresh={this.onRefresh.bind(this)} | ||
colors={['#d9534f']} | ||
/> | ||
} | ||
> | ||
<Content> | ||
{this.renderContent()} | ||
</Content> | ||
</ScrollView> | ||
</Container> | ||
</DrawerLayoutAndroid> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = ({ projectList }) => { | ||
const project = projectList.projects; | ||
const loading = projectList.loading; | ||
|
||
return { project, loading }; | ||
}; | ||
|
||
export default connect(mapStateToProps, { projectListFetch, projectListValidating })(ProjectList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.