fix: improve role assignment logic and permission handling in dashboard components

This commit is contained in:
2025-10-27 08:41:53 -03:00
parent 2c2b792b4a
commit 6bfc0c2ced
19 changed files with 2105 additions and 118 deletions

View File

@@ -105,8 +105,11 @@
// Se for alterar role, pegar a role atual do usuário
if (acao === "alterar_role" && usuariosQuery.data) {
const usuario = usuariosQuery.data.find((u: any) => u._id === usuarioId);
if (usuario) {
novaRoleId = usuario.role._id;
if (usuario && usuario.role && usuario.role._id) {
novaRoleId = usuario.role._id as Id<"roles">;
} else if (rolesQuery.data && rolesQuery.data.length > 0) {
// Se não conseguir pegar a role atual, usar a primeira role disponível
novaRoleId = rolesQuery.data[0]._id;
}
}