diff --git a/app/(manage)/manage/users/users-client.tsx b/app/(manage)/manage/users/users-client.tsx index 96c9905..5470ea9 100644 --- a/app/(manage)/manage/users/users-client.tsx +++ b/app/(manage)/manage/users/users-client.tsx @@ -35,6 +35,10 @@ export function UsersClient() { const [loading, setLoading] = useState(true) const [search, setSearch] = useState("") const [actionLoading, setActionLoading] = useState>({}) +const [banTarget, setBanTarget] = useState(null) +const [banReason, setBanReason] = useState("") +const [banExpiryDays, setBanExpiryDays] = useState("") +const [banFilter, setBanFilter] = useState<"all" | "banned" | "active">("all") useEffect(() => { const fetchUsers = async () => { @@ -49,14 +53,17 @@ export function UsersClient() { }, []) const filteredUsers = useMemo(() => { + let result = users const term = search.trim().toLowerCase() - if (!term) return users - return users.filter( - (u) => - u.name?.toLowerCase().includes(term) || - u.email?.toLowerCase().includes(term) - ) - }, [users, search]) + if (term) { + result = result.filter( + (u) => u.name?.toLowerCase().includes(term) || u.email?.toLowerCase().includes(term) + ) + } + if (banFilter === "banned") result = result.filter((u) => u.banned) + if (banFilter === "active") result = result.filter((u) => !u.banned) + return result + }, [users, search, banFilter]) const handleRoleChange = async (userId: string, newRole: Role) => { setActionLoading((prev) => ({ ...prev, [userId]: true })) @@ -70,15 +77,25 @@ export function UsersClient() { } } - const handleBan = async (userId: string) => { - setActionLoading((prev) => ({ ...prev, [userId]: true })) + const handleBan = async () => { + if (!banTarget) return + setActionLoading((prev) => ({ ...prev, [banTarget.id]: true })) try { - await authClient.admin.banUser({ userId }) + await authClient.admin.banUser({ + userId: banTarget.id, + banReason: banReason.trim() || undefined, + banExpires: banExpiryDays + ? new Date(Date.now() + Number(banExpiryDays) * 24 * 60 * 60 * 1000) + : undefined, + } as any) setUsers((prev) => - prev.map((u) => (u.id === userId ? { ...u, banned: true } : u)) + prev.map((u) => (u.id === banTarget.id ? { ...u, banned: true } : u)) ) + setBanTarget(null) + setBanReason("") + setBanExpiryDays("") } finally { - setActionLoading((prev) => ({ ...prev, [userId]: false })) + setActionLoading((prev) => ({ ...prev, [banTarget.id]: false })) } } @@ -117,6 +134,21 @@ export function UsersClient() { /> + {/* Filter Tabs */} +
+ {(["all", "active", "banned"] as const).map((f) => ( + + ))} +
+ {/* Users List */} {loading ? (
@@ -190,7 +222,7 @@ export function UsersClient() { ) : (
)} + + {/* Ban Modal */} + {banTarget && ( +
setBanTarget(null)}> +
e.stopPropagation()}> +

Ban {banTarget.name || banTarget.email}

+
+ +