Clicking on activity working

This commit is contained in:
John Lyon-Smith
2018-04-14 16:12:33 -07:00
parent 56db130612
commit 5c7b3fd1c2
2 changed files with 139 additions and 43 deletions

View File

@@ -1,4 +1,4 @@
import React from 'react' import React from "react"
import { import {
StyleSheet, StyleSheet,
View, View,
@@ -8,34 +8,45 @@ import {
TextInput, TextInput,
KeyboardAvoidingView, KeyboardAvoidingView,
Platform, Platform,
TouchableOpacity TouchableOpacity,
} from 'react-native' } from "react-native"
import MapView, { Marker } from 'react-native-maps' import MapView, { Marker } from "react-native-maps"
import { FormBinder } from 'react-form-binder' import { FormBinder } from "react-form-binder"
import { Icon, Header, PhotoButton, BoundInput, BoundButton, BoundOptionStrip } from '../ui' import {
import autobind from 'autobind-decorator' Icon,
import { ifIphoneX, isIphoneX } from 'react-native-iphone-x-helper' Header,
PhotoButton,
BoundInput,
BoundButton,
BoundOptionStrip,
} from "../ui"
import { MessageModal } from "../Modal"
import autobind from "autobind-decorator"
import KeyboardSpacer from "react-native-keyboard-spacer"
import { isIphoneX } from "react-native-iphone-x-helper"
import { api } from "../API"
import { formatLatLng, parseLatLng } from "../util"
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
flexGrow: 1, flexGrow: 1,
backgroundColor: '#DDDDDD', backgroundColor: "#DDDDDD",
}, },
panel: { panel: {
width: '94%', width: "94%",
backgroundColor: 'white', backgroundColor: "white",
alignSelf: 'center', alignSelf: "center",
marginTop: '3%', marginTop: "3%",
shadowColor: 'gray', shadowColor: "gray",
shadowOffset: { width: 2, height: 2 }, shadowOffset: { width: 2, height: 2 },
shadowRadius: 2, shadowRadius: 2,
shadowOpacity: .5, shadowOpacity: 0.5,
padding: 10, padding: 10,
}, },
label: { label: {
fontSize: 14, fontSize: 14,
marginBottom: 4, marginBottom: 4,
} },
}) })
export class Activity extends React.Component { export class Activity extends React.Component {
@@ -44,7 +55,8 @@ export class Activity extends React.Component {
isValid: true, isValid: true,
}, },
location: { location: {
isValid: true, isValid: (r, v) => v !== "",
isReadOnly: true,
}, },
details: { details: {
isValid: true, isValid: true,
@@ -57,7 +69,7 @@ export class Activity extends React.Component {
}, },
status: { status: {
isValid: true, isValid: true,
} },
} }
constructor(props) { constructor(props) {
@@ -66,6 +78,51 @@ export class Activity extends React.Component {
binder: new FormBinder({}, Activity.bindings), binder: new FormBinder({}, Activity.bindings),
messageModal: null, messageModal: null,
} }
const { search } = this.props.location
if (search) {
const id = new URLSearchParams(search).get("id")
if (id) {
api
.getActivity(id)
.then((activity) => {
if (activity) {
const [lng, lat] = activity.location.coordinates
activity.location = formatLatLng(lat, lng)
this.setState({
binder: new FormBinder(activity, Activity.bindings),
region: {
latitude: lat,
longitude: lng,
latitudeDelta: 0.01,
longitudeDelta: 0.01,
},
})
}
})
.catch((err) => {
this.setState({
messageModal: {
icon: "hand",
message: "Unable to get activity details",
detail: err.message,
back: true,
},
})
})
}
}
}
@autobind
handleMessageDismiss() {
const back = this.state.messageModal.back
this.setState({ messageModal: null })
if (back) {
this.handleBackPress()
}
} }
@autobind @autobind
@@ -75,41 +132,49 @@ export class Activity extends React.Component {
if (history.length > 1) { if (history.length > 1) {
history.goBack() history.goBack()
} else { } else {
history.replace('/home') history.replace("/home")
} }
} }
render() { render() {
const { binder } = this.state const { binder, messageModal, region } = this.state
return ( return (
<View style={{ width: '100%', height: '100%' }}> <View style={{ width: "100%", height: "100%" }}>
<Header title='Activity' leftButton={{ icon: 'back', onPress: this.handleBackPress }} /> <Header
title="Activity"
leftButton={{ icon: "back", onPress: this.handleBackPress }}
/>
<ScrollView style={styles.container}> <ScrollView style={styles.container}>
<View style={styles.panel}> <View style={styles.panel}>
<BoundInput binder={binder} name='resolution' label='Resolution:' /> <BoundInput binder={binder} name="resolution" label="Resolution:" />
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<BoundOptionStrip <BoundOptionStrip
binder={binder} binder={binder}
options={[ options={[
{ value: 'planned', text: 'Planned' }, { value: "planned", text: "Planned" },
{ value: 'open', text: 'Open' }, { value: "open", text: "Open" },
{ value: 'onHold', text: 'On Hold' }, { value: "onHold", text: "On Hold" },
{ value: 'closed', text: 'Closed' }, { value: "closed", text: "Closed" },
]} ]}
label='Status:' label="Status:"
name='status' /> name="status"
/>
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<BoundInput binder={binder} name='notes' label='Notes:' /> <BoundInput binder={binder} name="notes" label="Notes:" />
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<BoundInput binder={binder} name='dateTime' label='Date &amp; Time:' /> <BoundInput
<BoundInput binder={binder} name='location' label='Location:' /> binder={binder}
name="dateTime"
label="Date &amp; Time:"
/>
<BoundInput binder={binder} name="location" label="Location:" />
<MapView <MapView
style={{ style={{
width: '100%', width: "100%",
height: 400, height: 400,
marginTop: 10, marginTop: 10,
}} }}
@@ -119,24 +184,43 @@ export class Activity extends React.Component {
longitude: -79.384293, longitude: -79.384293,
latitudeDelta: 0.0922, latitudeDelta: 0.0922,
longitudeDelta: 0.0421, longitudeDelta: 0.0421,
}} /> }}
/>
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<Text style={styles.label}>Pictures:</Text> <Text style={styles.label}>Pictures:</Text>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', marginBottom: 5 }}> <View
style={{
flexDirection: "row",
justifyContent: "space-between",
marginBottom: 5,
}}>
<PhotoButton /> <PhotoButton />
<PhotoButton /> <PhotoButton />
<PhotoButton /> <PhotoButton />
</View> </View>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', marginTop: 5 }}> <View
style={{
flexDirection: "row",
justifyContent: "space-between",
marginTop: 5,
}}>
<PhotoButton /> <PhotoButton />
<PhotoButton /> <PhotoButton />
<PhotoButton /> <PhotoButton />
</View> </View>
</View> </View>
{ isIphoneX ? <View style={{ height: 30, width: '100%' }} /> : null } {isIphoneX ? <View style={{ height: 30, width: "100%" }} /> : null}
</ScrollView> </ScrollView>
<MessageModal
open={!!messageModal}
icon={messageModal ? messageModal.icon : ""}
message={messageModal ? messageModal.message : ""}
detail={messageModal ? messageModal.detail : ""}
onDismiss={messageModal && this.handleMessageDismiss}
/>
{Platform.OS === "ios" && <KeyboardSpacer />}
</View> </View>
); )
} }
} }

View File

@@ -84,8 +84,8 @@ export class Home extends React.Component {
} }
@autobind @autobind
handleItemSelect(item, index) { handleItemSelect(item) {
this.props.history.push("/activity") this.props.history.push(`/activity?id=${item._id}`)
} }
@autobind @autobind
@@ -207,12 +207,24 @@ export class Home extends React.Component {
<View <View
key={workItem._id} key={workItem._id}
style={{ style={{
flexDirection: "column", flexDirection: "row",
justifyContent: "center", justifyContent: "flex-start",
alignItems: "center",
backgroundColor: "#F4F4F4", backgroundColor: "#F4F4F4",
paddingLeft: 8, paddingLeft: 8,
height: 45, height: 45,
}}> }}>
<Icon
name={
workItem.workItemType === "order"
? "hardhat"
: workItem.workItemType === "complaint"
? "question"
: "clipboard"
}
size={16}
style={{ marginRight: 10 }}
/>
<Text style={{ fontSize: 16 }}> <Text style={{ fontSize: 16 }}>
{workItemTypeText[workItem.workItemType].toUpperCase()}{" "} {workItemTypeText[workItem.workItemType].toUpperCase()}{" "}
{pad(workItem.ticketNumber, 4)} {pad(workItem.ticketNumber, 4)}
@@ -230,7 +242,7 @@ export class Home extends React.Component {
backgroundColor: "white", backgroundColor: "white",
}} }}
underlayColor="#EEEEEE" underlayColor="#EEEEEE"
onPress={() => this.handleItemSelect(activity, index)}> onPress={() => this.handleItemSelect(activity)}>
<View <View
style={{ style={{
height: "100%", height: "100%",