import React, { Component, Fragment } from 'react';
import { Link, NavLink, Redirect } from 'react-router-dom';
import queryString from 'query-string';
import ErrorBox from './error-box';
import InfoBox from './info-box';
import Sidebar from './sidebar';
import { HelpIcon, CloseIcon, SaveIcon } from './icons';
import CONFIG from './fields-config.json';
const BuildingEdit = (props) => {
if (!props.user){
return
}
if (!props.building_id){
return (
Back to maps
);
}
const search = (props.location && props.location.search)?
queryString.parse(props.location.search):
{};
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 = this.props.search.cat === this.props.slug;
return (
match}>
{this.props.title}
{ (match && this.props.intro)? { this.props.intro }
: null }
{
match?
: null
}
)
}
}
const TextInput = (props) => (
);
const NumberInput = (props) => (
);
const LikeButton = (props) => (
);
export default BuildingEdit;