fixed problems and add AlertBox

This commit is contained in:
2025-09-17 19:42:13 -06:00
parent 7040865452
commit 10adca26af
14 changed files with 134 additions and 85 deletions
+32
View File
@@ -0,0 +1,32 @@
.messageBox {
position: absolute;
padding: 0.5rem 1.25rem;
border-radius: 4px;
font-weight: bold;
font-size: 1.5rem;
text-align: center;
opacity: 1;
z-index: 100;
top: 0;
left: 0;
width: 100%;
max-width: 200px;
}
.messageBox.hidden {
opacity: 0;
pointer-events: none;
transition: opacity 1s ease-out;
}
.success {
background-color: #d1f7c4;
color: #000000;
border: 1px solid #a5d6a7;
}
.error {
background-color: #ffcdd2;
color: #000000;
border: 1px solid #ef9a9a;
}
+37
View File
@@ -0,0 +1,37 @@
'use client'
import { useEffect, useState } from "react";
import "./AlertBox.css";
interface AlertBoxProps {
message: string;
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 (
<div className={`messageBox ${type} ${!visible ? "hidden" : ""}`}>
{text}
</div>
);
}
+5 -19
View File
@@ -6,6 +6,7 @@ import { useRouter } from "next/navigation";
import Cookies from "js-cookie";
import { envConfig } from "@/app/lib/config";
import "./Impressions.css";
import AlertBox from "../AlertBox/AlertBox";
interface CostOption {
value: number;
@@ -20,10 +21,6 @@ function Impressions({ costs, numAccount }: ImpressionsProps) {
const [cost, setCost] = useState("");
const [error, setError] = useState("");
const [alert, setAlert] = useState("");
const [showError, setShowError] = useState(false);
const [showAlert, setShowAlert] = useState(false);
const router = useRouter();
const handleLogout = () => {
@@ -33,7 +30,6 @@ function Impressions({ costs, numAccount }: ImpressionsProps) {
};
const handlePayment = async () => {
setAlert("");
setError("");
if (!numAccount) {
@@ -46,9 +42,9 @@ function Impressions({ costs, numAccount }: ImpressionsProps) {
return;
}
if(!cost){
setError("Selecciona un costo")
return;
if (!cost) {
setError("Selecciona un costo");
return;
}
const token = Cookies.get("token");
@@ -72,7 +68,6 @@ function Impressions({ costs, numAccount }: ImpressionsProps) {
}
);
setAlert("Cobro realizado correctamente");
setPages("");
} catch (error: any) {
const errorMessage =
@@ -132,16 +127,7 @@ function Impressions({ costs, numAccount }: ImpressionsProps) {
Cobrar
</button>
{error && (
<div className={`messageBox error ${!showError ? "hidden" : ""}`}>
{error}
</div>
)}
{alert && (
<div className={`messageBox success ${!showAlert ? "hidden" : ""}`}>
{alert}
</div>
)}
{error && <AlertBox message={error} type="error" />}
</div>
</div>
</form>
+8 -2
View File
@@ -2,14 +2,20 @@
import { useRouter } from "next/navigation";
import { useState } from "react";
function SearchUser() {
interface urlProp{
urlBase:string
}
function SearchUser(url:urlProp) {
const [numAccount, setNumAccount] = useState("");
const router = useRouter();
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (numAccount) {
router.push(`/Impresiones?numAccount=${numAccount}`);
router.push(`/${url.urlBase}?numAccount=${numAccount}`);
}
};