Compare commits

...

4 Commits

Author SHA1 Message Date
Traym17 425119ce9c Cambio de tipo
Cambio en un atributo del tipo de usuario
2022-07-13 23:12:11 -06:00
Traym17 25d2edb726 Listar y registrar completos
El registro y el listar de los administradores del sistema listo
2022-07-13 23:01:27 -06:00
Traym17 de2418cc52 Registro correcto
Buen funcionamiento del registro del admin del sistema
2022-07-12 23:15:34 -06:00
Traym17 9804bd2842 Pruebas del fetch 2022-07-12 20:16:42 -06:00
2 changed files with 49 additions and 14 deletions

View File

@ -162,7 +162,7 @@ const App = () => {
label: 'Home', label: 'Home',
items: [ items: [
{label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/'}, {label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/'},
{label: 'Registro admin sistema', icon: 'pi pi-fw pi-id-card', to: '/formAdminSistema'} {label: 'Administradores del sistema', icon: 'pi pi-fw pi-id-card', to: '/formAdminSistema'}
] ]
}, },
{ {

View File

@ -1,21 +1,42 @@
import React, { useState } from 'react'; import React, { useEffect, useState } from 'react';
import { InputText } from 'primereact/inputtext'; import { InputText } from 'primereact/inputtext';
import { Button } from 'primereact/button'; import { Button } from 'primereact/button';
import { DataTable } from 'primereact/datatable';
import { Column } from 'primereact/column';
import { CustomerService } from '../service/CustomerService';
const FormAdminSistema = () => { const FormAdminSistema = () => {
const [pokemones,setPokemones]=useState([]);
const [urlFetch,setUrlFetch]=useState('http://localhost:4000/user/allUsers');
async function fetchP(){
let nombres=await fetch(urlFetch, {method:'GET'});
let pokemonesRes= await nombres.json();
setPokemones(pokemonesRes.message);
console.log(pokemones);
}
useEffect(()=>{
fetchP();
},[])
function registrarAdmin() { function registrarAdmin() {
var data = { var data = {
dni: "12687", dni: document.getElementById('identificacion').value,
name: "hola", name: document.getElementById('nombre').value,
last_name: "buuu", last_name: document.getElementById('apellidos').value,
email: "tmora4c@ucenfotec.ac.cr", email: document.getElementById('correo_electronico').value,
phone: 84664515, phone: document.getElementById('telefono').value,
password: "1203", password: document.getElementById('correo_electronico').value,
user_type: "1", user_type: "1", //1 es admin
status: "2" status: "1"
}; };
console.log(data); // console.log(data);
fetch('http://localhost:4000/user/createAdminSystem/', { fetch('http://localhost:4000/user/createAdminSystem/', {
cache: 'no-cache', cache: 'no-cache',
method: 'POST', method: 'POST',
@ -26,7 +47,7 @@ const FormAdminSistema = () => {
}) })
.then( .then(
function (response) { function (response) {
if (response.status != 200) if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status); console.log('Ocurrió un error con el servicio: ' + response.status);
else else
return response.json(); return response.json();
@ -34,7 +55,7 @@ const FormAdminSistema = () => {
) )
.then( .then(
function (response) { function (response) {
console.log(response); fetchP();
} }
) )
.catch( .catch(
@ -44,6 +65,18 @@ const FormAdminSistema = () => {
return ( return (
<div className="grid"> <div className="grid">
<div className="col-12">
<div className="card">
<h5>Administradores del sistema</h5>
<DataTable value={pokemones} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="last_name" header="Apellidos" style={{ flexGrow: 1, flexBasis: '160px' }} alignFrozen="left"></Column>
<Column field="dni" header="Identificación" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="email" header="Correo electrónico" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
<Column field="phone" header="Telefóno" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
</DataTable>
</div>
</div>
<div className="col-12"> <div className="col-12">
<div className="card"> <div className="card">
<h5>Registro de un administrador del sistema</h5> <h5>Registro de un administrador del sistema</h5>
@ -66,13 +99,15 @@ const FormAdminSistema = () => {
</div> </div>
<div className="field col-12"> <div className="field col-12">
<label htmlFor="telefono">Teléfono</label> <label htmlFor="telefono">Teléfono</label>
<InputText id="telefono" type="text" rows="4" /> <InputText id="telefono" type="number" rows="4" />
</div> </div>
<Button label="Registrar" onClick={registrarAdmin}></Button> <Button label="Registrar" onClick={registrarAdmin}></Button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
) )
} }