feat(filters): replace existing filters with dynamic filters for improved user and device management

This commit is contained in:
2025-07-14 21:39:31 +05:00
parent 8bcf4812be
commit 9926de99d6
4 changed files with 74 additions and 46 deletions

View File

@ -11,7 +11,6 @@ import type {
Topup Topup
} from "@/lib/backend-types"; } from "@/lib/backend-types";
import type { TopupResponse } from "@/lib/types"; import type { TopupResponse } from "@/lib/types";
import type { User } from "@/lib/types/user";
import { handleApiResponse } from "@/utils/tryCatch"; import { handleApiResponse } from "@/utils/tryCatch";
type GenericGetResponseProps = { type GenericGetResponseProps = {

View File

@ -1,5 +1,6 @@
import { Suspense } from "react"; import { Suspense } from "react";
import { DevicesTable } from "@/components/devices-table"; import { DevicesTable } from "@/components/devices-table";
import DynamicFilter from "@/components/generic-filter";
import Search from "@/components/search"; import Search from "@/components/search";
export default async function ParentalControl({ export default async function ParentalControl({
@ -27,8 +28,30 @@ export default async function ParentalControl({
id="user-filters" id="user-filters"
className=" pb-4 gap-4 flex sm:flex-row flex-col items-start justify-start" className=" pb-4 gap-4 flex sm:flex-row flex-col items-start justify-start"
> >
<Search /> <DynamicFilter
</div> description="Filter devices by name, MAC address, or vendor."
title="Device Filter"
inputs={[
{
name: "name",
label: "Device Name",
type: "string",
placeholder: "Enter device name",
},
{
name: "mac",
label: "MAC Address",
type: "string",
placeholder: "Enter MAC address",
},
{
name: "vendor",
label: "Vendor",
type: "string",
placeholder: "Enter vendor name",
}
]}
/> </div>
<Suspense key={(await searchParams).page} fallback={"loading...."}> <Suspense key={(await searchParams).page} fallback={"loading...."}>
<DevicesTable <DevicesTable
parentalControl={true} parentalControl={true}

View File

@ -1,10 +1,10 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { getServerSession } from "next-auth"; import { getServerSession } from "next-auth";
import { getProfileById } from "@/actions/user-actions";
import { authOptions } from "@/app/auth"; import { authOptions } from "@/app/auth";
import ClientErrorMessage from "@/components/client-error-message"; import ClientErrorMessage from "@/components/client-error-message";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import { FloatingLabelInput } from "@/components/ui/floating-label"; import { FloatingLabelInput } from "@/components/ui/floating-label";
import { getProfileById } from "@/queries/users";
import { tryCatch } from "@/utils/tryCatch"; import { tryCatch } from "@/utils/tryCatch";
export default async function Profile() { export default async function Profile() {

View File

@ -1,27 +1,7 @@
import Filter from "@/components/filter";
import Search from "@/components/search";
import { UsersTable } from "@/components/user-table";
import {
AArrowDown,
AArrowUp,
CheckCheck,
Hourglass,
Minus,
} from "lucide-react";
import { Suspense } from "react"; import { Suspense } from "react";
import DynamicFilter from "@/components/generic-filter";
import { UsersTable } from "@/components/user-table";
const sortfilterOptions = [
{
value: "asc",
label: "Ascending",
icon: <AArrowUp size={16} />,
},
{
value: "desc",
label: "Descending",
icon: <AArrowDown size={16} />,
},
];
export default async function AdminUsers({ export default async function AdminUsers({
searchParams, searchParams,
@ -43,33 +23,59 @@ export default async function AdminUsers({
id="user-table-filters" id="user-table-filters"
className=" pb-4 gap-4 flex items-center justify-start" className=" pb-4 gap-4 flex items-center justify-start"
> >
<Search /> <DynamicFilter
<Filter description="Filter users by id card, name, or house name and more."
options={[ title="User Filter"
inputs={[
{ {
value: "all", name: "first_name",
label: "ALL", label: "User First Name",
icon: <Minus size={14} />, type: "string",
placeholder: "Enter user first name",
}, },
{ {
value: "unverified", name: "last_name",
label: "Unverfieid", label: "User Last Name",
icon: <CheckCheck size={14} />, type: "string",
placeholder: "Enter user last name",
},
{
name: "id_card",
label: "ID Card",
type: "string",
placeholder: "Enter ID card number",
},
{
name: "house_name",
label: "House Name",
type: "string",
placeholder: "Enter house name",
},
{
name: "mobile",
label: "Phone Number",
type: "string",
placeholder: "Enter phone number",
},
{
name: "verified",
type: "radio-group",
label: "User Status",
options: [
{
value: "",
label: "All",
}, },
{ {
value: "verified",
label: "Verified", label: "Verified",
icon: <Hourglass size={14} />, value: "true",
}, },
{
label: "Unverified",
value: "false",
}]
}
]} ]}
defaultOption="all"
queryParamKey="status"
/>
<Filter
options={sortfilterOptions}
defaultOption="asc"
queryParamKey="sortBy"
/> />
</div> </div>
<Suspense fallback={"loading...."}> <Suspense fallback={"loading...."}>