import React, { useState } from 'react' 
import axios from 'axios';

export default function Create() {
    const [name, setName] = useState('');
    const postData = (e) => {
	e.preventDefault();
        //console.log('name: '+name);
	const url='http://83.223.94.182:65535/entities/create';
        //console.log('url: '+url);
	let data = new FormData();
	data.append('name',name);
	let config = {
	    method: 'post',
	    maxBodyLength: Infinity,
	    url: url,
	    data : data
	};
	axios.request(config)
	    .catch((error)=>{
		console.error('create:axios error: '+error);
	    });
    };
    return (
	<div>
	    <h1>Create</h1>
	    <form onSubmit={postData}>
		<label>
		    Enter name (input:{name}):
		    <input
			placeholder='Name'
			type="text"
			value={name}
			onChange={(e) => setName(e.target.value)}
		    />
		</label>
		<input
		    type="submit" />
	    </form>
	</div>
    );
};
