Work item delete working

This commit is contained in:
John Lyon-Smith
2018-04-06 15:57:24 -07:00
parent 57f98ad398
commit 1c222f06e9
4 changed files with 82 additions and 38 deletions

View File

@@ -66,7 +66,7 @@ export class WorkItem extends React.Component {
isValid: (r, v) => v !== "", isValid: (r, v) => v !== "",
}, },
workItemType: { workItemType: {
isValid: true, isValid: (r, v) => v !== "",
alwaysGet: true, alwaysGet: true,
}, },
} }
@@ -171,14 +171,11 @@ export class WorkItem extends React.Component {
@autobind @autobind
handleRegionChange(region) { handleRegionChange(region) {
const { binder } = this.state if (this.latLngInput) {
this.latLngInput.handleChangeText(
this.setState(
binder.updateFieldValue(
"location",
formatLatLng(region.latitude, region.longitude) formatLatLng(region.latitude, region.longitude)
) )
) }
} }
render() { render() {
@@ -200,6 +197,7 @@ export class WorkItem extends React.Component {
name="workItemType" name="workItemType"
label="Work Item Type:" label="Work Item Type:"
options={workItemTypeEnum} options={workItemTypeEnum}
message="Select a work item type"
/> />
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
@@ -235,7 +233,12 @@ export class WorkItem extends React.Component {
pointerEvents={false} pointerEvents={false}
/> />
</MapView> </MapView>
<BoundInput binder={binder} name="location" label="Location:" /> <BoundInput
ref={(ref) => (this.latLngInput = ref)}
binder={binder}
name="location"
label="Location:"
/>
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<Text style={styles.label}>Pictures:</Text> <Text style={styles.label}>Pictures:</Text>

View File

@@ -52,12 +52,40 @@ export class WorkItemList extends React.Component {
} }
@autobind @autobind
handleItemSelect(item, index) { handleItemSelect(item, ref) {
this.props.history.push(`/workitem?id=${item._id}`) this.props.history.push(`/workitem?id=${item._id}`)
} }
@autobind @autobind
handleItemDelete(item, index) {} handleItemDelete(item, ref) {
api
.deleteWorkItem(item._id)
.then(() => {
return api
.listWorkItems()
.then((list) => {
this.setState({ listItems: list.items })
})
.catch(() => {
this.setState({
messageModal: {
icon: "hand",
message: "Unable to get list of work items",
detail: error.message,
},
})
})
})
.catch(() => {
this.setState({
messageModal: {
icon: "hand",
message: "Unable to get delete work item",
detail: error.message,
},
})
})
}
@autobind @autobind
handleMessageDismiss() { handleMessageDismiss() {
@@ -65,7 +93,7 @@ export class WorkItemList extends React.Component {
} }
@autobind @autobind
handleAddPress(item, index) { handleDonePress() {
this.props.history.push("/workitem") this.props.history.push("/workitem")
} }
@@ -88,7 +116,7 @@ export class WorkItemList extends React.Component {
<Header <Header
title="Work Items" title="Work Items"
leftButton={{ icon: "back", onPress: this.handleBackPress }} leftButton={{ icon: "back", onPress: this.handleBackPress }}
rightButton={{ icon: "add", onPress: this.handleAddPress }} rightButton={{ icon: "add", onPress: this.handleDonePress }}
/> />
<SwipeListView <SwipeListView
useFlatList useFlatList
@@ -99,8 +127,8 @@ export class WorkItemList extends React.Component {
paddingBottom: 20, paddingBottom: 20,
}} }}
data={listItems} data={listItems}
keyExtractor={(item) => (item._id)} keyExtractor={(item) => item._id}
renderItem={({ item, index }) => ( renderItem={({ item }, rowMap) => (
<TouchableHighlight <TouchableHighlight
style={{ style={{
height: 50, height: 50,
@@ -109,7 +137,7 @@ export class WorkItemList extends React.Component {
backgroundColor: "white", backgroundColor: "white",
}} }}
underlayColor="#EEEEEE" underlayColor="#EEEEEE"
onPress={() => this.handleItemSelect(item, index)}> onPress={() => this.handleItemSelect(item, rowMap[item._id])}>
<View <View
style={{ height: "100%", width: "100%", flexDirection: "row" }}> style={{ height: "100%", width: "100%", flexDirection: "row" }}>
<View <View
@@ -133,7 +161,7 @@ export class WorkItemList extends React.Component {
</View> </View>
</TouchableHighlight> </TouchableHighlight>
)} )}
renderHiddenItem={({ item, index }) => ( renderHiddenItem={({ item }, rowMap) => (
<TouchableOpacity <TouchableOpacity
style={{ style={{
flexDirection: "row", flexDirection: "row",
@@ -141,7 +169,7 @@ export class WorkItemList extends React.Component {
height: 50, height: 50,
backgroundColor: "red", backgroundColor: "red",
}} }}
onPress={() => this.handleItemDelete(item, index)}> onPress={() => this.handleItemDelete(item, rowMap[item._id])}>
<View <View
style={{ style={{
flexDirection: "column", flexDirection: "column",

View File

@@ -1,7 +1,7 @@
import React from 'react' import React from "react"
import PropTypes from 'prop-types' import PropTypes from "prop-types"
import { TextInput, Text, View } from 'react-native' import { TextInput, Text, View } from "react-native"
import autobind from 'autobind-decorator' import autobind from "autobind-decorator"
export class BoundInput extends React.Component { export class BoundInput extends React.Component {
static propTypes = { static propTypes = {
@@ -37,10 +37,8 @@ export class BoundInput extends React.Component {
const { binder, name } = this.props const { binder, name } = this.props
const state = binder.getFieldState(name) const state = binder.getFieldState(name)
if (!state.readOnly && !state.disabled) {
this.setState(binder.updateFieldValue(name, newText)) this.setState(binder.updateFieldValue(name, newText))
} }
}
render() { render() {
const { label, password, name, placeholder, message, lines } = this.props const { label, password, name, placeholder, message, lines } = this.props
@@ -51,14 +49,16 @@ export class BoundInput extends React.Component {
} }
return ( return (
<View style={{ width: '100%' }}> <View style={{ width: "100%" }}>
<Text style={{ color: 'black', fontSize: 14, marginBottom: 5 }}>{label}</Text> <Text style={{ color: "black", fontSize: 14, marginBottom: 5 }}>
{label}
</Text>
<TextInput <TextInput
style={{ style={{
width: '100%', width: "100%",
paddingLeft: 5, paddingLeft: 5,
paddingRight: 5, paddingRight: 5,
borderColor: 'gray', borderColor: "gray",
borderWidth: 1, borderWidth: 1,
fontSize: 16, fontSize: 16,
paddingTop: 7, paddingTop: 7,
@@ -67,17 +67,21 @@ export class BoundInput extends React.Component {
multiline={lines > 1} multiline={lines > 1}
numberOfLines={lines} numberOfLines={lines}
editable={!disabled} editable={!disabled}
autoCapitalize='none' autoCapitalize="none"
underlineColorAndroid='white' underlineColorAndroid="white"
value={value} value={value}
secureTextEntry={password} secureTextEntry={password}
onChangeText={this.handleChangeText} onChangeText={this.handleChangeText}
placeholder={placeholder} /> placeholder={placeholder}
<Text style={{ />
<Text
style={{
fontSize: 12, fontSize: 12,
display: valid ? 'none' : 'flex', display: valid ? "none" : "flex",
color: 'red', color: "red",
}}>{message}</Text> }}>
{message}
</Text>
</View> </View>
) )
} }

View File

@@ -12,6 +12,7 @@ export class BoundOptionStrip extends React.Component {
options: PropTypes.arrayOf( options: PropTypes.arrayOf(
PropTypes.shape({ value: PropTypes.string, text: PropTypes.string }) PropTypes.shape({ value: PropTypes.string, text: PropTypes.string })
).isRequired, ).isRequired,
message: PropTypes.string,
} }
constructor(props) { constructor(props) {
@@ -31,8 +32,8 @@ export class BoundOptionStrip extends React.Component {
} }
render() { render() {
const { name, label, options } = this.props const { name, label, options, message } = this.props
const { visible, disabled, value } = this.state const { visible, disabled, value, valid } = this.state
return ( return (
<View <View
@@ -49,6 +50,14 @@ export class BoundOptionStrip extends React.Component {
options={options} options={options}
onValueChanged={this.handleValueChanged} onValueChanged={this.handleValueChanged}
/> />
<Text
style={{
fontSize: 12,
display: valid ? "none" : "flex",
color: "red",
}}>
{message}
</Text>
</View> </View>
) )
} }