-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch.js
More file actions
393 lines (353 loc) · 10.9 KB
/
scratch.js
File metadata and controls
393 lines (353 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { reduxForm, Field } from 'redux-form';
import { withFirestore } from 'react-redux-firebase';
import { geocodeByAddress, getLatLng, geocodeByPlaceId } from 'react-places-autocomplete';
import { Segment, Form, Button, Grid, Header } from 'semantic-ui-react';
import {
combineValidators,
isRequired,
} from 'revalidate';
import TextInput from './components/TextInput';
import { createNewAccount } from '../../../redux/actions/create'
const mapState = (state, ownProps) => {
let location = {};
return {
initialValues: ownProps,
location,
};
};
const actions = {
createNewAccount
};
const validate = combineValidators({
//displayName: isRequired('displayName'),
firstName: isRequired('firstName'),
lastName: isRequired('lastName'),
locationName: isRequired('locationName'),
address: isRequired('address'),
// venue: isRequired('venue'),
});
class NewAccountForm extends Component {
state = {
address: {},
cityLatLng: {},
locationLatLng: {},
scriptLoaded: false
};
handleScriptLoaded = () => this.setState({ scriptLoaded: true });
handleAddressSelect = selectedAddress => {
geocodeByAddress(selectedAddress)
.then((result) => {
this.setState({ address: result[0].formatted_address})
})
geocodeByAddress(selectedAddress)
.then(results => geocodeByPlaceId(results[0].place_id))
.then(latlng => {
this.setState({
locationLatLng: latlng
});
})
.then(() => {
this.props.change('address', selectedAddress)
})
.catch((error) => {
console.log('Oh no!', error)
// this.setState({
// geocodeResults: this.renderGeocodeFailure(error),
// loading: false
// })
})
}
handleCitySelect = selectedCity => {
geocodeByAddress(selectedCity)
.then(results => getLatLng(results[0]))
.then(latlng => {
this.setState({
cityLatLng: latlng
});
})
.then(() => {
this.props.change('city', selectedCity);
});
};
handleVenueSelect = selectedVenue => {
geocodeByAddress(selectedVenue)
.then(results => getLatLng(results[0]))
.then(latlng => {
this.setState({
locationLatLng: latlng
});
})
.then(() => {
this.props.change('venue', selectedVenue);
});
};
onFormSubmit = values => {
values.locationLatLng = this.state.locationLatLng;
if (this.props.initialValues.id) {
if (Object.keys(values.locationLatLng).length === 0) {
values.locationLatLng = this.props.locationLatLng
}
console.log('Problem');
} else {
this.props.createNewAccount(values);
console.log('Submitted');
// this.props.history.push('/');
}
};
render() {
const { invalid, submitting, pristine, loading } = this.props;
// console.log('From Form',this.props);
console.log(this.state)
return (
<Grid>
{/* <Script
url="https://maps.googleapis.com/maps/api/js?key=AIzaSyBZWvcf7KHmOWX5EfFqZWkhl9pJw2GtiKk&libraries=places"
onLoad={this.handleScriptLoaded}
/> */}
<Grid.Column width={10}>
<Segment>
<Header sub color="teal" content="Ownership Details" />
<Form onSubmit={this.props.handleSubmit(this.onFormSubmit)}>
{/* <Field
name="displayName"
type="text"
component={TextInput}
placeholder="Username"
/> */}
<Field
name="firstName"
type="text"
component={TextInput}
placeholder="First Name"
/>
<Field
name="lastName"
type="text"
component={TextInput}
placeholder="Last Name"
/>
<Header sub color="teal" content="Location details" />
<Field
name="locationName"
type="text"
component={TextInput}
placeholder="Location Name"
/>
<Field
name="address"
type="text"
component={TextInput}
placeholder="Address"
/>
{/* <Field
name="address"
type="text"
component={PlaceInput}
options={{ types: ['establishment'] }}
placeholder="Find Place...."
onSelect={this.handleAddressSelect}
/>
<Field
name="city"
type="text"
component={PlaceInput}
//options={{ types: ['(cities)'] }}
placeholder="Event city"
onSelect={this.handleCitySelect}
/>
{this.state.scriptLoaded && (
<Field
name="venue"
type="text"
component={PlaceInput}
// options={{
// location: new google.maps.LatLng(this.state.cityLatLng),
// radius: 1000,
// types: ['establishment']
// }}
placeholder="Event venue"
onSelect={this.handleVenueSelect}
/>
)} */}
<Button
loading={loading}
disabled={invalid || submitting || pristine}
positive
type="submit"
>
Submit
</Button>
{/* <Button disabled={loading} onClick={this.props.history} type="button">
Cancel
</Button> */}
{/* {event.id &&
<Button
onClick={() => cancelToggle(!event.cancelled, event.id)}
type='button'
color={event.cancelled ? 'green' : 'red'}
floated='right'
content={event.cancelled ? 'Reactivate Event' : 'Cancel Event'}
/>} */}
</Form>
</Segment>
</Grid.Column>
</Grid>
);
}
}
export default withFirestore(
connect(mapState, actions)(
reduxForm({ form: 'newAccountForm', enableReinitialize: true, validate })(
NewAccountForm
)
)
);
// import React, { Component } from 'react'
// import PlacesAutocomplete, { geocodeByAddress, getLatLng } from 'react-places-autocomplete'
// import PlacesSingleMarkerMapComponent from '../../Maps/SingleMarkerMap';
// import NewAccountForm from './NewAccountForm';
// const renderSuggestion = ({ formattedSuggestion }) => (
// <div className="Demo__suggestion-item">
// <i className="fa fa-map-marker Demo__suggestion-icon" />
// <strong>{formattedSuggestion.mainText}</strong>{' '}
// <small className="text-muted">{formattedSuggestion.secondaryText}</small>
// </div>
// )
// const cssClasses = {
// root: 'form-group',
// input: 'Demo__search-input',
// autocompleteContainer: 'Demo__autocomplete-container',
// }
// const shouldFetchSuggestions = ({ value }) => value.length > 2
// const onError = (status, clearSuggestions) => {
// console.log(
// 'Error happened while fetching suggestions from Google Maps API',
// status
// )
// clearSuggestions()
// }
// class SearchBar extends Component {
// constructor(props) {
// super(props)
// this.state = {
// address: '',
// locationName: '',
// locationLatLng: {},
// addressDetails: null,
// placeId: null,
// geocodeResults: null,
// loading: false,
// }
// this.handleSelect = this.handleSelect.bind(this)
// this.handleChange = this.handleChange.bind(this)
// }
// handleSelect(address) {
// console.log(address);
// let locationName = address.split(',')[0];
// console.log(locationName);
// this.setState({
// address: locationName,
// locationName,
// loading: true,
// })
// geocodeByAddress(address)
// .then(results => getLatLng(results[0]))
// .then(({ lat, lng }) => {
// this.setState({
// locationLatLng: {lat, lng},
// geocodeResults: this.renderGeocodeSuccess(lat, lng),
// loading: false,
// })
// })
// .then(geocodeByAddress(address)
// .then((result) => {
// this.setState({ addressDetails: result[0].formatted_address})
// }))
// .catch(error => {
// console.log('Geocode Error', error)
// this.setState({
// geocodeResults: this.renderGeocodeFailure(error),
// loading: false,
// })
// })
// }
// handleChange(address) {
// this.setState({
// address,
// geocodeResults: null,
// })
// }
// renderGeocodeFailure(err) {
// return (
// <div className="alert alert-danger" role="alert">
// <strong>Error!</strong> {err}
// </div>
// )
// }
// renderGeocodeSuccess(lat, lng) {
// const markers = {
// lat,
// lng
// }
// return (
// <div>
// <div className="alert alert-success" role="alert">
// <strong>Success!</strong> Geocoder found latitude and longitude, continue with creating account.{' '}
// <PlacesSingleMarkerMapComponent
// markers={markers}
// />
// <strong>
// {lat}, {lng}
// </strong>
// </div>
// <div>
// </div>
// </div>
// )
// }
// render() {
// const inputProps = {
// type: 'text',
// value: this.state.address,
// onChange: this.handleChange,
// onBlur: () => {
// console.log('Blur event!')
// },
// onFocus: () => {
// console.log('Focused!')
// },
// autoFocus: true,
// placeholder: 'Search Places',
// name: 'Demo__input',
// id: 'my-input-id',
// }
// console.log(this.state);
// return (
// <div>
// <PlacesAutocomplete
// renderSuggestion={renderSuggestion}
// inputProps={inputProps}
// classNames={cssClasses}
// onSelect={this.handleSelect}
// onEnterKeyDown={this.handleSelect}
// onError={onError}
// shouldFetchSuggestions={shouldFetchSuggestions}
// />
// {this.state.loading && (
// <div>
// <i className="fa fa-spinner fa-pulse fa-3x fa-fw Demo__spinner" />
// </div>
// )}
// {this.state.geocodeResults && (
// <div>
// <div className="geocoding-results">{this.state.geocodeResults}</div>
// <div><NewAccountForm locationName={this.state.address} address={this.state.addressDetails} locationLatLng={this.state.locationLatLng} /></div>
// </div>
// )}
// </div>
// )
// }
// }
// export default SearchBar