change to pathname and params
This commit is contained in:
@@ -22,9 +22,10 @@ function Mesas() {
|
||||
<option value="90">15</option>
|
||||
</select>
|
||||
|
||||
<div className="checkbox">
|
||||
<div className="checkbox-grid">
|
||||
<label>
|
||||
<input type="checkbox" />
|
||||
<label>Mantenimiento</label>
|
||||
Mantenimiento</label>
|
||||
</div>
|
||||
|
||||
<button className="button buttonSearch" type="submit">
|
||||
|
||||
@@ -12,7 +12,7 @@ export default async function Sanciones(props: { student?: Student }) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<SearchUser urlBase="BitacoraSanciones" value={idCuenta} />
|
||||
<SearchUser value={idCuenta} />
|
||||
{props.student && (
|
||||
<>
|
||||
<Information
|
||||
|
||||
@@ -8,6 +8,7 @@ interface ClearParamsProps {
|
||||
|
||||
export default function ClearParams({ paramsToClear }: ClearParamsProps) {
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
const url = new URL(window.location.href);
|
||||
let changed = false;
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
'use client'
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
interface urlProp{
|
||||
urlBase:string
|
||||
value:string|null
|
||||
interface urlProp {
|
||||
value: string | null;
|
||||
}
|
||||
|
||||
function SearchUser(props:urlProp) {
|
||||
function SearchUser(props: urlProp) {
|
||||
const [numAcount, setnumAcount] = useState("");
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
useEffect(() => {
|
||||
if (props.value) {
|
||||
@@ -20,16 +21,17 @@ function SearchUser(props:urlProp) {
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
if (numAcount) {
|
||||
router.push(`/${props.urlBase}?numAcount=${numAcount}`);
|
||||
params.delete("error");
|
||||
params.set("numAcount", `${numAcount}`);
|
||||
router.push(`${pathname}?${params.toString()}`);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<form className="containerForm"
|
||||
onSubmit={handleSubmit}>
|
||||
<form className="containerForm" onSubmit={handleSubmit}>
|
||||
<label className="label">No.Cuenta</label>
|
||||
<div className="groupInput">
|
||||
<input
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { usePathname, useSearchParams } from "next/navigation";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState, ReactNode } from "react";
|
||||
|
||||
@@ -18,6 +18,7 @@ interface ToggleProps {
|
||||
export default function Toggle({ options, defaultView }: ToggleProps) {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const pathname = usePathname();
|
||||
const [view, setView] = useState(defaultView || options[0].key);
|
||||
|
||||
const handleClick = (key: string) => {
|
||||
@@ -26,7 +27,7 @@ export default function Toggle({ options, defaultView }: ToggleProps) {
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
params.set("key", key);
|
||||
|
||||
router.replace(`${window.location.pathname}?${params.toString()}`);
|
||||
router.replace(`${pathname}?${params.toString()}`);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -3,15 +3,16 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import AlertBox from "@/app/Components/Global/AlertBox/AlertBox";
|
||||
import ClearParams from "@/app/Components/Global/ClearParams/ClearParams";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
|
||||
export default function GlobalAlert() {
|
||||
const searchParams = useSearchParams();
|
||||
const [showSuccess, setShowSuccess] = useState<string | null>(null);
|
||||
const [showError, setShowError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const url = new URL(window.location.href);
|
||||
const success = url.searchParams.get("success");
|
||||
const error = url.searchParams.get("error");
|
||||
const success = searchParams.get("success");
|
||||
const error = searchParams.get("error");
|
||||
|
||||
if (success) setShowSuccess(success);
|
||||
if (error) setShowError(error);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import Cookies from "js-cookie";
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { PostImpressions } from "@/app/lib/postImpressions";
|
||||
|
||||
interface CostOption {
|
||||
@@ -19,6 +19,8 @@ function Impressions({ costs, numAcount }: ImpressionsProps) {
|
||||
const [cost, setCost] = useState("");
|
||||
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const handleLogout = () => {
|
||||
Cookies.remove("token");
|
||||
@@ -27,12 +29,11 @@ function Impressions({ costs, numAcount }: ImpressionsProps) {
|
||||
};
|
||||
|
||||
const handlePayment = 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) {
|
||||
@@ -65,7 +66,7 @@ function Impressions({ costs, numAcount }: ImpressionsProps) {
|
||||
setCost("");
|
||||
params.delete("error");
|
||||
params.set("success", "Impresion cobrada correctamente");
|
||||
router.push(`${currentUrl}&${params.toString()}`);
|
||||
router.push(`${pathname}&${params.toString()}`);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -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