diff --git a/src/views/AdminAuthorizations.tsx b/src/views/AdminAuthorizations.tsx index b0c0245..5cc7354 100644 --- a/src/views/AdminAuthorizations.tsx +++ b/src/views/AdminAuthorizations.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { Loader2, Search, ShieldCheck, UserCog } from "lucide-react"; import { useAuth } from "@/contexts/AuthContext"; @@ -16,6 +16,11 @@ import { Switch } from "@/components/ui/switch"; const PAGE_SIZE = 25; +const normalizeSearchDigits = (value: string) => + value + .replace(/[۰-۹]/g, (digit) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(digit))) + .replace(/[٠-٩]/g, (digit) => String("٠١٢٣٤٥٦٧٨٩".indexOf(digit))); + function fullName(user: Pick) { return [user.first_name, user.last_name].filter(Boolean).join(" ") || user.username; } @@ -34,6 +39,14 @@ export default function AdminAuthorizations() { queryFn: () => api.listUsers({ search: search || undefined, limit: PAGE_SIZE, offset: 0 }), }); + useEffect(() => { + const timeoutId = window.setTimeout(() => { + setSearch(normalizeSearchDigits(searchDraft).trim()); + }, 400); + + return () => window.clearTimeout(timeoutId); + }, [searchDraft]); + const authQuery = useQuery({ queryKey: ["admin", "authorizations", selectedUserId], queryFn: () => api.getUserAuthorization(selectedUserId as number), @@ -104,18 +117,13 @@ export default function AdminAuthorizations() { نام، موبایل، ایمیل یا نام کاربری را جستجو کنید. -
- +
+ setSearchDraft(event.target.value)} - onKeyDown={(event) => { - if (event.key === "Enter") setSearch(searchDraft.trim()); - }} placeholder="جستجو..." - className="text-right" + className="pl-10 text-right" />
{usersQuery.isLoading ? ( @@ -140,7 +148,10 @@ export default function AdminAuthorizations() { {fullName(item)}
-

{item.mobile || item.email || item.username}

+
+

{item.mobile || "بدون شماره موبایل"}

+

{item.email || item.username}

+
))}