import React, {Component} from 'react'; import PropTypes from 'prop-types'; export default class AddLocation extends Component { constructor(props) { super(props); this.state = { type: 'A' } this.onSelectChange = this.onSelectChange.bind(this); this.saveLocation = this.saveLocation.bind(this); } onSelectChange(event) { this.setState({ type: event.target.value }); this.forceUpdate(); } handleNameChange = event => { this.setState({ name: event.target.value }); }; handleDescriptionChange = event => { this.setState({ desciption: event.target.value }); }; handleLatitudeChange = event => { this.setState({ latitude: event.target.value }); }; handleLongitudeChange = event => { this.setState({ longitude: event.target.value }); }; handleFoodTypeChange = event => { this.setState({ foodType: event.target.value }); }; handleMenuChange = event => { this.setState({ menu: event.target.value }); }; handleCategoryChange = event => { this.setState({ category: event.target.value }); }; handleYearOpenedChange = event => { this.setState({ yearOpened: event.target.value }); }; handleCapacityChange = event => { this.setState({ capacity: event.target.value }); }; async saveLocation() { var location = this.getLocation(); var res = await fetch('/api/locations',{ method: 'POST', body: JSON.stringify(location), headers: {"Content-Type": "application/json"} }); if (res.status === 200) { this.props.onSave(); } } getLocation() { var location = { name: this.state.name, description: (this.state.description === undefined ? null : this.state.description), type: this.state.type, latitude: this.state.latitude, longitude: this.state.longitude }; if (this.state.type === 'A') { location.attr = { category: this.state.category } } else if (this.state.type === 'R') { location.attr = { details: { foodType: this.state.foodType, menu: this.state.menu }, favorites: [] }; } else if (this.state.type === 'S') { location.attr = { details: { yearOpened: this.state.yearOpened, capacity: this.state.capacity }, events: [] }; } return location; } renderLocationTypeOptions() { if (this.state.type === 'A'){ return(
Type: | |
Name: | |
Description: | |
Latitude: | |
Longitude: |