Files

56 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2026-01-26 13:04:50 -06:00
"use client";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
2026-03-04 15:00:47 -06:00
import { useEffect, useState } from "react";
2026-01-26 13:04:50 -06:00
2026-03-04 15:00:47 -06:00
interface urlProp {
value: string | null;
}
2026-01-26 13:04:50 -06:00
2026-03-04 15:00:47 -06:00
export default function SearchMesa(props: urlProp) {
2026-01-29 11:21:12 -06:00
const [inputValue, setInputValue] = useState("");
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
2026-01-26 13:04:50 -06:00
2026-03-04 15:00:47 -06:00
useEffect(() => {
if (props.value) {
setInputValue(props.value);
}
if(props.value===null){
setInputValue("")
}
}, [props.value]);
2026-01-26 13:04:50 -06:00
const buscar = (e: React.FormEvent) => {
e.preventDefault();
2026-01-29 11:21:12 -06:00
const params = new URLSearchParams(searchParams.toString());
if (inputValue) {
params.set("table", `${inputValue}`);
router.push(`${pathname}?${params.toString()}`);
}
2026-01-26 13:04:50 -06:00
};
return (
<>
<form className="containerForm" onSubmit={buscar}>
<label>Numero de mesa</label>
<div className="groupInput">
<input
type="text"
2026-01-26 13:04:50 -06:00
placeholder="Coloca el numero de mesa"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
/>
<button type="submit" className="button buttonSearch">
Buscar
</button>
</div>
</form>
</>
);
}