"use client"; import toast from "react-hot-toast"; import { useState } from "react"; import { PostReceipt } from "@/app/lib/postReceipt"; import { useRouter } from "next/navigation"; import "./Receipt.css"; interface ReceiptsProps { numAcount: number | null; } function Receipt({ numAcount }: ReceiptsProps) { const router = useRouter(); const [folio, setFolio] = useState(""); const [amount, setAmount] = useState(""); const [date, setDate] = 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 = async () => { if (!numAcount) { toast.error("busca de nuevo al estudiante"); return; } if (!folio) { toast.error("Ingresa el folio del ticket"); return; } if (!amount) { toast.error("Coloca el monto a depositar"); return; } if (!date) { toast.error("Coloca la fecha"); return; } try { await PostReceipt({ id_cuenta: numAcount, folio_recibo: folio, monto: Number(amount), fecha_recibo: date, }); setFolio(""); setAmount(""); setDate(""); toast.success("Recibo guardado"); router.refresh(); } catch (err: any) { toast.error(String(err)); } }; return (
); } export default Receipt; //IO