import React, { Component, Fragment } from 'react';
import { Link, NavLink, Redirect } from 'react-router-dom';
import ErrorBox from './error-box';
import InfoBox from './info-box';
import Sidebar from './sidebar';
import CONFIG from './fields-config.json';
class BuildingEdit extends Component {
render() {
if (!this.props.user){
return
}
if (!this.props.building_id){
return (
Back to maps
);
}
return (
{
CONFIG.map((conf_props) => {
return
})
}
);
}
}
class EditForm extends Component {
constructor(props) {
super(props);
this.state = {...props}
this.state.error = this.state.error || undefined;
this.handleChange = this.handleChange.bind(this);
this.handleLike = this.handleLike.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
const target = event.target;
const value = (target.value === '')? null : target.value;
const name = target.name;
this.setState({
[name]: value
});
}
handleLike(event) {
const liked = event.target.checked;
this.setState({
like: liked
});
}
handleSubmit(event) {
event.preventDefault();
this.setState({error: undefined})
fetch(`/building/${this.props.building_id}.json`, {
method: 'POST',
body: JSON.stringify(this.state),
headers:{
'Content-Type': 'application/json'
},
credentials: 'same-origin'
}).then(
res => res.json()
).then(function(res){
if (res.error) {
this.setState({error: res.error})
} else {
this.props.selectBuilding(res);
this.props.history.push(`/building/${this.props.building_id}.html`);
}
}.bind(this)).catch(
(err) => this.setState({error: err})
);
}
render() {
const match = true;
return (
match}>
{this.props.title}
)
}
}
const TextInput = (props) => (
{props.title}
);
const NumberInput = (props) => (
{props.title}
);
const LikeButton = (props) => (
Like this building?
);
export default BuildingEdit;