mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-02-21 18:22:00 +00:00
- Updated the title and description in layout.tsx to reflect the new application name. - Replaced the background color in globals.css with a background image for the title section. - Enhanced the Devices and UserDevices pages by adding search and filter components for improved user interaction. - Introduced a new DevicesTable component for displaying device data with pagination. - Updated the Users page to improve layout and added a filter for user status. - Made various UI adjustments across components for better consistency and usability.
74 lines
1.7 KiB
TypeScript
74 lines
1.7 KiB
TypeScript
"use client";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select";
|
|
import { cn } from "@/lib/utils";
|
|
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
|
import { useState, useTransition } from "react";
|
|
|
|
interface FilterOption {
|
|
value: string;
|
|
label: string;
|
|
icon: React.ReactNode;
|
|
}
|
|
|
|
interface FilterProps {
|
|
options: FilterOption[];
|
|
defaultOption: string;
|
|
queryParamKey: string;
|
|
}
|
|
|
|
export default function Filter({
|
|
options,
|
|
defaultOption,
|
|
queryParamKey,
|
|
}: FilterProps) {
|
|
const [selectedOption, setSelectedOption] = useState(defaultOption);
|
|
const searchParams = useSearchParams();
|
|
const { replace } = useRouter();
|
|
const pathname = usePathname();
|
|
const [isPending, startTransition] = useTransition();
|
|
|
|
function handleFilterChange(value: string) {
|
|
setSelectedOption(value);
|
|
const params = new URLSearchParams(searchParams.toString());
|
|
|
|
params.set(queryParamKey, value);
|
|
params.set("page", "1");
|
|
|
|
startTransition(() => {
|
|
replace(`${pathname}?${params.toString()}`);
|
|
});
|
|
}
|
|
|
|
return (
|
|
<div className={cn(isPending && "animate-pulse")}>
|
|
<Select
|
|
disabled={isPending}
|
|
value={selectedOption}
|
|
onValueChange={(val) => handleFilterChange(val)}
|
|
>
|
|
<SelectTrigger className="w-auto">
|
|
<SelectValue>
|
|
{options.find((option) => option.value === selectedOption)?.label}
|
|
</SelectValue>
|
|
</SelectTrigger>
|
|
<SelectContent align="end">
|
|
{options.map((option) => (
|
|
<SelectItem key={option.value} value={option.value}>
|
|
<div className="flex items-center gap-4">
|
|
{option.icon}
|
|
<span>{option.label}</span>
|
|
</div>
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
);
|
|
}
|