diff --git a/app/(private)/ActivosMantenimiento/page.tsx b/app/(private)/ActivosMantenimiento/page.tsx index 2f0136d..9656692 100644 --- a/app/(private)/ActivosMantenimiento/page.tsx +++ b/app/(private)/ActivosMantenimiento/page.tsx @@ -1,8 +1,6 @@ import Areas from "@/app/Components/ActivosMantenimiento/Areas"; import Mesas from "@/app/Components/ActivosMantenimiento/Mesas"; import Equipos from "@/app/Components/Equipos/equipos"; -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; import SearchUser from "@/app/Components/Global/SearchUser/searchUser"; import Toggle from "@/app/Components/Global/Toggle/Toggle"; @@ -10,30 +8,13 @@ export default async function Page(props: { searchParams?: Promise<{ numAcount?: string; machine?: string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const numAcount = params?.numAcount ? params.numAcount : null; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; return (
- {showError && ( - <> - - - - )} - - {showSuccess && ( - <> - - - - )}

EQUIPOS ACTIVOS Y EN MANTENIMIENTO

diff --git a/app/(private)/AgregarTiempo/page.tsx b/app/(private)/AgregarTiempo/page.tsx index 723498d..3070b39 100644 --- a/app/(private)/AgregarTiempo/page.tsx +++ b/app/(private)/AgregarTiempo/page.tsx @@ -1,31 +1,27 @@ import SearchUser from "@/app/Components/Global/SearchUser/searchUser"; import Information from "@/app/Components/Global/Information/information"; import Receipt from "@/app/Components/Receipt/Receipt"; -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; +import toast from "react-hot-toast"; import { GetStudent } from "@/app/lib/getStudent"; import "./addTime.css"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; export default async function Page(props: { searchParams?: Promise<{ numAcount: string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const numAcount = params?.numAcount ? params.numAcount : null; - const showSuccess = params?.success ? params.success : null; - let showError = params?.error ? params.error : null; let student: any = null; if (numAcount) { const result = await GetStudent(parseInt(numAcount)); if (result.error) { - showError = "Alumno no encontrado"; + toast.error("Alumno no encontrado"); + return } else { student = result; } @@ -33,25 +29,12 @@ export default async function Page(props: { return (
- {showError && ( - <> - - - - )} - - {showSuccess && ( - <> - - - - )}

AGREGAR TIEMPO

- {student ? ( + {student && ( <> @@ -59,8 +42,6 @@ export default async function Page(props: { - ) : ( - <> )}
); diff --git a/app/(private)/Alta/page.tsx b/app/(private)/Alta/page.tsx index 2e51c0a..6f534c4 100644 --- a/app/(private)/Alta/page.tsx +++ b/app/(private)/Alta/page.tsx @@ -1,34 +1,14 @@ -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; import RegisterAlta from "@/app/Components/Alta/registerAlta"; import "./style.css"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; export default async function Page(props: { searchParams?: Promise<{ - success?: string; - error?: string; }>; }) { const params = await props.searchParams; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; - return (
- {showError && ( - <> - - - - )} - - {showSuccess && ( - <> - - - - )}

ALTA

diff --git a/app/(private)/AsignacionEquipo/page.tsx b/app/(private)/AsignacionEquipo/page.tsx index 51effbc..92cb5d2 100644 --- a/app/(private)/AsignacionEquipo/page.tsx +++ b/app/(private)/AsignacionEquipo/page.tsx @@ -1,5 +1,3 @@ -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; import SearchUser from "@/app/Components/Global/SearchUser/searchUser"; import Toggle from "@/app/Components/Global/Toggle/Toggle"; import { GetStudent } from "@/app/lib/getStudent"; @@ -11,15 +9,11 @@ export default async function Page(props: { searchParams?: Promise<{ numAcount?: string; machine?: string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const numAcount = params?.numAcount ? params.numAcount : null; const machine = params?.machine ? params.machine : null; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; let student: any = null; @@ -34,19 +28,7 @@ export default async function Page(props: { return (
- {showError && ( - <> - - - - )} - {showSuccess && ( - <> - - - - )}

ASIGNACION DE EQUIPOS

diff --git a/app/(private)/BitacoraSanciones/page.tsx b/app/(private)/BitacoraSanciones/page.tsx index cc6c2cd..02e5046 100644 --- a/app/(private)/BitacoraSanciones/page.tsx +++ b/app/(private)/BitacoraSanciones/page.tsx @@ -3,23 +3,17 @@ import BitacoraEquipo from "@/app/Components/BitacoraSanciones/BitacoraEquipo"; import BitacoraMesas from "@/app/Components/BitacoraSanciones/BitacoraMesas"; import Sanciones from "@/app/Components/BitacoraSanciones/Sanciones"; import Toggle from "@/app/Components/Global/Toggle/Toggle"; -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; import { GetStudent } from "@/app/lib/getStudent"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; export default async function Page(props: { searchParams?: Promise<{ key?: string; numAcount?: string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const key = params?.key && params.key ; const numAcount = params?.numAcount ? params.numAcount : null; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; let student: any = null; @@ -34,19 +28,6 @@ export default async function Page(props: { return (
- {showError && ( - <> - - - - )} - - {showSuccess && ( - <> - - - - )}

BITACORA Y SANCIONES

diff --git a/app/(private)/CambiarPass/page.tsx b/app/(private)/CambiarPass/page.tsx index 23da32e..c6388ad 100644 --- a/app/(private)/CambiarPass/page.tsx +++ b/app/(private)/CambiarPass/page.tsx @@ -1,32 +1,13 @@ import ChangePassword from "@/app/Components/auth/ChangePassword/changePassword"; -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; export default async function Page(props: { searchParams?: Promise<{ - success?: string; - error?: string; }>; }) { const params = await props.searchParams; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; return (
- {showError && ( - <> - - - - )} - - {showSuccess && ( - <> - - - - )}

Cambiar contraseña

diff --git a/app/(private)/Impresiones/page.tsx b/app/(private)/Impresiones/page.tsx index f78b77e..53494b1 100644 --- a/app/(private)/Impresiones/page.tsx +++ b/app/(private)/Impresiones/page.tsx @@ -2,33 +2,31 @@ import SearchUser from "../../Components/Global/SearchUser/searchUser"; import Receipt from "../../Components/Receipt/Receipt"; import Toggle from "../../Components/Global/Toggle/Toggle"; import Information from "../../Components/Global/Information/information"; -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; import Impressions from "@/app/Components/Impressions/impressions"; +import ShowError from "@/app/Components/Global/ShowError"; + import { GetStudent } from "@/app/lib/getStudent"; import "@/app/globals.css"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; export default async function Page(props: { searchParams?: Promise<{ key: string; numAcount: string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const key = params?.key && params.key; const numAcount = params?.numAcount ? params.numAcount : null; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; let student: any = null; + let errorMessage = ""; if (numAcount) { const result = await GetStudent(parseInt(numAcount)); if (result.error) { + errorMessage = `${result.error}`; } else { student = result; } @@ -36,19 +34,8 @@ export default async function Page(props: { return (
- {showError && ( - <> - - - - )} - {showSuccess && ( - <> - - - - )} + {errorMessage && }

IMPRESIONES Y PLOTEO

diff --git a/app/(private)/InformacionEquipo/page.tsx b/app/(private)/InformacionEquipo/page.tsx index e664473..8b62831 100644 --- a/app/(private)/InformacionEquipo/page.tsx +++ b/app/(private)/InformacionEquipo/page.tsx @@ -1,40 +1,21 @@ import Toggle from "@/app/Components/Global/Toggle/Toggle"; import Equipos from "@/app/Components/Equipos/equipos"; -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; import ProgramSelector from "@/app/Components/InformacionEquipos/ProgramSelector"; import "./informacionequipo.css"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; export default async function Page(props: { searchParams?: Promise<{ key?:string; machine?: string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const key = params?.key && params.key; const machine = params?.machine ? params.machine : null; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; return (
- {showError && ( - <> - - - - )} - - {showSuccess && ( - <> - - - - )}

INFORMACION DE EQUIPOS

diff --git a/app/(private)/Inscripcion/page.tsx b/app/(private)/Inscripcion/page.tsx index 96abb7f..3ebe703 100644 --- a/app/(private)/Inscripcion/page.tsx +++ b/app/(private)/Inscripcion/page.tsx @@ -2,30 +2,26 @@ import SearchUser from "@/app/Components/Global/SearchUser/searchUser"; import Information from "@/app/Components/Global/Information/information"; import Receipt from "@/app/Components/Receipt/Receipt"; import Selection from "@/app/Components/Selection/Selection"; -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; import { GetStudent } from "@/app/lib/getStudent"; import "./inscripcion.css"; +import ShowError from "@/app/Components/Global/ShowError"; export default async function Page(props: { searchParams?: Promise<{ numAcount: string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const numAcount = params?.numAcount ? params.numAcount : null; - const showSuccess = params?.success ? params.success : null; - let showError = params?.error ? params.error : null; let student: any = null; + let errorMessage = ""; if (numAcount) { const result = await GetStudent(parseInt(numAcount)); if (result.error) { - showError = "Alumno no encontrado"; + errorMessage = `${result.error}`; } else { student = result; } @@ -33,19 +29,8 @@ export default async function Page(props: { return (
- {showError && ( - <> - - - - )} - - {showSuccess && ( - <> - - - - )} + + {errorMessage && }

INSCRIPCIÓN

diff --git a/app/(private)/Inscritos/page.tsx b/app/(private)/Inscritos/page.tsx index 25d5e10..33e0605 100644 --- a/app/(private)/Inscritos/page.tsx +++ b/app/(private)/Inscritos/page.tsx @@ -1,33 +1,15 @@ -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; export default async function Page(props: { searchParams?: Promise<{ period: string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const period = params?.period ? params.period : null; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; return (
- {showError && ( - <> - - - - )} - {showSuccess && ( - <> - - - - )}

INSCRITOS

diff --git a/app/(private)/Mensajes/page.tsx b/app/(private)/Mensajes/page.tsx index eaeaf38..4531cf4 100644 --- a/app/(private)/Mensajes/page.tsx +++ b/app/(private)/Mensajes/page.tsx @@ -1,35 +1,16 @@ import EnviarMensaje from "@/app/Components/EviarMensaje/EnviarMensaje"; -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; import Toggle from "@/app/Components/Global/Toggle/Toggle"; export default async function Page(props: { searchParams?: Promise<{ key:string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const key = params?.key && params.key ; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; return (
- {showError && ( - <> - - - - )} - - {showSuccess && ( - <> - - - - )}

Enviar mensaje

diff --git a/app/(private)/Monitor/page.tsx b/app/(private)/Monitor/page.tsx index f228ed9..6712b5c 100644 --- a/app/(private)/Monitor/page.tsx +++ b/app/(private)/Monitor/page.tsx @@ -3,14 +3,10 @@ import styles from "./Page.module.css"; export default async function Page(props: { searchParams?: Promise<{ numAcount: string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const numAcount = params?.numAcount ? params.numAcount : null; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; return (
diff --git a/app/(private)/QuitarSancion/page.tsx b/app/(private)/QuitarSancion/page.tsx index 74d7ef3..bd1e1a5 100644 --- a/app/(private)/QuitarSancion/page.tsx +++ b/app/(private)/QuitarSancion/page.tsx @@ -4,14 +4,10 @@ import QuitarSancion from "@/app/Components/QuitarSancion/QuitarSancion"; export default async function Page(props: { searchParams?: Promise<{ numAcount: string; - success?: string; - error?: string; }>; }) { const params = await props.searchParams; const numAcount = params?.numAcount ? params.numAcount : null; - const showSuccess = params?.success ? params.success : null; - const showError = params?.error ? params.error : null; return ( <> diff --git a/app/Components/ActivosMantenimiento/Areas.tsx b/app/Components/ActivosMantenimiento/Areas.tsx index 9304175..9285ba2 100644 --- a/app/Components/ActivosMantenimiento/Areas.tsx +++ b/app/Components/ActivosMantenimiento/Areas.tsx @@ -9,7 +9,7 @@ export default function Areas() { const [mantenimiento, setMantenimiento] = useState(false); // Checkbox Mantenimiento const [mensaje, setMensaje] = useState(""); // Mensaje dinámico - const handleActualizar = (e: React.FormEvent) => { + const handleActualizar = (e: React.FormEvent) => { e.preventDefault(); if (!area) { diff --git a/app/Components/ActivosMantenimiento/Equipos.tsx b/app/Components/ActivosMantenimiento/Equipos.tsx index 9728709..53aa0e7 100644 --- a/app/Components/ActivosMantenimiento/Equipos.tsx +++ b/app/Components/ActivosMantenimiento/Equipos.tsx @@ -6,7 +6,7 @@ function Equipos() { const [tiempo, setTiempo] = useState(""); const [mensaje, setMensaje] = useState(""); - const handleBuscar = (e: React.FormEvent) => { + const handleBuscar = (e: React.FormEvent) => { e.preventDefault(); if (!cuenta) { setMensaje("Ingresa un número de cuenta antes de buscar"); @@ -15,7 +15,7 @@ function Equipos() { setMensaje(`Buscando información del No. de cuenta: ${cuenta}`); }; - const handleAsignar = (e: React.FormEvent) => { + const handleAsignar = (e: React.FormEvent) => { e.preventDefault(); if (!tiempo) { setMensaje("Selecciona un equipo antes de asignar"); diff --git a/app/Components/ActivosMantenimiento/Mesas.tsx b/app/Components/ActivosMantenimiento/Mesas.tsx index ff48be7..e37138c 100644 --- a/app/Components/ActivosMantenimiento/Mesas.tsx +++ b/app/Components/ActivosMantenimiento/Mesas.tsx @@ -8,7 +8,7 @@ function Mesas() { const [mantenimiento, setMantenimiento] = useState(false); // Checkbox Mantenimiento const [mensaje, setMensaje] = useState(""); // Mensaje dinámico - const handleConfirmar = (e: React.FormEvent) => { + const handleConfirmar = (e: React.FormEvent) => { e.preventDefault(); if (!mesa) { diff --git a/app/Components/EviarMensaje/EnviarMensaje.tsx b/app/Components/EviarMensaje/EnviarMensaje.tsx index 99aadfb..ac01900 100644 --- a/app/Components/EviarMensaje/EnviarMensaje.tsx +++ b/app/Components/EviarMensaje/EnviarMensaje.tsx @@ -12,7 +12,7 @@ const EnviarMensaje = ({ titulo, opciones }: EnviarMensajeProps) => { const [mensaje, setMensaje] = useState(""); const [customMsg, setCustomMsg] = useState(""); - const handleSubmit = (e: React.FormEvent) => { + const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); // Aquí puedes manejar el envío (guardar en estado global, enviar a backend, etc.) }; diff --git a/app/Components/Global/AlertBox/AlertBox.css b/app/Components/Global/AlertBox/AlertBox.css deleted file mode 100644 index cceac3f..0000000 --- a/app/Components/Global/AlertBox/AlertBox.css +++ /dev/null @@ -1,57 +0,0 @@ -@keyframes slideInLeft { - 0% { - opacity: 0; - transform: translateX(-100%); - } - 100% { - opacity: 0.9; - transform: translateX(0); - } -} - -@keyframes slideOutRight { - 0% { - opacity: 0.9; - transform: translateX(0); - } - 100% { - opacity: 0; - transform: translateX(100%); - } -} - -.messageBox { - display: flex; - position: absolute; - padding: 0.5rem 1.25rem; - border-radius: 0 4px 4px 0; - font-weight: bold; - font-size: 2rem; - text-align: center; - z-index: 100; - top: 0; - left: 0; - max-width: 500px; - max-height: min-content; - opacity: 0; -} - -.messageBox:not(.hidden) { - animation: slideInLeft 0.5s ease forwards; -} - -.messageBox.hidden { - animation: slideOutRight 0.5s ease forwards; -} - -.success { - background-color: #d1f7c4; - color: #000000; - border: 1px solid #a5d6a7; -} - -.error { - background-color: #ffcdd2; - color: #000000; - border: 1px solid #ef9a9a; -} diff --git a/app/Components/Global/AlertBox/AlertBox.tsx b/app/Components/Global/AlertBox/AlertBox.tsx deleted file mode 100644 index aa295e5..0000000 --- a/app/Components/Global/AlertBox/AlertBox.tsx +++ /dev/null @@ -1,42 +0,0 @@ -"use client"; - -import { useEffect, useState } from "react"; -import "./AlertBox.css"; -import ClearParams from "../ClearParams/ClearParams"; - -interface AlertBoxProps { - message: string | null; - type: "error" | "success"; - duration?: number; -} - -export default function AlertBox({ - message, - type, - duration = 6000, -}: AlertBoxProps) { - const [visible, setVisible] = useState(false); - const [text, setText] = useState(""); - - useEffect(() => { - if (message) { - setText(message); - setVisible(true); - - const timeout = setTimeout(() => { - setVisible(false); - setTimeout(() => setText(""), 500); - }, duration); - - return () => clearTimeout(timeout); - } - }, [message, duration]); - - if (!text) return null; - - return ( -
- {text} -
- ); -} diff --git a/app/Components/Global/ClearParams/ClearParams.tsx b/app/Components/Global/ClearParams/ClearParams.tsx deleted file mode 100644 index 7bf870c..0000000 --- a/app/Components/Global/ClearParams/ClearParams.tsx +++ /dev/null @@ -1,28 +0,0 @@ -"use client"; - -import { useEffect } from "react"; - -interface ClearParamsProps { - paramsToClear: string[]; -} - -export default function ClearParams({ paramsToClear }: ClearParamsProps) { - useEffect(() => { - if (typeof window === "undefined") return; - const url = new URL(window.location.href); - let changed = false; - - paramsToClear.forEach((param) => { - if (url.searchParams.has(param)) { - url.searchParams.delete(param); - changed = true; - } - }); - - if (changed) { - window.history.replaceState({}, "", url.toString()); - } - }, [paramsToClear]); - - return null; -} diff --git a/app/Components/Global/FormHandle.tsx b/app/Components/Global/FormHandle.tsx deleted file mode 100644 index 6f3d3c9..0000000 --- a/app/Components/Global/FormHandle.tsx +++ /dev/null @@ -1,40 +0,0 @@ -"use client"; - -import { ReactNode, useCallback } from "react"; -import { useRouter, usePathname, useSearchParams } from "next/navigation"; - -interface FormHandlerProps { - children: ReactNode; - onSubmit: () => Promise; -} - -export default function FormHandler({ children, onSubmit }: FormHandlerProps) { - const router = useRouter(); - const searchParams = useSearchParams(); - const pathname = usePathname(); - - const updateParams = useCallback( - (updates: Record) => { - const params = new URLSearchParams(searchParams.toString()); - - Object.entries(updates).forEach(([key, value]) => { - if (value === null) params.delete(key); - else params.set(key, value); - }); - - router.push(`${pathname}?${params.toString()}`); - }, - [searchParams, router, pathname] - ); - - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - try { - await onSubmit(); - } catch (err: any) { - updateParams({ error: String(err) }); - } - }; - - return {children}; -} diff --git a/app/Components/Global/SearchUser/searchUser.tsx b/app/Components/Global/SearchUser/searchUser.tsx index 8057454..9251b8e 100644 --- a/app/Components/Global/SearchUser/searchUser.tsx +++ b/app/Components/Global/SearchUser/searchUser.tsx @@ -19,11 +19,10 @@ function SearchUser(props: urlProp) { } }, [props.value]); - const handleSubmit = (e: React.FormEvent) => { + const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); const params = new URLSearchParams(searchParams.toString()); if (numAcount) { - params.delete("error"); params.set("numAcount", `${numAcount}`); router.push(`${pathname}?${params.toString()}`); } diff --git a/app/Components/Global/ShowError.tsx b/app/Components/Global/ShowError.tsx new file mode 100644 index 0000000..ef7140b --- /dev/null +++ b/app/Components/Global/ShowError.tsx @@ -0,0 +1,14 @@ +"use client"; + +import { useEffect } from "react"; +import toast from "react-hot-toast"; + +export default function ShowError({ message }: { message: string }) { + useEffect(() => { + if (message) { + toast.error(message); + } + }, [message]); + + return null; +} diff --git a/app/Components/Global/visual/GlobalAlert.tsx b/app/Components/Global/visual/GlobalAlert.tsx deleted file mode 100644 index a1518bf..0000000 --- a/app/Components/Global/visual/GlobalAlert.tsx +++ /dev/null @@ -1,36 +0,0 @@ -"use client"; - -import { useEffect, useState } from "react"; -import AlertBox from "@/app/Components/Global/AlertBox/AlertBox"; -import ClearParams from "@/app/Components/Global/ClearParams/ClearParams"; -import { useSearchParams } from "next/navigation"; - -export default function GlobalAlert() { - const searchParams = useSearchParams(); - const [showSuccess, setShowSuccess] = useState(null); - const [showError, setShowError] = useState(null); - - useEffect(() => { - const success = searchParams.get("success"); - const error = searchParams.get("error"); - - if (success) setShowSuccess(success); - if (error) setShowError(error); - }, []); - - return ( -
- {showError && ( - <> - - - )} - - {showSuccess && ( - <> - - - )} -
- ); -} diff --git a/app/Components/Impressions/impressions.tsx b/app/Components/Impressions/impressions.tsx index 018a35d..534f634 100644 --- a/app/Components/Impressions/impressions.tsx +++ b/app/Components/Impressions/impressions.tsx @@ -4,6 +4,7 @@ import Cookies from "js-cookie"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { PostImpressions } from "@/app/lib/postImpressions"; +import toast from "react-hot-toast"; interface CostOption { value: number; @@ -27,24 +28,19 @@ function Impressions({ costs, numAcount }: ImpressionsProps) { }; const handlePayment = async () => { - const currentUrl = new URL(window.location.href); - const params = new URLSearchParams(); - - const setError = (msg: string) => { - params.set("error", msg); - router.push(`${currentUrl}&${params.toString()}`); - }; - if (!numAcount) { - return setError("busca de nuevo al estudiante"); + toast.error("busca de nuevo al estudiante"); + return; } if (!pages) { - return setError("Ingresa el numero de hojas a imprimir"); + toast.error("Ingresa el numero de hojas a imprimir"); + return; } if (!cost) { - return setError("Selecciona un costo"); + toast.error("Selecciona un costo"); + return; } const result = await PostImpressions({ @@ -56,16 +52,15 @@ function Impressions({ costs, numAcount }: ImpressionsProps) { if (result.error) { if (result.error === "Token inválido") handleLogout(); else { - return setError(`Error: ${result.error}`); + toast.error(result.error); + return; } return; } setPages(""); setCost(""); - params.delete("error"); - params.set("success", "Impresion cobrada correctamente"); - router.push(`${currentUrl}&${params.toString()}`); + toast.success("Impresion cobrada correctamente"); }; return ( diff --git a/app/Components/Receipt/Receipt.tsx b/app/Components/Receipt/Receipt.tsx index 60efc9d..79b125d 100644 --- a/app/Components/Receipt/Receipt.tsx +++ b/app/Components/Receipt/Receipt.tsx @@ -1,5 +1,6 @@ "use client"; +import toast from "react-hot-toast"; import { useState } from "react"; import { PostReceipt } from "@/app/lib/postReceipt"; import { useRouter } from "next/navigation"; @@ -28,28 +29,25 @@ function Receipt({ numAcount }: ReceiptsProps) { //restrict this month// const handleSaveReceipt = async () => { - const currentUrl = new URL(window.location.href); - const params = new URLSearchParams(); - - const setError = (msg: string) => { - params.set("error", msg); - router.push(`${currentUrl}&${params.toString()}`); - }; if (!numAcount) { - return setError("busca de nuevo al estudiante"); + toast.error("busca de nuevo al estudiante"); + return; } if (!folio) { - return setError("Ingresa el folio del ticket"); + toast.error("Ingresa el folio del ticket"); + return; } if (!amount) { - return setError("Coloca el monto a depositar"); + toast.error("Coloca el monto a depositar"); + return; } if (!date) { - return setError("Coloca la fecha"); + toast.error("Coloca la fecha"); + return; } try { @@ -64,11 +62,9 @@ function Receipt({ numAcount }: ReceiptsProps) { setAmount(""); setDate(""); - params.delete("error"); - params.set("success", "Recibo guardado"); - router.push(`${currentUrl}&${params.toString()}`); + toast.success("Recibo guardado"); } catch (err: any) { - setError(String(err)); + toast.error(String(err)); } }; @@ -111,10 +107,7 @@ function Receipt({ numAcount }: ReceiptsProps) { if (value === "" || numericValue <= 1000) { setAmount(value); } else { - const currentUrl = new URL(window.location.href); - const params = new URLSearchParams(); - params.set("error", "El monto no puede superar $1000.00"); - router.push(`${currentUrl}&${params.toString()}`); + toast.error("El monto no puede superar $1000.00"); } } }} diff --git a/app/Components/SearchDateBetween/SearchDateBetween.tsx b/app/Components/SearchDateBetween/SearchDateBetween.tsx index 2cfb89b..38102bb 100644 --- a/app/Components/SearchDateBetween/SearchDateBetween.tsx +++ b/app/Components/SearchDateBetween/SearchDateBetween.tsx @@ -6,7 +6,7 @@ function SearchDateBetween() { const [startDate, setStartDate] = useState(""); const [endDate, setEndDate] = useState(""); - const handleSubmit = (e: React.FormEvent) => { + const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); console.log("Fecha inicio:", startDate); console.log("Fecha fin:", endDate); diff --git a/app/Components/auth/ChangePassword/changePassword.tsx b/app/Components/auth/ChangePassword/changePassword.tsx index c02db53..1a47db6 100644 --- a/app/Components/auth/ChangePassword/changePassword.tsx +++ b/app/Components/auth/ChangePassword/changePassword.tsx @@ -6,7 +6,7 @@ export default function ChangePassword() { const [newPass, setNewPass] = useState(""); const [confirmNewPass, setconfirmNewPass] = useState(""); - const handleChangePass = (e: React.FormEvent) => { + const handleChangePass = (e: React.FormEvent) => { e.preventDefault; const data = { pass, newPass, confirmNewPass }; console.log(data); diff --git a/app/Components/auth/Login/Login.tsx b/app/Components/auth/Login/Login.tsx index e5adf37..0e8fae2 100644 --- a/app/Components/auth/Login/Login.tsx +++ b/app/Components/auth/Login/Login.tsx @@ -3,24 +3,32 @@ import { useState } from "react"; import { loginUser } from "@/app/lib/login"; import { useRouter } from "next/navigation"; +import toast from "react-hot-toast"; import "./Login.css"; -import AlertBox from "../../Global/AlertBox/AlertBox"; function Login() { const [user, setUser] = useState(""); const [password, setPassword] = useState(""); - const [error, setError] = useState(""); - const [alert, setAlert] = useState(""); const router = useRouter(); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); + if (!user) { + toast.error("Coloca un usuario"); + return; + } + + if (!password) { + toast.error("Coloca una contraseña"); + return; + } + const data = await loginUser(user, password); if ("error" in data) { - setError(data.error); + toast.error(data.error); } else { const token = data.access_token; const payload = JSON.parse(atob(token.split(".")[1])); @@ -29,7 +37,7 @@ function Login() { document.cookie = `token=${token}; path=/; SameSite=Strict`; document.cookie = `usuario=${usuario}; path=/; SameSite=Strict`; - setAlert("Inicio de sesión exitoso"); + toast.success("Inicio de sesión exitoso"); router.push("/Impresiones"); } }; @@ -70,9 +78,6 @@ function Login() { > Iniciar sesión - - {error && } - {alert && }
); diff --git a/app/Components/layout/ToastProvider.tsx b/app/Components/layout/ToastProvider.tsx new file mode 100644 index 0000000..9cadd36 --- /dev/null +++ b/app/Components/layout/ToastProvider.tsx @@ -0,0 +1,44 @@ +"use client"; + +import { Toaster } from "react-hot-toast"; +import React from "react"; + +export function ToastProvider({ children }: { children: React.ReactNode }) { + return ( + <> + {children} + + + ); +} diff --git a/app/layout.tsx b/app/layout.tsx index b7a6f45..bb5e5fe 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -5,6 +5,7 @@ import Header from "./Components/layout/Header/Header"; import Footer from "./Components/layout/Footer/Footer"; import "./globals.css"; +import { ToastProvider } from "./Components/layout/ToastProvider"; const poppins = Poppins({ variable: "--font-poppins", @@ -27,9 +28,11 @@ export default function RootLayout({ return ( -
-
{children}
-