diff --git a/app/(private)/BitacoraSanciones/page.tsx b/app/(private)/BitacoraSanciones/page.tsx index d82577f..66b5906 100644 --- a/app/(private)/BitacoraSanciones/page.tsx +++ b/app/(private)/BitacoraSanciones/page.tsx @@ -6,8 +6,14 @@ import Toggle from "@/app/Components/Toggle/Toggle"; import SearchDate from "@/app/Components/SearchDate/SearchDate"; import Information from "@/app/Components/Information/information"; import SearchUser from "@/app/Components/SearchUser/searchUser"; +import { GetStudent } from "@/app/lib/getStudent"; + +export default function Page({ searchParams }: any) { + const params = searchParams; + + let student: any = null; + let error: string | null = null; -export default function Page() { const [usuario_sanciones] = useState([ { no_cuenta: "425530275 ", @@ -166,8 +172,26 @@ export default function Page() { label: "Sanciones", content: ( <> - + + + +
+ + +
+ + +
+
@@ -180,22 +204,6 @@ export default function Page() { - - - -
- - -
- {usuario_sanciones.map((sancion, index) => ( diff --git a/app/(private)/Impresiones/page.tsx b/app/(private)/Impresiones/page.tsx index 01bf9e3..b72beac 100644 --- a/app/(private)/Impresiones/page.tsx +++ b/app/(private)/Impresiones/page.tsx @@ -4,12 +4,12 @@ import Impressions from "../../Components/Impressions/impressions"; import Toggle from "../../Components/Toggle/Toggle"; import Information from "../../Components/Information/information"; -import "@/app/globals.css"; -import { GetStudent } from "@/app/lib/getStudent"; import AlertBox from "@/app/Components/AlertBox/AlertBox"; +import { GetStudent } from "@/app/lib/getStudent"; +import "@/app/globals.css"; export default async function Page({ searchParams }: any) { - const params = await searchParams; + const params = await searchParams; const numAccount = params.numAccount ? Number(params.numAccount) : null; let student: any = null; @@ -26,7 +26,7 @@ export default async function Page({ searchParams }: any) { return (
- {error && } + {error && }

IMPRESIONES Y PLOTEO

@@ -46,7 +46,7 @@ export default async function Page({ searchParams }: any) { { key: "1", label: "Recibo", - content: , + content: , }, { key: "2", diff --git a/app/(private)/Inscripciones/page.tsx b/app/(private)/Inscripciones/page.tsx index 657ce35..da37631 100644 --- a/app/(private)/Inscripciones/page.tsx +++ b/app/(private)/Inscripciones/page.tsx @@ -1,4 +1,3 @@ -"use client"; import "./inscriptions.css"; import SearchUser from "@/app/Components/SearchUser/searchUser"; @@ -6,25 +5,47 @@ import Information from "@/app/Components/Information/information"; import StepNavigator from "@/app/Components/StepNavigator/StepNavigator"; import Receipt from "@/app/Components/Receipt/Receipt"; import Selection from "@/app/Components/Selection/Selection"; +import { GetStudent } from "@/app/lib/getStudent"; + +export default async function Page({ searchParams }: any) { + const params = await searchParams; + const numAccount = params.numAccount ? Number(params.numAccount) : null; + + let student: any = null; + let error: string | null = null; + if (numAccount) { + const result = await GetStudent(numAccount); + + if (result.error) { + error = result.error; + } else { + student = result; + } + } -export default function Page() { return (

INSCRIPCION

- + - + {student ? ( + <> + - console.log()}> - - - + + + + + + ) : ( + <> + )}
); } diff --git a/app/(private)/QuitarSancion/page.tsx b/app/(private)/QuitarSancion/page.tsx index 129c7c2..c97c635 100644 --- a/app/(private)/QuitarSancion/page.tsx +++ b/app/(private)/QuitarSancion/page.tsx @@ -1,6 +1,6 @@ "use client"; import { useState } from "react"; -import styles from "./Page.module.css"; // importamos el css +import styles from "./Page.module.css"; import SearchUser from "@/app/Components/SearchUser/searchUser"; export default function Page() { @@ -17,7 +17,7 @@ export default function Page() { return (

Quitar Sanciones

- +
{sancion.no_cuenta}
diff --git a/app/Components/AlertBox/AlertBox.css b/app/Components/AlertBox/AlertBox.css index 84d2886..866d28f 100644 --- a/app/Components/AlertBox/AlertBox.css +++ b/app/Components/AlertBox/AlertBox.css @@ -1,7 +1,8 @@ .messageBox { + display: flex; position: absolute; padding: 0.5rem 1.25rem; - border-radius: 4px; + border-radius: 0 4px 4px 0; font-weight: bold; font-size: 1.5rem; text-align: center; @@ -10,13 +11,15 @@ top: 0; left: 0; width: 100%; - max-width: 200px; + max-height: min-content; + opacity: 0.9; + transition: opacity 0.5s ease, transform 0.5s ease; } .messageBox.hidden { opacity: 0; pointer-events: none; - transition: opacity 1s ease-out; + transition: opacity 1s ease-out,transform 0.5 ease; } .success { diff --git a/app/Components/BarNavigation/BarNavigation.css b/app/Components/BarNavigation/BarNavigation.css index 0c85b77..63c86ec 100644 --- a/app/Components/BarNavigation/BarNavigation.css +++ b/app/Components/BarNavigation/BarNavigation.css @@ -1,5 +1,4 @@ .barNavigation { - position: absolute; text-align: center; background-color: rgb(1, 92, 184); padding: 0 20px; diff --git a/app/Components/Impressions/impressions.tsx b/app/Components/Impressions/impressions.tsx index f680eaa..9f0baa5 100644 --- a/app/Components/Impressions/impressions.tsx +++ b/app/Components/Impressions/impressions.tsx @@ -1,12 +1,12 @@ "use client"; import { useState } from "react"; -import axios from "axios"; import { useRouter } from "next/navigation"; import Cookies from "js-cookie"; -import { envConfig } from "@/app/lib/config"; -import "./Impressions.css"; import AlertBox from "../AlertBox/AlertBox"; +import { PostImpressions } from "@/app/lib/postImpressions"; + +import "./Impressions.css"; interface CostOption { value: number; @@ -16,6 +16,7 @@ interface ImpressionsProps { costs: CostOption[]; numAccount: number | null; } + function Impressions({ costs, numAccount }: ImpressionsProps) { const [pages, setPages] = useState(""); const [cost, setCost] = useState(""); @@ -47,38 +48,20 @@ function Impressions({ costs, numAccount }: ImpressionsProps) { return; } - const token = Cookies.get("token"); - if (!token) { - handleLogout(); + const result = await PostImpressions({ + id_cuenta:numAccount, + numero_hojas : parseInt(pages), + monto: parseInt(cost) * parseInt(pages), + }); + + if (result.error) { + if (result.error === "Token inválido") handleLogout(); + else setError(result.error); return; } - try { - await axios.post( - `${envConfig.apiUrl}/impressions`, - { - numAccount: numAccount, - pages: parseInt(pages), - cost: parseInt(cost) * parseInt(pages), - }, - { - headers: { - Authorization: `Bearer ${token}`, - }, - } - ); - - setPages(""); - } catch (error: any) { - const errorMessage = - error.response?.data?.error || "No se encontró el estudiante"; - - if (errorMessage === "Token inválido") { - handleLogout(); - } - - setError(errorMessage); - } + setPages(""); + setCost("") }; return ( @@ -119,7 +102,7 @@ function Impressions({ costs, numAccount }: ImpressionsProps) {
- +
diff --git a/app/Components/Login/Login.tsx b/app/Components/Login/Login.tsx index 6cf63fc..c86b84d 100644 --- a/app/Components/Login/Login.tsx +++ b/app/Components/Login/Login.tsx @@ -4,11 +4,12 @@ import { loginUser } from "@/app/lib/login"; import { useRouter } from "next/navigation"; import "./Login.css"; +import AlertBox from "../AlertBox/AlertBox"; function Login() { const [user, setUser] = useState(""); const [password, setPassword] = useState(""); - const [message, setMessage] = useState(""); + const [error, setError] = useState(""); const router = useRouter(); @@ -18,10 +19,16 @@ function Login() { const data = await loginUser(user, password); if ("error" in data) { - setMessage(data.error); + setError(data.error); } else { - document.cookie = `token=${data.access_token}; path=/; SameSite=Strict`; - setMessage("Inicio de sesión exitoso"); + const token = data.access_token; + const payload = JSON.parse(atob(token.split(".")[1])); + const id_usuario = payload.id; + + document.cookie = `token=${token}; path=/; SameSite=Strict`; + document.cookie = `id_usuario=${id_usuario}; path=/; SameSite=Strict`; + + setError("Inicio de sesión exitoso"); router.push("/Impresiones"); } }; @@ -63,16 +70,7 @@ function Login() { Iniciar sesión - {message && ( -
- {message} -
- )} + {error && } ); diff --git a/app/Components/Receipt/Receipt.tsx b/app/Components/Receipt/Receipt.tsx index 817af7c..ba453b5 100644 --- a/app/Components/Receipt/Receipt.tsx +++ b/app/Components/Receipt/Receipt.tsx @@ -1,141 +1,133 @@ -'use client' -import { useEffect, useState } from "react"; -import "./Receipt.css" -import { PostReceipt } from "@/app/lib/receipt"; +"use client"; +import AlertBox from "../AlertBox/AlertBox"; +import { useState } from "react"; +import { PostReceipt } from "@/app/lib/postReceipt"; +import Cookies from "js-cookie"; -function Receipt() { - const [folio, setFolio] = useState(''); - const [amount, setAmount] = useState(''); - const [date, setDate] = useState(''); +import "./Receipt.css"; - const [error, setError] = useState(''); - const [alert, setAlert] = useState(''); - const [showError, setShowError] = useState(false); - const [showAlert, setShowAlert] = useState(false); - - //restrict this month// - const day = new Date(); - const year = day.getFullYear(); - const month = day.getMonth(); - const today = day.getDate(); - - const minFecha = new Date(year, month, 1).toISOString().split('T')[0]; - const maxFecha = new Date(year, month, today).toISOString().split('T')[0]; - //restrict this month// - - //fadeOut alert and error - useEffect(() => { - if (alert) { - setShowAlert(true); - const timeout = setTimeout(() => { - setShowAlert(false); - setTimeout(() => setAlert(''), 500); - }, 6000); - return () => clearTimeout(timeout); - } - }, [alert]); - - useEffect(() => { - if (error) { - setShowError(true); - const timeout = setTimeout(() => { - setShowError(false); - setTimeout(() => setError(''), 500); - }, 6000); - return () => clearTimeout(timeout); - } - }, [error]); - //fadeOut alert and error// - - const handleSaveReceipt = ( )=>{ - //PostReceipt(data{folio,amount,date}) - } - - return ( -
{ - e.preventDefault(); - handleSaveReceipt(); - }} - > - -
- - -
- - { - const value = e.target.value; - if (/^\d*$/.test(value)) { - setFolio(value); - } - }} - placeholder='Numero de folio...' - inputMode='numeric' - pattern='[0-9]*' - /> -
- -
- - { - const value = e.target.value; - - if (/^\d*\.?\d*$/.test(value)) { - const numericValue = parseFloat(value); - - if (value === '' || (numericValue <= 1000)) { - setAmount(value); - } else { - setAlert('') - setError('El monto no puede superar $1000.00') - } - } - }} - placeholder='Monto recibido...' - inputMode='numeric' - pattern="^\d*\.?\d+$" - /> -
- -
- - setDate(e.target.value)} - min={minFecha} - max={maxFecha} - /> -
- -
- - - {error && -
- {error} -
- } - {alert && -
- {alert} -
- } -
-
- - ) +interface ReceiptsProps { + numAccount: number | null; } -export default Receipt -//IO \ No newline at end of file +function Receipt({ numAccount }: ReceiptsProps) { + const [folio, setFolio] = useState(""); + const [amount, setAmount] = useState(""); + const [date, setDate] = useState(""); + + const [error, setError] = useState(""); + const [alert, setAlert] = useState(""); + + //restrict this month// + const day = new Date(); + const year = day.getFullYear(); + const month = day.getMonth(); + const today = day.getDate(); + + const minFecha = new Date(year, month, 1).toISOString().split("T")[0]; + const maxFecha = new Date(year, month, today).toISOString().split("T")[0]; + //restrict this month// + + const handleSaveReceipt = () => { + if (!numAccount) { + setError("Error busca denuevo al estudiante"); + return; + } + + if (!folio) { + setError("Ingresa el folio del tiket"); + return; + } + + if (!amount) { + setError("coloca el monto a depositar"); + return; + } + + if (!date) { + setError("coloca la fecha"); + return; + } + + PostReceipt({ + id_cuenta: numAccount, + folio_recibo: folio, + monto: Number(amount), + fecha_recibo: date, + }); + }; + + return ( +
{ + e.preventDefault(); + handleSaveReceipt(); + }} + > +
+
+ + { + const value = e.target.value; + if (/^\d*$/.test(value)) { + setFolio(value); + } + }} + placeholder="Numero de folio..." + inputMode="numeric" + pattern="[0-9]*" + /> +
+ +
+ + { + const value = e.target.value; + + if (/^\d*\.?\d*$/.test(value)) { + const numericValue = parseFloat(value); + + if (value === "" || numericValue <= 1000) { + setAmount(value); + } else { + setAlert(""); + setError("El monto no puede superar $1000.00"); + } + } + }} + placeholder="Monto recibido..." + inputMode="numeric" + pattern="^\d*\.?\d+$" + /> +
+ +
+ + setDate(e.target.value)} + min={minFecha} + max={maxFecha} + /> +
+ +
+ + + {error && } + {alert && } +
+
+ + ); +} + +export default Receipt; +//IO diff --git a/app/globals.css b/app/globals.css index 2e5efe7..49178fa 100644 --- a/app/globals.css +++ b/app/globals.css @@ -81,10 +81,10 @@ footer p { .mainContainer { position: relative; - display: flex; - flex-direction: column; + display: grid; + grid-template-rows: 40px 1fr; align-items: center; - justify-content: center; + justify-items: center; height: 100%; width: 100%; } @@ -439,6 +439,10 @@ table tr { justify-content: center; align-items: center; } + + footer p { + font-size: 1.2rem; +} } @media (max-height: 960px) { diff --git a/app/lib/apiClient.ts b/app/lib/apiClient.ts new file mode 100644 index 0000000..5fd0104 --- /dev/null +++ b/app/lib/apiClient.ts @@ -0,0 +1,23 @@ +import axios from "axios"; +import Cookies from "js-cookie"; +import { envConfig } from "./config"; + +const apiClient = axios.create({ + baseURL: envConfig.apiUrl, + headers: { + "Content-Type": "application/json", + }, +}); + +apiClient.interceptors.request.use((config) => { + const token = Cookies.get("token"); + console.log(token) + if (token) { + if (config.headers && "set" in config.headers) { + config.headers.set("Authorization", `Bearer ${token}`); + } + } + return config; +}); + +export default apiClient; diff --git a/app/lib/login.ts b/app/lib/login.ts index 680a445..b32f0db 100644 --- a/app/lib/login.ts +++ b/app/lib/login.ts @@ -2,14 +2,17 @@ import axios from "axios"; import { envConfig } from "./config"; export async function loginUser(usuario: string, password: string) { - try { - const response = await axios.post(`${envConfig.apiUrl}/user`, { usuario, password }); - return response.data; - } catch (error: any) { - const msg = - error.response?.data?.message || - error.message || - "Error desconocido en el login"; - return { error: msg }; - } + try { + const response = await axios.post(`${envConfig.apiUrl}/user`, { + usuario, + password, + }); + return response.data; + } catch (error: any) { + const msg = + error.response?.data?.message || + error.message || + "Error desconocido en el login"; + return { error: msg }; + } } diff --git a/app/lib/postImpressions.ts b/app/lib/postImpressions.ts new file mode 100644 index 0000000..5cc2a5c --- /dev/null +++ b/app/lib/postImpressions.ts @@ -0,0 +1,14 @@ +import apiClient from "@/app/lib/apiClient"; + +export async function PostImpressions(data: any) { + try { + const response = await apiClient.post("/operations/impressions", data); + return response.data; + } catch (error: any) { + const msg = + error.response?.data?.error || + error.message || + "Error desconocido al cobrar impresión"; + return { error: msg }; + } +} diff --git a/app/lib/postReceipt.ts b/app/lib/postReceipt.ts new file mode 100644 index 0000000..6c39e74 --- /dev/null +++ b/app/lib/postReceipt.ts @@ -0,0 +1,15 @@ +import apiClient from "./apiClient"; + +export async function PostReceipt(data: any) { + try { + const response = await apiClient.post("/operations/receipt", data); + console.log(response.data); + return response.data; + } catch (error: any) { + const msg = + error.response?.data?.message || + error.message || + "Error desconocido al crear recibo"; + return { error: msg }; + } +} diff --git a/app/lib/receipt.ts b/app/lib/receipt.ts deleted file mode 100644 index 6385567..0000000 --- a/app/lib/receipt.ts +++ /dev/null @@ -1,18 +0,0 @@ -import axios from "axios"; -import { envConfig } from "./config"; - -export async function PostReceipt(usuario: string, password: string) { - try { - const response = await axios.post(`${envConfig.apiUrl}/operations`, { - usuario, - password, - }); - return response.data; - } catch (error: any) { - const msg = - error.response?.data?.message || - error.message || - "Error desconocido en el guardado del Recibo"; - return { error: msg }; - } -} diff --git a/package.json b/package.json index e142761..3e66ed6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "next dev --turbopack", "build": "next build", - "start": "source ~/.nvm/nvm.sh && node --version && nvm use 22.10.0 && npm install && next build && next start -p 3356", + "start": "next start", "lint": "next lint" }, "dependencies": {