add new request and add .example
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
'use client'
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import './Impressions.css'
|
||||
import axios from "axios";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Cookies from "js-cookie";
|
||||
import { envConfig } from "@/app/lib/config";
|
||||
import "./Impressions.css";
|
||||
|
||||
interface CostOption {
|
||||
value: number;
|
||||
@@ -9,117 +13,140 @@ interface CostOption {
|
||||
|
||||
interface ImpressionsProps {
|
||||
costs: CostOption[];
|
||||
numAccount: number | null;
|
||||
}
|
||||
function Impressions({ costs }:ImpressionsProps) {
|
||||
const [pages, setPages] = useState("");
|
||||
const [cost, setCost] = useState("");
|
||||
function Impressions({ costs, numAccount }: ImpressionsProps) {
|
||||
const [pages, setPages] = useState("");
|
||||
const [cost, setCost] = useState("");
|
||||
|
||||
const [error, setError] = useState('');
|
||||
const [alert, setAlert] = useState('');
|
||||
const [showError, setShowError] = useState(false);
|
||||
const [showAlert, setShowAlert] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [alert, setAlert] = useState("");
|
||||
const [showError, setShowError] = useState(false);
|
||||
const [showAlert, setShowAlert] = useState(false);
|
||||
|
||||
// const handlePayment = async () => {
|
||||
// setAlert('')
|
||||
// setError('')
|
||||
// if (!studentData) {
|
||||
// setError('Error busca denuevo al estudiante');
|
||||
// return;
|
||||
// }
|
||||
// if (!pages) {
|
||||
// setError('Ingresa el numero de hojas a imprimir')
|
||||
// return;
|
||||
// }
|
||||
// try {
|
||||
// await axios.post(
|
||||
// `${url}/impressions`,
|
||||
// {
|
||||
// numAccount: numAccount,
|
||||
// pages: parseInt(pages),
|
||||
// cost: parseInt(pages),
|
||||
// },
|
||||
// { headers }
|
||||
// );
|
||||
// handleSearch()
|
||||
// setAlert('Cobro realizado correctamente');
|
||||
// setPages('')
|
||||
// } catch (error) {
|
||||
// const errorMessage = error.response?.data?.error || 'No se encontró el estudiante';
|
||||
const router = useRouter();
|
||||
|
||||
// if (errorMessage === 'Token inválido') {
|
||||
// handleLogout();
|
||||
// }
|
||||
const handleLogout = () => {
|
||||
Cookies.remove("token");
|
||||
Cookies.remove("session");
|
||||
router.push("/Login");
|
||||
};
|
||||
|
||||
// setError(errorMessage);
|
||||
// }
|
||||
// };
|
||||
const handlePayment = async () => {
|
||||
setAlert("");
|
||||
setError("");
|
||||
|
||||
return (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
// handlePayment();
|
||||
}}>
|
||||
<div className="gap">
|
||||
if (!numAccount) {
|
||||
setError("Error busca denuevo al estudiante");
|
||||
return;
|
||||
}
|
||||
|
||||
<div className='groupInput'>
|
||||
<label className='label'>Costo:</label>
|
||||
<select
|
||||
value={cost}
|
||||
onChange={(e) => setCost(e.target.value)}
|
||||
>
|
||||
<option value="">-- Selecciona un tiempo --</option>
|
||||
{costs.map((c) => (
|
||||
<option key={c.value} value={c.value}>
|
||||
${c.value}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
if (!pages) {
|
||||
setError("Ingresa el numero de hojas a imprimir");
|
||||
return;
|
||||
}
|
||||
|
||||
<div className='groupInput'>
|
||||
<label className='label'>Hojas:</label>
|
||||
<input
|
||||
type='text'
|
||||
value={pages}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
if (/^\d*$/.test(value)) {
|
||||
setPages(value);
|
||||
}
|
||||
}}
|
||||
placeholder='Numero de hojas a imprimir...'
|
||||
inputMode='numeric'
|
||||
pattern='[0-9]*'
|
||||
/>
|
||||
</div>
|
||||
if(!cost){
|
||||
setError("Selecciona un costo")
|
||||
return;
|
||||
}
|
||||
|
||||
<div className='groupLabel'>
|
||||
<label className='label'>Total: {pages && `$${pages}.00`}</label>
|
||||
</div>
|
||||
const token = Cookies.get("token");
|
||||
if (!token) {
|
||||
handleLogout();
|
||||
return;
|
||||
}
|
||||
|
||||
<div className='containerButton'>
|
||||
<button
|
||||
className='button buttonCharge'
|
||||
type='submit'>
|
||||
Cobrar
|
||||
</button>
|
||||
try {
|
||||
await axios.post(
|
||||
`${envConfig.apiUrl}/impressions`,
|
||||
{
|
||||
numAccount: numAccount,
|
||||
pages: parseInt(pages),
|
||||
cost: parseInt(cost) * parseInt(pages),
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
{error &&
|
||||
<div className={`messageBox error ${!showError ? 'hidden' : ''}`}>
|
||||
{error}
|
||||
</div>
|
||||
}
|
||||
{alert &&
|
||||
<div className={`messageBox success ${!showAlert ? 'hidden' : ''}`}>
|
||||
{alert}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
setAlert("Cobro realizado correctamente");
|
||||
setPages("");
|
||||
} catch (error: any) {
|
||||
const errorMessage =
|
||||
error.response?.data?.error || "No se encontró el estudiante";
|
||||
|
||||
if (errorMessage === "Token inválido") {
|
||||
handleLogout();
|
||||
}
|
||||
|
||||
setError(errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
handlePayment();
|
||||
}}
|
||||
>
|
||||
<div className="gap">
|
||||
<div className="groupInput">
|
||||
<label className="label">Costo:</label>
|
||||
<select value={cost} onChange={(e) => setCost(e.target.value)}>
|
||||
<option value="">-- Selecciona un tiempo --</option>
|
||||
{costs.map((c) => (
|
||||
<option key={c.value} value={c.value}>
|
||||
${c.value}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="groupInput">
|
||||
<label className="label">Hojas:</label>
|
||||
<input
|
||||
type="text"
|
||||
value={pages}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
if (/^\d*$/.test(value)) {
|
||||
setPages(value);
|
||||
}
|
||||
}}
|
||||
placeholder="Numero de hojas a imprimir..."
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="groupLabel">
|
||||
<label className="label">Total: {pages && `$${pages}.00`}</label>
|
||||
</div>
|
||||
|
||||
<div className="containerButton">
|
||||
<button className="button buttonCharge" type="submit">
|
||||
Cobrar
|
||||
</button>
|
||||
|
||||
{error && (
|
||||
<div className={`messageBox error ${!showError ? "hidden" : ""}`}>
|
||||
{error}
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
)}
|
||||
{alert && (
|
||||
<div className={`messageBox success ${!showAlert ? "hidden" : ""}`}>
|
||||
{alert}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
export default Impressions
|
||||
//IO
|
||||
export default Impressions;
|
||||
//IO
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
import { useEffect, useState } from "react";
|
||||
import "./Receipt.css"
|
||||
import { PostReceipt } from "@/app/lib/receipt";
|
||||
|
||||
function Receipt() {
|
||||
const [folio, setFolio] = useState('');
|
||||
@@ -46,11 +47,15 @@ function Receipt() {
|
||||
}, [error]);
|
||||
//fadeOut alert and error//
|
||||
|
||||
const handleSaveReceipt = ( )=>{
|
||||
//PostReceipt(data{folio,amount,date})
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
// handleSaveReceipt();
|
||||
handleSaveReceipt();
|
||||
}}
|
||||
>
|
||||
|
||||
|
||||
@@ -1,34 +1,44 @@
|
||||
'use client'
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
function SearchUser() {
|
||||
const [numAccount, setNumAccount] = useState('');
|
||||
return (
|
||||
<>
|
||||
<form className="containerForm">
|
||||
<label className='label'>No.Cuenta</label>
|
||||
<div className='groupInput'>
|
||||
<input
|
||||
type='text'
|
||||
value={numAccount}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
if (/^\d*$/.test(value) && value.length <= 9) {
|
||||
setNumAccount(value);
|
||||
}
|
||||
}}
|
||||
placeholder='Coloca un número de cuenta...'
|
||||
inputMode='numeric'
|
||||
pattern='[0-9]*'
|
||||
/>
|
||||
<button
|
||||
className='button buttonSearch'
|
||||
type='submit'
|
||||
>Buscar
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
)
|
||||
const [numAccount, setNumAccount] = useState("");
|
||||
const router = useRouter();
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (numAccount) {
|
||||
router.push(`/Impresiones?numAccount=${numAccount}`);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<form className="containerForm"
|
||||
onSubmit={handleSubmit}>
|
||||
<label className="label">No.Cuenta</label>
|
||||
<div className="groupInput">
|
||||
<input
|
||||
type="text"
|
||||
value={numAccount}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
if (/^\d*$/.test(value) && value.length <= 9) {
|
||||
setNumAccount(value);
|
||||
}
|
||||
}}
|
||||
placeholder="Coloca un número de cuenta..."
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
/>
|
||||
<button className="button buttonSearch" type="submit">
|
||||
Buscar
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default SearchUser
|
||||
export default SearchUser;
|
||||
|
||||
Reference in New Issue
Block a user