Skip to content

Commit 43f8cd0

Browse files
committed
depurando code
1 parent 7a65d2c commit 43f8cd0

12 files changed

+69
-112
lines changed
Loading
Loading

FrontEndReactJS/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
👉 npm i nextjs-toast-notify
1111
👉 https://www.npmjs.com/package/nextjs-toast-notify
1212
👉 https://www.nextjstoastnotify.com/
13+
👉 https://www.youtube.com/watch?v=mVY0iprskvQ
14+
15+
#### instalar la Librería loading-request para agregar un efecto Loading mientras se realiza una solicitud HTTP con Javascript
16+
👉 npm i loading-request
17+
👉 https://www.npmjs.com/package/loading-request
18+
👉 https://www.youtube.com/watch?v=1SHAlJYXvok&t=8s
1319

1420
#### Instalar la Librería react-data-table-component para mejorar la tabla con buscador y paginación.
1521

FrontEndReactJS/package-lock.json

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FrontEndReactJS/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"axios": "^1.6.7",
14+
"loading-request": "^2.2.0",
1415
"nextjs-toast-notify": "^1.27.0",
1516
"react": "^18.2.0",
1617
"react-data-table-component": "^7.6.2",

FrontEndReactJS/src/components/FormlarioEmpleado.jsx

+35-19
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { useForm } from "react-hook-form";
44

55
// importando la funcion toast Librería nextjs-toast-notify para las alertas
66
import { toast } from "nextjs-toast-notify";
7-
import VariablesDeEstados from "./VariablesDeEstados";
8-
import "../styles/loading.css";
7+
8+
// importando la Librería loading-request para agregar un efecto Loading mientras se realiza una solicitud HTTP con Javascript
9+
import { showLoading, hideLoading } from "loading-request";
910

1011
import SelectEdad from "./SelectEdad";
1112
import SelectCargoEmpleado from "./SelectCargoEmpleado";
12-
import Loading from "./Loading";
1313

1414
const FormlarioEmpleado = ({
1515
URL_API,
@@ -19,8 +19,6 @@ const FormlarioEmpleado = ({
1919
dataEditarEmpleado,
2020
avatarUrl,
2121
}) => {
22-
const { loading, setLoading } = VariablesDeEstados();
23-
2422
const {
2523
register,
2624
handleSubmit,
@@ -41,7 +39,13 @@ const FormlarioEmpleado = ({
4139
: "";
4240

4341
const customHandleSubmit = async (data) => {
44-
setLoading(true);
42+
// Agregando función showLoading para inabilitar la pantalla mientras se realiza la petición HTTP
43+
showLoading({
44+
message: "Enviando información...",
45+
spinnerColor: "#8201ff",
46+
textLoadingColor: "#8201ff",
47+
textLoadingSize: "20px",
48+
});
4549

4650
const formData = new FormData();
4751
formData.append("nombre", data.nombre);
@@ -59,22 +63,35 @@ const FormlarioEmpleado = ({
5963
},
6064
});
6165

62-
// Simulamos un envío de formulario asíncrono
63-
setTimeout(() => {
64-
setLoading(false);
65-
}, 1000);
66+
//setLoading(false);
67+
toast.success("Empleado agregado correctamente", {
68+
duration: 4000,
69+
progress: true,
70+
position: "top-right",
71+
transition: "swingInverted",
72+
icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-check"><path d="M20 6 9 17l-5-5"/></svg>',
73+
sonido: true,
74+
});
6675

67-
toast.success("Empleado agregado correctamente");
6876
// Consulto la API para obtener la lista de empleados actualizada y actualizo la lista de empleados
6977
const empleadosData = await obtenerEmpleados();
7078
setEmpleados(empleadosData);
7179
} catch (error) {
7280
console.error("Error al agregar empleado:", error);
81+
} finally {
82+
// Agregando función hideLoading para habilitar la pantalla
83+
hideLoading({ timeLoading: 1500 });
7384
}
7485
};
7586

7687
const handleSubmitUpdateForm = async (data) => {
77-
setLoading(true);
88+
showLoading({
89+
message: "eliminando el empleado...",
90+
spinnerColor: "#8201ff",
91+
textLoadingColor: "#8201ff",
92+
textLoadingSize: "20px",
93+
});
94+
7895
/**
7996
* IMPORTANTE: para enviar el formulario por el metodo put, se debe enmascarar(engañar) el tipo de solicitud, diciendo con axios que la solicitud
8097
* es de tipo POST, pero en realidad es de tipo PUT ya que esta agregando formData.append("_method", "PUT"); y esto define el metodo de envio.
@@ -105,18 +122,19 @@ const FormlarioEmpleado = ({
105122
"Content-Type": "multipart/form-data",
106123
},
107124
});
108-
// Simulamos un envío de formulario asíncrono
109-
setTimeout(() => {
110-
setLoading(false);
111-
}, 1000);
112125

113-
toast.success("Empleado actualizado correctamente");
126+
toast.success("Empleado actualizado correctamente", {
127+
transition: "bounceIn",
128+
sonido: true,
129+
});
114130
// Consulto la API para obtener la lista de empleados actualizada y actualizo la lista de empleados
115131
const empleadosData = await obtenerEmpleados();
116132
setEmpleados(empleadosData);
117133
volverAlHomeDesdeEditar();
118134
} catch (error) {
119135
console.error("Error al actualizar el empleado:", error);
136+
} finally {
137+
hideLoading({ timeLoading: 1000 });
120138
}
121139
};
122140

@@ -265,8 +283,6 @@ const FormlarioEmpleado = ({
265283
</button>
266284
</div>
267285
</form>
268-
269-
{loading && <Loading />}
270286
</>
271287
);
272288
};

FrontEndReactJS/src/components/HomePage.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import FormlarioEmpleado from "./FormlarioEmpleado";
22
import ListaEmpleados from "./ListaEmpleados";
33
import VariablesDeEstados from "./VariablesDeEstados";
44

5-
// importando Librería para las alertas
5+
// Importando nextjs-toast-notify.css para las alertas, forma parte del paquete nextjs-toast-notify
66
import "nextjs-toast-notify/dist/nextjs-toast-notify.css";
7+
// Importando index.css para agregar un efecto Loading mientras se realiza una solicitud HTTP con Javascript
8+
import "loading-request/dist/index.css";
79

810
const URL_API = "http://127.0.0.1:8500/api/empleados";
911
const avatarUrl = "http://127.0.0.1:8500/avatars/";

FrontEndReactJS/src/components/ListaEmpleados.jsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { useEffect } from "react";
66
// importando la funcion toast Librería nextjs-toast-notify para las alertas
77
import { toast } from "nextjs-toast-notify";
88

9+
// importando la Librería loading-request para agregar un efecto Loading mientras se realiza una solicitud HTTP con Javascript
10+
import { showLoading, hideLoading } from "loading-request";
11+
912
import DetallesEmpleado from "./DetallesEmpleado";
1013
import TablaEmpleado from "./TablaEmpleado";
1114

@@ -37,15 +40,28 @@ const ListaEmpleados = ({
3740
* Función para eliminar un empleado
3841
*/
3942
const eliminarEmpleado = async (idEmpleado) => {
43+
// Agregando función showLoading para inabilitar la pantalla mientras se realiza la petición HTTP
44+
showLoading({
45+
message: "eliminando el empleado...",
46+
spinnerColor: "#8201ff",
47+
textLoadingColor: "#8201ff",
48+
textLoadingSize: "20px",
49+
});
50+
4051
try {
4152
await axios.delete(`${URL_API}/${idEmpleado}`);
4253
const nuevaListaEmpleados = empleados.filter(
4354
(empleado) => empleado.id !== idEmpleado
4455
);
45-
toast.success("Empleado eliminado correctamente");
56+
toast.success("Empleado eliminado correctamente", {
57+
sonido: true,
58+
});
4659
setEmpleados(nuevaListaEmpleados);
4760
} catch (error) {
4861
console.error("Error al eliminar el empleado:", error);
62+
} finally {
63+
// Agregando función hideLoading para habilitar la pantalla
64+
hideLoading({ timeLoading: 1000 });
4965
}
5066
};
5167

FrontEndReactJS/src/components/Loading.jsx

-14
This file was deleted.

FrontEndReactJS/src/components/VariablesDeEstados.jsx

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useState } from "react";
22
const VariablesDeEstados = () => {
3-
const [loading, setLoading] = useState(false); // Para manejar el estado de carga cuando se enviar el formulario
43
const [mostrarDetallesEmpleado, setMostarDetallesEmpleado] = useState(false); // Para manejar el estado del detalles del empleado
54
const [dataInformacionEmpleado, setDataInformacionEmpleado] = useState({}); // Almacenar informacion del empleado cuando se observa detalles del mismo
65
const [dataEditarEmpleado, setDataEditarEmpleado] = useState({}); // Almacenar informacion del empleado para editar
@@ -9,8 +8,6 @@ const VariablesDeEstados = () => {
98
const [empleados, setEmpleados] = useState([]); // Para almacenar la lista de empleados
109

1110
return {
12-
loading,
13-
setLoading,
1411
empleados,
1512
setEmpleados,
1613
mostrarDetallesEmpleado,

FrontEndReactJS/src/styles/loading.css

-74
This file was deleted.

0 commit comments

Comments
 (0)