Fix bugs when adding activity

This commit is contained in:
John Lyon-Smith
2018-04-27 18:10:39 -07:00
parent 93f3d462b2
commit 53a4df55a2
8 changed files with 138 additions and 79 deletions

View File

@@ -20,13 +20,15 @@ import {
BoundOptionStrip,
BoundHeader,
BoundPhotoPanel,
FormStaticInput,
} from "../ui"
import { MessageModal, WaitModal } 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"
import { formatLatLng } from "../util"
import moment from "moment"
import "url-search-params-polyfill"
const styles = StyleSheet.create({
@@ -57,13 +59,6 @@ export class Activity extends React.Component {
noValue: true,
isDisabled: (r) => !(r.anyModified && r.allValid),
},
dateTime: {
isValid: (r, v) => v !== "",
isReadOnly: true,
},
details: {
isValid: (r, v) => v !== "",
},
resolution: {
isValid: (r, v) => v !== "",
},
@@ -72,14 +67,19 @@ export class Activity extends React.Component {
},
photos: {
isValid: (r, v) => v && v.length > 0,
initValue: [],
},
status: {
isValid: (r, v) => v !== "",
alwaysGet: true,
},
location: {
isValid: (r, v) => v !== "",
isReadOnly: true,
workItem: {
isValid: true,
alwaysGet: true,
},
team: {
isValid: true,
alwaysGet: true,
},
}
@@ -99,17 +99,26 @@ export class Activity extends React.Component {
const getWorkItem = (id) => {
api
.getWorkItem(id)
.then((workitem) => {
.then((workItem) => {
if (workItem) {
const [lng, lat] = workItem.location.coordinates
this.setState({
binder: new FormBinder(
{
workItem: workItem._id,
team: api.loggedInUser.team,
},
Activity.bindings
),
region: {
latitude: lat,
longitude: lng,
latitudeDelta: 0.01,
longitudeDelta: 0.01,
},
location: formatLatLng(lat, lng),
dateTime: moment().format(),
})
}
})
@@ -225,7 +234,14 @@ export class Activity extends React.Component {
}
render() {
const { binder, messageModal, waitModal, region } = this.state
const {
binder,
messageModal,
waitModal,
region,
dateTime,
location,
} = this.state
return (
<View style={{ width: "100%", height: "100%" }}>
@@ -257,12 +273,8 @@ export class Activity extends React.Component {
<BoundInput binder={binder} name="notes" label="Notes:" />
</View>
<View style={styles.panel}>
<BoundInput
binder={binder}
name="dateTime"
label="Date &amp; Time:"
/>
<BoundInput binder={binder} name="location" label="Location:" />
<FormStaticInput label="Date &amp; Time:" value={dateTime} />
<FormStaticInput label="Location:" value={location} />
<View style={{ flexDirection: "column", justifyContent: "center" }}>
<MapView
style={{
@@ -283,12 +295,7 @@ export class Activity extends React.Component {
showsScale={false}
showsUserLocation
cacheEnabled
initialRegion={{
latitude: 43.653908,
longitude: -79.384293,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
region={region}
/>
<Icon
name="target"