mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-02-22 17:02:01 +00:00
- Introduced a new Agreements page for managing agreements in the dashboard. - Enhanced the Devices page by adding sorting and filtering options for better device management. - Updated the Users page to include sorting functionality and improved layout. - Implemented user verification and rejection dialogs for better user management. - Added InputReadOnly component for displaying user information in a read-only format. - Refactored search component to improve usability and visual consistency.
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
import { Loader2 } from "lucide-react";
|
|
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
|
import { useRef, useTransition } from "react";
|
|
import { Button } from "./ui/button";
|
|
|
|
export default function Search({ disabled }: { disabled?: boolean }) {
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
const { replace } = useRouter();
|
|
|
|
const pathname = usePathname();
|
|
const [isPending, startTransition] = useTransition();
|
|
const searchParams = useSearchParams();
|
|
const searchQuery = searchParams.get("query");
|
|
|
|
function handleSearch(term: string) {
|
|
const params = new URLSearchParams(searchParams.toString());
|
|
|
|
if (term) {
|
|
params.set("query", term);
|
|
params.set("page", "1");
|
|
} else {
|
|
params.delete("query");
|
|
}
|
|
|
|
startTransition(() => {
|
|
replace(`${pathname}?${params.toString()}`);
|
|
});
|
|
}
|
|
|
|
return (
|
|
<div className="flex w-full gap-2 items-center justify-between">
|
|
<Input
|
|
ref={inputRef}
|
|
placeholder="Search..."
|
|
type="text"
|
|
className="w-fit"
|
|
name="search"
|
|
id="search"
|
|
defaultValue={searchQuery ? searchQuery : ""}
|
|
disabled={disabled}
|
|
spellCheck={false}
|
|
onChange={(e) => handleSearch(e.target.value)}
|
|
/>
|
|
<Button
|
|
disabled={isPending}
|
|
onClick={() => {
|
|
if (inputRef.current) {
|
|
inputRef.current.value = "";
|
|
}
|
|
replace(pathname);
|
|
}}
|
|
>
|
|
{isPending ? <Loader2 className="animate-spin" /> : "Reset"}
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|