Created
May 12, 2019 10:06
-
-
Save yshuman1/491eb911b01c3ac6cb98ceff6e4f0302 to your computer and use it in GitHub Desktop.
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
import React, { Component } from 'react'; | |
import { connect } from 'react-redux'; | |
import { Picker, Text } from 'react-native'; | |
import { employeeUpdate, employeeCreate } from '../actions'; | |
import { Card, CardSection, Input, Button } from './common'; | |
class EmployeeCreate extends Component { | |
onButtonPress() { | |
const { name, phone, shift } = this.props; | |
this.props.employeeCreate({ name, phone, shift }); | |
} | |
render() { | |
return ( | |
<Card> | |
<CardSection> | |
<Input | |
label='Name' | |
placeholder='Jane' | |
value={this.props.name} | |
onChangeText={value => | |
this.props.employeeUpdate({ prop: 'name', value }) | |
} | |
/> | |
</CardSection> | |
<CardSection> | |
<Input | |
label='Phone' | |
placeholder='555-555-5555' | |
value={this.props.phone} | |
onChangeText={value => | |
this.props.employeeUpdate({ prop: 'phone', value }) | |
} | |
/> | |
</CardSection> | |
<CardSection style={{ flexDirection: 'column' }}> | |
<Text style={styles.pickerTextStyle}>Shift</Text> | |
<Picker | |
style={{ flex: 1 }} | |
selectedValue={this.props.shift} | |
onValueChange={value => | |
this.props.employeeUpdate({ prop: 'shift', value }) | |
} | |
> | |
<Picker.Item label='Monday' value='Monday' /> | |
<Picker.Item label='Tuesday' value='Tuesday' /> | |
<Picker.Item label='Wednesday' value='Wednesday' /> | |
<Picker.Item label='Thursday' value='Thursday' /> | |
<Picker.Item label='Friday' value='Friday' /> | |
<Picker.Item label='Saturday' value='Saturday' /> | |
<Picker.Item label='Sunday' value='Sunday' /> | |
</Picker> | |
</CardSection> | |
<CardSection> | |
<Button onPress={this.onButtonPress.bind(this)}>Create</Button> | |
</CardSection> | |
</Card> | |
); | |
} | |
} | |
const styles = { pickerTextStyle: { fontSize: 18, paddingLeft: 20 } }; | |
const mapStateToProps = state => { | |
const { name, phone, shift } = state.employeeForm; | |
return { name, phone, shift }; | |
}; | |
export default connect( | |
mapStateToProps, | |
{ employeeUpdate, employeeCreate } | |
)(EmployeeCreate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment