diff --git a/app/Components/Alta/registerAlta.css b/app/Components/Alta/registerAlta.css index 20e1fdd..f81c1d8 100644 --- a/app/Components/Alta/registerAlta.css +++ b/app/Components/Alta/registerAlta.css @@ -12,12 +12,6 @@ background-color: #001f5c; } -button:disabled { - background-color: #bfc6d1; - cursor: not-allowed; - opacity: 0.7; -} - .altaContainerButton{ display: flex; width: 100%; diff --git a/app/Components/Receipt/Inscripcion.tsx b/app/Components/Receipt/Inscripcion.tsx index b585412..dbafcb2 100644 --- a/app/Components/Receipt/Inscripcion.tsx +++ b/app/Components/Receipt/Inscripcion.tsx @@ -7,13 +7,28 @@ import { useRouter } from "next/navigation"; import "./Receipt.css"; import Selection from "../Selection/Selection"; +import { envConfig } from "@/app/lib/config"; interface ReceiptsProps { numAcount: number | null; plataformasInscritas: string[]; } -export default function Inscripcion({ numAcount, plataformasInscritas }: ReceiptsProps) { +const PLATAFORMA_MAP: Record = { + WINDOWS: 1, + MACINTOSH: 2, + PROFESORES: 5, +}; + +export default function Inscripcion({ + numAcount, + plataformasInscritas, +}: ReceiptsProps) { + const [conPago, setConPago] = useState<"con" | "sin">("con"); + const [plataformaSeleccionada, setPlataformaSeleccionada] = useState< + string | null + >(null); + const router = useRouter(); const [folio, setFolio] = useState(""); @@ -70,85 +85,130 @@ export default function Inscripcion({ numAcount, plataformasInscritas }: Receipt } }; + const handleInscripcionSinPago = async () => { + if (!numAcount) { + toast.error("busca de nuevo al estudiante"); + return; + } + + if (!plataformaSeleccionada) { + toast.error("Selecciona una plataforma"); + return; + } + + const id_plataforma = PLATAFORMA_MAP[plataformaSeleccionada]; + + try { + const res = await fetch(`${envConfig.apiUrl}/alumno-inscrito`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + id_cuenta: numAcount, + id_plataforma, + realizo_pago: false, + }), + }); + + const data = await res.json(); + + if (!res.ok) { + throw new Error(data.message || "Error al inscribir"); + } + + toast.success("Alumno inscrito sin pago"); + router.refresh(); + } catch (err: any) { + toast.error(err.message); + } + }; + return (
- + -
{ - e.preventDefault(); - handleSaveReceipt(); - }} - > -
-
- - { - const value = error.target.value; - if (/^\d*$/.test(value) && value.length <= 7) { - setFolio(value); - } - }} - placeholder="Numero de tiket..." - 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 { - toast.error("El monto no puede superar $1000.00"); + {conPago === "con" && ( + { + e.preventDefault(); + handleSaveReceipt(); + }} + > +
+
+ + { + const value = e.target.value; + if (/^\d*$/.test(value) && value.length <= 7) { + setFolio(value); } - } - }} - placeholder="Monto recibido..." - inputMode="numeric" - pattern="^\d*\.?\d+$" - /> -
+ }} + /> +
-
- - setDate(e.target.value)} - min={minFecha} - max={maxFecha} - /> -
+
+ + { + const value = e.target.value; + if (/^\d*\.?\d*$/.test(value)) { + const numericValue = parseFloat(value); + if (value === "" || numericValue <= 1000) { + setAmount(value); + } + } + }} + /> +
-
- +
+ + setDate(e.target.value)} + min={minFecha} + max={maxFecha} + /> +
+ +
+ +
+ + )} + {conPago === "sin" && ( +
+
- + )}
); } diff --git a/app/Components/Selection/Selection.tsx b/app/Components/Selection/Selection.tsx index 27f7aff..27630bc 100644 --- a/app/Components/Selection/Selection.tsx +++ b/app/Components/Selection/Selection.tsx @@ -5,11 +5,18 @@ import "./Selection.css"; function Selection({ plataformasInscritas = [], + onSelect, }: { plataformasInscritas: string[]; + onSelect: (plataforma: string | null) => void; }) { const [selected, setSelected] = useState(null); + const handleSelect = (optionName: string) => { + const value = selected === optionName ? null : optionName; + setSelected(value); + onSelect(value); + }; const options = [ { name: "WINDOWS", @@ -25,10 +32,6 @@ function Selection({ }, ]; - const handleSelect = (optionName: string) => { - setSelected(selected === optionName ? null : optionName); - }; - const opcionesDisponibles = options.filter( (option) => !plataformasInscritas.includes(option.name), ); diff --git a/app/globals.css b/app/globals.css index a57e817..73a342d 100644 --- a/app/globals.css +++ b/app/globals.css @@ -247,6 +247,12 @@ button { height: 3.5rem; } +button:disabled { + background-color: #bfc6d1; + cursor: not-allowed; + opacity: 0.7; +} + .groupInput { display: flex; flex-wrap: wrap;