111 lines
3.1 KiB
TypeScript
111 lines
3.1 KiB
TypeScript
"use client";
|
|
|
|
import "./landing/globals.css";
|
|
import Header from "./landing/new_header";
|
|
import Footer from "@/components/layout/footer";
|
|
import LandingBody from "./landing/landing_body";
|
|
import Dashboard from "./carga/page";
|
|
import Consulta from "./visualizacion/page";
|
|
import LoginPage from "@/containers/LoginPage";
|
|
import FormularioCargaIndividual from "./alta/alta";
|
|
import { useSession } from "@/hooks/use-session";
|
|
import { useEffect, useState } from "react";
|
|
import path from "path";
|
|
import { motion } from "framer-motion";
|
|
|
|
export type PageKey = "landing" | "login" | "carga" | "consulta" | "carga individual";
|
|
|
|
export interface HeaderItem {
|
|
label: string;
|
|
page?: PageKey;
|
|
onClick?: () => void;
|
|
}
|
|
|
|
const Home = () => {
|
|
const [page, setPage] = useState<PageKey>("landing");
|
|
const { data: user, loading } = useSession(); // usuario viene de useSession()
|
|
const [isCarga, setIsCarga] = useState("Carga");
|
|
const [saludo, setSaludo] = useState("");
|
|
|
|
useEffect(() => {
|
|
const origen = user?.tipo;
|
|
|
|
if (origen === "LOAD") {
|
|
setSaludo("Bienvenido al módulo de carga de datos");
|
|
} else if (origen === "RED") {
|
|
setSaludo("Bienvenido usuario de red");
|
|
} else if (origen === "AT") {
|
|
setSaludo("Bienvenido usuario de AT");
|
|
} else if (origen === "CORREO") {
|
|
setSaludo("Bienvenido usuario de correo");
|
|
} else if (origen === "SOLICITA") {
|
|
setSaludo("Bienvenido usuario de préstamos PC Puma");
|
|
}
|
|
}, [user]);
|
|
|
|
useEffect(() => {
|
|
if (user?.tipo === "LOAD") {
|
|
setIsCarga("Carga");
|
|
} else {
|
|
setIsCarga("Descarga");
|
|
}
|
|
}, [user]);
|
|
|
|
const handleLogout = () => {
|
|
localStorage.removeItem("token");
|
|
location.reload();
|
|
};
|
|
|
|
const items: HeaderItem[] = user
|
|
? [
|
|
{ label: "Inicio", page: "landing" },
|
|
{ label: "Consulta", page: "consulta" },
|
|
{ label: isCarga, page: "carga" },
|
|
...(user.tipo === "LOAD"
|
|
? [
|
|
{ label: "Carga individual", page: "carga individual" as PageKey },
|
|
]
|
|
: []),
|
|
{ label: "Cerrar sesión", onClick: handleLogout },
|
|
]
|
|
: [
|
|
{ label: "Consulta", page: "consulta" },
|
|
{ label: "Inicio", page: "landing" },
|
|
{ label: "Login", page: "login" },
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<Header items={items} onClickItem={setPage} />
|
|
|
|
{/* Saludo en la esquina superior derecha */}
|
|
{saludo && (
|
|
<motion.div
|
|
className="w-full flex justify-end pr-6 mb-5"
|
|
initial={{ x: -100, opacity: 0 }}
|
|
animate={{ x: 0, opacity: 1 }}
|
|
transition={{ duration: 1.5, ease: "easeOut" }}
|
|
>
|
|
<h2 className="text-dorado text-sm text-right">{saludo}</h2>
|
|
</motion.div>
|
|
|
|
|
|
)}
|
|
|
|
<div className="flex-grow-1 d-flex flex-column align-items-center justify-content-center text-center">
|
|
{page === "landing" && <LandingBody />}
|
|
{page === "login" && <LoginPage />}
|
|
{page === "consulta" && <Consulta />}
|
|
{page === "carga" && <Dashboard />}
|
|
{page === "carga individual" && user?.tipo === "LOAD" && (
|
|
<FormularioCargaIndividual />
|
|
)}
|
|
</div>
|
|
|
|
<Footer />
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Home;
|