Refactor and centralize user and pagination interfaces in useAdmin hook

- Unified `User` and `PaginationMeta` type definitions into `useAdmin` to improve maintainability and consistency.
- Updated affected components (`UserManagementContent`, `UserListTable`, `UserFormDialog`, `UserActionMenu`) to reference the centralized types.
- Enhanced test coverage for user-related hooks to include create, update, delete, activate, deactivate, and bulk actions.
This commit is contained in:
Felipe Cardoso
2025-11-06 12:49:46 +01:00
parent 91bc4f190d
commit f22f87250c
6 changed files with 316 additions and 49 deletions

View File

@@ -123,6 +123,39 @@ export function useAdminStats() {
});
}
/**
* Pagination metadata structure
*/
export interface PaginationMeta {
total: number;
page: number;
page_size: number;
total_pages: number;
has_next: boolean;
has_prev: boolean;
}
/**
* User interface matching backend UserResponse
*/
export interface User {
id: string;
email: string;
first_name: string;
last_name: string | null;
is_active: boolean;
is_superuser: boolean;
created_at: string;
}
/**
* Paginated user list response
*/
export interface PaginatedUserResponse {
data: User[];
pagination: PaginationMeta;
}
/**
* Hook to fetch paginated list of all users (for admin)
*
@@ -135,7 +168,7 @@ export function useAdminUsers(page = 1, limit = DEFAULT_PAGE_LIMIT) {
return useQuery({
queryKey: ['admin', 'users', page, limit],
queryFn: async () => {
queryFn: async (): Promise<PaginatedUserResponse> => {
const response = await adminListUsers({
query: { page, limit },
throwOnError: false,
@@ -146,7 +179,7 @@ export function useAdminUsers(page = 1, limit = DEFAULT_PAGE_LIMIT) {
}
// Type assertion: if no error, response has data
return (response as { data: unknown }).data;
return (response as { data: PaginatedUserResponse }).data;
},
// Only fetch if user is a superuser (frontend guard)
enabled: user?.is_superuser === true,