change to pathname and params
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { PostReceipt } from "@/app/lib/postReceipt";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
|
||||
import "./Receipt.css";
|
||||
|
||||
@@ -12,6 +12,8 @@ interface ReceiptsProps {
|
||||
|
||||
function Receipt({ numAcount }: ReceiptsProps) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const [folio, setFolio] = useState("");
|
||||
const [amount, setAmount] = useState("");
|
||||
@@ -28,12 +30,11 @@ function Receipt({ numAcount }: ReceiptsProps) {
|
||||
//restrict this month//
|
||||
|
||||
const handleSaveReceipt = async () => {
|
||||
const currentUrl = new URL(window.location.href);
|
||||
const params = new URLSearchParams();
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
|
||||
const setError = (msg: string) => {
|
||||
params.set("error", msg);
|
||||
router.push(`${currentUrl}&${params.toString()}`);
|
||||
router.push(`${pathname}&${params.toString()}`);
|
||||
};
|
||||
|
||||
if (!numAcount) {
|
||||
@@ -66,7 +67,7 @@ function Receipt({ numAcount }: ReceiptsProps) {
|
||||
|
||||
params.delete("error");
|
||||
params.set("success", "Recibo guardado");
|
||||
router.push(`${currentUrl}&${params.toString()}`);
|
||||
router.push(`${pathname}&${params.toString()}`);
|
||||
} catch (err: any) {
|
||||
setError(String(err));
|
||||
}
|
||||
@@ -111,10 +112,9 @@ function Receipt({ numAcount }: ReceiptsProps) {
|
||||
if (value === "" || numericValue <= 1000) {
|
||||
setAmount(value);
|
||||
} else {
|
||||
const currentUrl = new URL(window.location.href);
|
||||
const params = new URLSearchParams();
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
params.set("error", "El monto no puede superar $1000.00");
|
||||
router.push(`${currentUrl}&${params.toString()}`);
|
||||
router.push(`${pathname}&${params.toString()}`);
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user