fix(types): replace unexpected any with explicit types across useUserManagement hook

This commit is contained in:
2026-08-20 12:08:24 +00:00
parent 842b826463
commit 3da77e8d7a
+12 -11
View File
@@ -22,7 +22,7 @@ export interface UserProfile {
privileges?: { privileges?: {
name: string; name: string;
description: string; description: string;
permissions: any; permissions: Record<string, unknown>;
}; };
} }
@@ -38,7 +38,7 @@ export interface UserPrivilege {
id: string; id: string;
name: string; name: string;
description: string | null; description: string | null;
permissions: any; permissions: Record<string, unknown>;
created_at: string; created_at: string;
updated_at: string; updated_at: string;
} }
@@ -209,10 +209,11 @@ export function useUserManagement() {
toast.success('Usuário criado com sucesso! Senha padrão: 1234'); toast.success('Usuário criado com sucesso! Senha padrão: 1234');
fetchUsers(); fetchUsers();
return result; return result;
} catch (error: any) { } catch (error: unknown) {
console.error('Error creating user:', error); console.error('Error creating user:', error);
if (error.message?.includes('User with this email already exists')) { const err = error as Error;
if (err.message?.includes('User with this email already exists')) {
toast.error('Este e-mail já está em uso'); toast.error('Este e-mail já está em uso');
} else if (error.message?.includes('Only admins can create new users')) { } else if (error.message?.includes('Only admins can create new users')) {
toast.error('Apenas administradores podem criar usuários'); toast.error('Apenas administradores podem criar usuários');
@@ -268,12 +269,13 @@ export function useUserManagement() {
fetchUsers(); fetchUsers();
fetchPendingUsers(); fetchPendingUsers();
return true; return true;
} catch (error: any) { } catch (error: unknown) {
console.error('Error deleting user:', error); console.error('Error deleting user:', error);
if (error.message?.includes('Only admins can delete users')) { const err = error as Error;
if (err.message?.includes('Only admins can delete users')) {
toast.error('Apenas administradores podem excluir usuários'); toast.error('Apenas administradores podem excluir usuários');
} else if (error.message?.includes('User cannot be deleted due to existing dependencies')) { } else if (err.message?.includes('User cannot be deleted due to existing dependencies')) {
toast.error('Este usuário não pode ser excluído pois possui dados vinculados no sistema'); toast.error('Este usuário não pode ser excluído pois possui dados vinculados no sistema');
} else { } else {
toast.error('Erro ao excluir usuário'); toast.error('Erro ao excluir usuário');
@@ -338,10 +340,9 @@ export function useUserManagement() {
} }
}; };
// Toggle user status
const toggleUserStatus = async (userId: string, currentStatus: string) => { const toggleUserStatus = async (userId: string, currentStatus: string) => {
const newStatus = currentStatus === 'active' ? 'inactive' : 'active'; const newStatus = currentStatus === 'active' ? 'inactive' : 'active';
await updateUser(userId, { status: newStatus as any }); await updateUser(userId, { status: newStatus as UserProfile['status'] });
}; };
// CRUD functions for Functions table // CRUD functions for Functions table
@@ -396,7 +397,7 @@ export function useUserManagement() {
}; };
// CRUD functions for Privileges table - Updated to handle interface resources // CRUD functions for Privileges table - Updated to handle interface resources
const createPrivilege = async (data: { name: string; description?: string; permissions?: any }, resourceKeys: string[] = []) => { const createPrivilege = async (data: { name: string; description?: string; permissions?: Record<string, unknown> }, resourceKeys: string[] = []) => {
try { try {
const { data: newPrivilege, error } = await supabase const { data: newPrivilege, error } = await supabase
.from('privileges') .from('privileges')
@@ -424,7 +425,7 @@ export function useUserManagement() {
} }
}; };
const updatePrivilege = async (id: string, data: { name: string; description?: string; permissions?: any }) => { const updatePrivilege = async (id: string, data: { name: string; description?: string; permissions?: Record<string, unknown> }) => {
try { try {
const { error } = await supabase const { error } = await supabase
.from('privileges') .from('privileges')