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

@@ -88,41 +88,39 @@ export class WorkItem extends React.Component {
}
const { search } = this.props.location
const params = search ? new URLSearchParams(search) : { get: () => null }
const id = params.get("id")
if (search) {
const id = new URLSearchParams(search).get("id")
if (id) {
api
.getWorkItem(id)
.then((workItem) => {
if (workItem) {
const [lng, lat] = workItem.location.coordinates
const region = {
latitude: lat,
longitude: lng,
latitudeDelta: 0.01,
longitudeDelta: 0.01,
}
workItem.location = formatLatLng(lat, lng)
this.setState({
binder: new FormBinder(workItem, WorkItem.bindings),
region,
})
if (id) {
api
.getWorkItem(id)
.then((workItem) => {
if (workItem) {
const [lng, lat] = workItem.location.coordinates
const region = {
latitude: lat,
longitude: lng,
latitudeDelta: 0.01,
longitudeDelta: 0.01,
}
})
.catch((err) => {
workItem.location = formatLatLng(lat, lng)
this.setState({
messageModal: {
icon: "hand",
message: "Unable to get work item details",
detail: err.message,
back: true,
},
binder: new FormBinder(workItem, WorkItem.bindings),
region,
})
}
})
.catch((err) => {
this.setState({
messageModal: {
icon: "hand",
message: "Unable to get work item details",
detail: err.message,
back: true,
},
})
}
})
}
}
@@ -219,6 +217,7 @@ export class WorkItem extends React.Component {
if (this.addressInput) {
this.addressInput.handleChangeText(address)
}
this.setState({ region: ref.mapView.region })
})
.catch(() => {
if (this.addressInput) {