|
@@ -11,23 +11,37 @@ export default function Noticias(){
|
11
|
11
|
|
12
|
12
|
const [inputs, setInputs] = useState([]);
|
13
|
13
|
|
14
|
|
- //Esta funcion manejea los cambio que uno hace en cuanto a la informacion
|
15
|
|
- const handleChange = (event) => {
|
16
|
|
- const name = event.target.name;
|
17
|
|
- const value = event.target.value;
|
18
|
|
- setInputs(values => ({...values, [name]: value}));
|
19
|
|
- }
|
20
|
|
-
|
21
|
|
- //Esta funcion maneja los cambios al uno presionar el boton y lo sube a la base de datos
|
22
|
|
- const handleSubmit = (event) => {
|
23
|
|
- event.preventDefault();
|
24
|
|
-
|
25
|
|
- axios.post('http://localhost/apicenso/user/save', inputs).then(function(response){
|
26
|
|
- //axios.post('https://ada.uprrp.edu/~luis.ortiz79/api/user/save', inputs).then(function(response){
|
|
14
|
+ const handleSubmit = e => {
|
|
15
|
+ e.preventDefault();
|
|
16
|
+ e.persist();
|
|
17
|
+ axios({
|
|
18
|
+ method: 'post',
|
|
19
|
+ headers: {
|
|
20
|
+ 'Accept':'application/json',
|
|
21
|
+ 'content-type': 'application/json'
|
|
22
|
+ },
|
|
23
|
+ url: `https://ada.uprrp.edu/~luis.ortiz79/api/user/save`,
|
|
24
|
+ //data: formData
|
|
25
|
+ data: inputs,
|
|
26
|
+ body: JSON.stringify(inputs),
|
|
27
|
+ })
|
|
28
|
+ .then((response)=>response.json())
|
|
29
|
+ .then((response)=>{
|
27
|
30
|
console.log(response.data);
|
28
|
31
|
navigate('/');
|
|
32
|
+ })
|
|
33
|
+ .catch((error)=>{
|
|
34
|
+ alert("Error: " + error);
|
29
|
35
|
});
|
30
|
|
-
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+ const handleChange = (e) => {
|
|
39
|
+ const name = e.target.name;
|
|
40
|
+ const value = e.target.value;
|
|
41
|
+ setInputs(values => ({
|
|
42
|
+ ...values,
|
|
43
|
+ [name]: value,
|
|
44
|
+ }));
|
31
|
45
|
}
|
32
|
46
|
|
33
|
47
|
const [users, setUsers] = useState([]);
|
|
@@ -37,20 +51,44 @@ export default function Noticias(){
|
37
|
51
|
|
38
|
52
|
//Esta funcion busca el id de la noticia selecionada en la base de datos
|
39
|
53
|
function getUsers() {
|
40
|
|
- axios.get('http://localhost/apicenso/users/').then(function(response) {
|
41
|
|
- //axios.get('https://ada.uprrp.edu/~luis.ortiz79/api/users/').then(function(response) {
|
|
54
|
+ axios({
|
|
55
|
+ method: 'get',
|
|
56
|
+ headers: {
|
|
57
|
+ 'Accept':'application/json',
|
|
58
|
+ 'content-type': 'application/json'
|
|
59
|
+ },
|
|
60
|
+ url: `https://ada.uprrp.edu/~luis.ortiz79/api/users/`,
|
|
61
|
+ //data: formData
|
|
62
|
+ })
|
|
63
|
+ .then((response)=>response.json())
|
|
64
|
+ .then((response)=>{
|
42
|
65
|
console.log(response.data);
|
43
|
66
|
setUsers(response.data);
|
|
67
|
+ })
|
|
68
|
+ .catch((error)=>{
|
|
69
|
+ alert("Error: " + error);
|
44
|
70
|
});
|
45
|
71
|
}
|
46
|
72
|
|
47
|
73
|
|
48
|
|
- //Esta funcion envie el id a la base de datos para ser borrada
|
|
74
|
+ //Esta funcion envie el id a la base de datos para ser borrada
|
49
|
75
|
const deleteUser = (id) => {
|
50
|
|
- axios.delete(`http://localhost/apicenso/user/${id}/delete`).then(function(response){
|
51
|
|
- //axios.delete(`https://ada.uprrp.edu/~luis.ortiz79/api/user/${id}/delete`).then(function(response){
|
|
76
|
+ axios({
|
|
77
|
+ method: 'delete',
|
|
78
|
+ headers: {
|
|
79
|
+ 'Accept':'application/json',
|
|
80
|
+ 'content-type': 'application/json'
|
|
81
|
+ },
|
|
82
|
+ url: `https://ada.uprrp.edu/~luis.ortiz79/api/user/${id}/delete`,
|
|
83
|
+ //data: formData
|
|
84
|
+ })
|
|
85
|
+ .then((response)=>response.json())
|
|
86
|
+ .then((response)=>{
|
52
|
87
|
console.log(response.data);
|
53
|
88
|
getUsers();
|
|
89
|
+ })
|
|
90
|
+ .catch((error)=>{
|
|
91
|
+ alert("Error: " + error);
|
54
|
92
|
});
|
55
|
93
|
}
|
56
|
94
|
|
|
@@ -65,7 +103,6 @@ export default function Noticias(){
|
65
|
103
|
//En la primera tabla es donde el usuario puede subir la noticia en la base de datos
|
66
|
104
|
//En la segunda tabla es donde le da la lista de lo que contiene la base de datos y la opcion de poder borrar esa noticia
|
67
|
105
|
<div className="Noticias">
|
68
|
|
-
|
69
|
106
|
<h1>Noticias</h1>
|
70
|
107
|
|
71
|
108
|
<form onSubmit={handleSubmit}>
|
|
@@ -83,7 +120,7 @@ export default function Noticias(){
|
83
|
120
|
<th>
|
84
|
121
|
<label>Subject:</label>
|
85
|
122
|
</th>
|
86
|
|
- <td>
|
|
123
|
+ <td>
|
87
|
124
|
<textarea name="subject" placeholder="Write something.." onChange={handleChange} ></textarea>
|
88
|
125
|
</td>
|
89
|
126
|
</tr>
|
|
@@ -116,9 +153,9 @@ export default function Noticias(){
|
116
|
153
|
</td>
|
117
|
154
|
</tr>
|
118
|
155
|
)}
|
119
|
|
-
|
|
156
|
+
|
120
|
157
|
</tbody>
|
121
|
158
|
</table>
|
122
|
159
|
</div>
|
123
|
160
|
);
|
124
|
|
-}
|
|
161
|
+}
|