import React, { useEffect, useState } from 'react'; import { InputText } from 'primereact/inputtext'; import { Button } from 'primereact/button'; import { DataTable } from 'primereact/datatable'; import { Column } from 'primereact/column'; const GuardasSeguridad = () => { const [pokemones, setPokemones] = useState([]); const [urlFetch, setUrlFetch] = useState( 'http://localhost:4000/user/findGuards/62be68215692582bbfd77134', ); async function fetchP() { let nombres = await fetch(urlFetch, { method: 'GET' }); let pokemonesRes = await nombres.json(); setPokemones(pokemonesRes.message); console.log(pokemones); } useEffect(() => { fetchP(); }, []); function registrarGuarda() { var data = { dni: document.getElementById('identificacion').value, name: document.getElementById('nombre').value, last_name: document.getElementById('apellidos').value, email: document.getElementById('correo_electronico').value, phone: document.getElementById('telefono').value, password: document.getElementById('correo_electronico').value, user_type: '4', //4 es guarda status: '1', community_id: '62be68215692582bbfd77134', }; var data2 = { dni: '98765', name: 'Danielito', last_name: 'Rodriguez', email: 'danirodriguez@gmail.com', phone: 84664515, password: '1203', user_type: '2', status: '4', community_id: '62be68215692582bbfd77134', }; console.log(data2); fetch('http://localhost:4000/user/createGuard', { cache: 'no-cache', method: 'POST', mode: 'cors', body: JSON.stringify(data2), headers: { 'Content-Type': 'application/json', }, }) .then(function (response) { if (response.status != 201) console.log('Ocurrió un error con el servicio: ' + response.status); else return response.json(); }) .then(function (response) { fetchP(); }) .catch((err) => console.log('Ocurrió un error con el fetch', err)); } return (