Files
front-AT/app/Components/Global/SearchUser/searchUser.tsx
T

63 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-09-29 19:57:02 -06:00
"use client";
2025-09-17 16:47:19 -06:00
2025-09-29 19:57:02 -06:00
import { usePathname, useRouter, useSearchParams } from "next/navigation";
2025-09-22 11:57:52 -06:00
import { useEffect, useState } from "react";
2025-09-17 19:42:13 -06:00
2025-09-29 19:57:02 -06:00
interface urlProp {
value: string | null;
2025-09-17 19:42:13 -06:00
}
2025-09-29 19:57:02 -06:00
function SearchUser(props: urlProp) {
2026-02-26 13:52:47 -06:00
const [numAcount, setnumAcount] = useState<string>("");
2025-09-17 16:47:19 -06:00
const router = useRouter();
2025-09-29 19:57:02 -06:00
const pathname = usePathname();
const searchParams = useSearchParams();
2025-09-17 16:47:19 -06:00
2025-09-22 11:57:52 -06:00
useEffect(() => {
if (props.value) {
setnumAcount(props.value);
}
2026-02-26 13:35:29 -06:00
if(props.value===null){
setnumAcount("")
}
2025-09-22 11:57:52 -06:00
}, [props.value]);
2025-10-01 15:29:23 -06:00
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
2025-09-17 16:47:19 -06:00
e.preventDefault();
2025-09-29 19:57:02 -06:00
const params = new URLSearchParams(searchParams.toString());
2025-09-22 12:15:32 -04:00
if (numAcount) {
2025-09-29 19:57:02 -06:00
params.set("numAcount", `${numAcount}`);
router.push(`${pathname}?${params.toString()}`);
2025-09-17 16:47:19 -06:00
}
};
return (
<>
2025-09-29 19:57:02 -06:00
<form className="containerForm" onSubmit={handleSubmit}>
2025-09-17 16:47:19 -06:00
<label className="label">No.Cuenta</label>
<div className="groupInput">
<input
type="text"
2025-09-22 12:15:32 -04:00
value={numAcount}
2025-09-17 16:47:19 -06:00
onChange={(e) => {
const value = e.target.value;
if (/^\d*$/.test(value) && value.length <= 9) {
2025-09-22 12:15:32 -04:00
setnumAcount(value);
2025-09-17 16:47:19 -06:00
}
}}
placeholder="Coloca un número de cuenta..."
inputMode="numeric"
pattern="[0-9]*"
/>
<button className="button buttonSearch" type="submit">
Buscar
</button>
</div>
</form>
</>
);
2025-09-02 19:50:17 -04:00
}
2025-09-17 16:47:19 -06:00
export default SearchUser;
2025-10-02 01:41:41 -06:00
//IO