useAdminUsers
Location: src/hooks/useAdminUsers.js
Overview
Provides three hooks for admin user management: useAdminUsers for searching users, useUserDetail for viewing a user's full profile with actions/reports/posts, and useUserActions for issuing warnings, suspensions, bans, and revoking previous actions.
These hooks are intended for use in admin panel components only.
Exported Hooks
useAdminUsers
Searches users via the admin_search_users RPC function.
function useAdminUsers(): {
users: User[],
isLoading: boolean,
error: string | null,
searchUsers: (term: string, statusFilter?: string | null) => Promise<void>,
clearSearch: () => void
}
| Property | Type | Description |
|---|---|---|
users | User[] | Array of matching user objects |
isLoading | boolean | Whether a search is in progress |
error | string | null | Error message if search failed |
searchUsers | (term, statusFilter?) => Promise<void> | Search users by term (min 2 chars). Optional status filter. Returns up to 50 results. |
clearSearch | () => void | Clear search results and errors |
useUserDetail
Fetches detailed information about a specific user.
function useUserDetail(userId: string): {
user: object | null,
actions: Action[],
reports: Report[],
posts: Post[],
isLoading: boolean,
error: string | null,
refetch: () => void
}
| Parameter | Type | Required | Description |
|---|---|---|---|
userId | string | Yes | The target user's ID |
| Property | Type | Description |
|---|---|---|
user | object | null | User profile data from admin_view_user RPC |
actions | Action[] | Admin actions (warnings, suspensions, bans) with admin info. Up to 20 most recent. |
reports | Report[] | Reports filed against this user with reporter info. Up to 10 most recent. |
posts | Post[] | The user's recent posts (id, content, intent, created_at, is_hidden). Up to 10. |
isLoading | boolean | Whether data is being fetched |
error | string | null | Error message if fetch failed |
refetch | () => void | Re-fetch all user detail data |
useUserActions
Provides admin moderation actions.
function useUserActions(): {
isSubmitting: boolean,
error: string | null,
warnUser: (userId: string, reason: string, notes?: string | null) => Promise<Result>,
suspendUser: (userId: string, reason: string, duration: number, notes?: string | null) => Promise<Result>,
banUser: (userId: string, reason: string, notes?: string | null) => Promise<Result>,
revokeAction: (actionId: string, reason: string) => Promise<Result>,
clearError: () => void
}
| Property | Type | Description |
|---|---|---|
isSubmitting | boolean | Whether an action is being submitted |
error | string | null | Error message if action failed |
warnUser | (userId, reason, notes?) => Promise<Result> | Issue a warning via admin_warn_user RPC |
suspendUser | (userId, reason, duration, notes?) => Promise<Result> | Suspend for duration days via admin_suspend_user RPC |
banUser | (userId, reason, notes?) => Promise<Result> | Permanently ban via admin_ban_user RPC |
revokeAction | (actionId, reason) => Promise<Result> | Revoke a previous action via admin_revoke_action RPC |
clearError | () => void | Clear the error state |
Usage
import { useAdminUsers, useUserDetail, useUserActions } from '../hooks/useAdminUsers';
function AdminUserSearch() {
const { users, isLoading, searchUsers, clearSearch } = useAdminUsers();
return (
<div>
<input onChange={(e) => searchUsers(e.target.value)} />
{users.map(u => <UserRow key={u.id} user={u} />)}
</div>
);
}
function AdminUserPanel({ userId }) {
const { user, actions, reports, posts, isLoading } = useUserDetail(userId);
const { warnUser, suspendUser, banUser } = useUserActions();
if (isLoading) return <Skeleton />;
return (
<div>
<h2>{user?.display_name}</h2>
<button onClick={() => warnUser(userId, 'Policy violation')}>Warn</button>
<button onClick={() => suspendUser(userId, 'Repeated violations', 7)}>Suspend 7 days</button>
</div>
);
}
Notes
- All admin RPC functions require admin role authorization on the server side.
useUserDetaildoes not auto-fetch on mount. You must callrefetch()to load data, or pass theuserIdand trigger loading from your component.warnUser,suspendUser,banUser, andrevokeActionall return{ success: true }or{ success: false, error: string }.- The
notesparameter on moderation actions is for internal admin notes, not visible to the user.
Last updated: 2026-02-07