1
1
import React , { useState } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import get from 'lodash/get' ;
4
+ import map from 'lodash/map' ;
4
5
import { Button , Input , InputNumber , Form , Row , Col } from 'antd' ;
5
6
import { httpActions } from '@codetanzania/ewea-api-client' ;
6
7
import { reduxActions } from '@codetanzania/ewea-api-states' ;
@@ -71,6 +72,14 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
71
72
const onFinish = ( values ) => {
72
73
const formData = { ...values } ;
73
74
75
+ // TODO: fix clearing custodians relations
76
+ // TODO: fix form ref geos.point.coordinates[0]
77
+ const longitude = get ( formData , 'geos.longitude' ) ;
78
+ const latitude = get ( formData , 'geos.latitude' ) ;
79
+ if ( longitude && latitude ) {
80
+ formData . geos . point = { coordinates : [ longitude , latitude ] } ;
81
+ }
82
+
74
83
if ( isEditForm ) {
75
84
const updates = { ...feature , ...formData } ;
76
85
putFeature (
@@ -87,14 +96,20 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
87
96
}
88
97
} ;
89
98
90
- const [ moreFilters , setMoreFilters ] = useState ( false ) ;
99
+ const [ moreOptions , setMoreOptions ] = useState ( false ) ;
91
100
92
101
return (
93
102
< Form
94
103
labelCol = { labelCol }
95
104
wrapperCol = { wrapperCol }
96
105
onFinish = { onFinish }
97
- initialValues = { { ...feature } }
106
+ initialValues = { {
107
+ ...feature ,
108
+ relations : {
109
+ ...get ( feature , 'relations' , { } ) ,
110
+ custodians : map ( get ( feature , 'relations.custodians' , [ ] ) , '_id' ) ,
111
+ } ,
112
+ } }
98
113
autoComplete = "off"
99
114
>
100
115
{ /* start: type & code */ }
@@ -126,7 +141,7 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
126
141
{ /* start:code */ }
127
142
< Col span = { 11 } >
128
143
< Form . Item
129
- label = "Code"
144
+ label = "Code/Number "
130
145
title = "Critical infrastructure code e.g DSM001"
131
146
name = { [ 'strings' , 'code' ] }
132
147
>
@@ -172,7 +187,7 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
172
187
>
173
188
< SearchableSelectInput
174
189
onSearch = { ( optns = { } ) => {
175
- return getAdministrativeAreas ( optns , feature ) ;
190
+ return getAdministrativeAreas ( optns ) ;
176
191
} }
177
192
optionLabel = { ( area ) => {
178
193
return `${ get ( area , 'strings.name.en' ) } (${ get (
@@ -191,14 +206,15 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
191
206
{ /* end: name & area */ }
192
207
193
208
{ /* start: longitude & latitude */ }
194
- { moreFilters && (
209
+ { moreOptions && (
195
210
< Row justify = "space-between" >
196
211
{ /* start:longitude */ }
197
212
< Col span = { 11 } >
198
213
< Form . Item
199
214
label = "Longitude"
200
215
title = "Critical infrastructure longitude(x-coordinate) e.g 39.2858"
201
- name = { [ 'geos' , 'point[0]' ] }
216
+ name = { [ 'geos' , 'longitude' ] }
217
+ initialValue = { get ( feature , 'geos.point.coordinates[0]' ) }
202
218
>
203
219
< InputNumber style = { { width : '100%' } } />
204
220
</ Form . Item >
@@ -209,7 +225,8 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
209
225
< Form . Item
210
226
label = "Latitude"
211
227
title = "Critical infrastructure latitude(y-coordinate) e.g -6.8188"
212
- name = { [ 'geos' , 'point[1]' ] }
228
+ name = { [ 'geos' , 'latitude' ] }
229
+ initialValue = { get ( feature , 'geos.point.coordinates[1]' ) }
213
230
>
214
231
< InputNumber style = { { width : '100%' } } />
215
232
</ Form . Item >
@@ -227,7 +244,7 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
227
244
>
228
245
< SearchableSelectInput
229
246
onSearch = { ( optns = { } ) => {
230
- return getAgencies ( optns , feature ) ;
247
+ return getAgencies ( optns ) ;
231
248
} }
232
249
optionLabel = { ( custodian ) => get ( custodian , 'name' ) }
233
250
optionValue = "_id"
@@ -249,8 +266,8 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
249
266
250
267
{ /* start:form actions */ }
251
268
< Form . Item wrapperCol = { { span : 24 } } style = { { textAlign : 'right' } } >
252
- < Button type = "link" onClick = { ( ) => setMoreFilters ( ! moreFilters ) } >
253
- { moreFilters ? 'Less Filters ' : 'More Filters ' }
269
+ < Button type = "link" onClick = { ( ) => setMoreOptions ( ! moreOptions ) } >
270
+ { moreOptions ? 'Less Options ' : 'More Options ' }
254
271
</ Button >
255
272
< Button style = { { marginLeft : 8 } } onClick = { onCancel } >
256
273
Cancel
@@ -261,7 +278,7 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
261
278
htmlType = "submit"
262
279
loading = { posting }
263
280
>
264
- Send
281
+ Save
265
282
</ Button >
266
283
</ Form . Item >
267
284
{ /* end:form actions */ }
0 commit comments