forked from irinazheltisheva/fastsite-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddEntityForm.js
More file actions
43 lines (37 loc) · 1.42 KB
/
AddEntityForm.js
File metadata and controls
43 lines (37 loc) · 1.42 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
import React, { useState } from 'react'
const AddEntityForm = props => {
const initialFormState = { id: '', title: '', subtitle: '', image: '', description: '', category: '' }
const [ entity, setEntity ] = useState(initialFormState)
const handleInputChange = event => {
const { name, value } = event.target
setEntity({ ...entity, [name]: value })
}
return (
<form
onSubmit={event => {
event.preventDefault()
if (!entity.id || !entity.title){
alert("Please add id and title");
return
}
props.addEntity(entity)
setEntity(initialFormState)
}}
>
<label>Id</label>
<input type="text" name="id" value={entity.id} onChange={handleInputChange} />
<label>Title</label>
<input type="text" name="title" value={entity.title} onChange={handleInputChange} />
<label>Subtitle</label>
<input type="text" name="subtitle" value={entity.subtitle} onChange={handleInputChange} />
<label>Image URL</label>
<input type="text" name="image" value={entity.image} onChange={handleInputChange} />
<label>Category</label>
<input type="text" name="category" value={entity.category} onChange={handleInputChange} />
<label>Description</label>
<textarea name="description" value={entity.description} rows="4" onChange={handleInputChange} />
<button>Add new entity</button>
</form>
)
}
export default AddEntityForm