forked from irinazheltisheva/fastsite-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditEntityForm.js
More file actions
47 lines (40 loc) · 1.44 KB
/
EditEntityForm.js
File metadata and controls
47 lines (40 loc) · 1.44 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
44
45
46
47
import React, { useState, useEffect } from 'react'
const EditEntityForm = props => {
const [ entity, setEntity ] = useState(props.currentEntity)
useEffect(
() => {
setEntity(props.currentEntity)
},
[ props ]
)
const handleInputChange = event => {
const { name, value } = event.target
setEntity({ ...entity, [name]: value })
}
return (
<form
onSubmit={event => {
event.preventDefault()
props.updateEntity(entity.id, entity)
}}
>
<label>Id</label>
<input type="text" name="id" value={entity.id} disabled="disabled"/>
<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>Update entity</button>
<button onClick={() => props.setEditing(false)} className="button muted-button">
Cancel
</button>
</form>
)
}
export default EditEntityForm