Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/zzgs4tgba6emjq6kuntitledPlain Text
// ADMINISTRACIÓN Y SEGURIDAD
if (esPrincipal) {
Card(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(20.dp),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.secondaryContainer
)
) {
Column(
modifier = Modifier.padding(18.dp),
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
Text(
text = "Cuenta protegida",
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onSecondaryContainer
)
Text(
text = "La cuenta del administrador principal está protegida y no puede modificarse desde este panel.",
color = MaterialTheme.colorScheme.onSecondaryContainer,
style = MaterialTheme.typography.bodyMedium
)
}
}
} else {
SeccionTitulo(
titulo = "Seguridad y administración",
descripcion = "Controla el nivel de acceso y la seguridad de la cuenta.",
identificador = "03"
)
// CAMBIAR ROL
TarjetaAccionCuenta(
titulo = "Rol del usuario",
descripcion = nombreRol(usuario.rol),
textoBoton = "Cambiar rol",
habilitado = !guardando,
onClick = { mostrarDialogoRol = true }
)
// ESTADO DE CUENTA
TarjetaAccionCuenta(
titulo = "Estado de la cuenta",
descripcion = if (estaActivo)
"Esta cuenta está habilitada y puede iniciar sesión."
else
"Esta cuenta está desactivada y no puede iniciar sesión.",
textoBoton = if (estaActivo)
"Desactivar cuenta"
else
"Activar cuenta",
habilitado = !guardando,
onClick = { mostrarDialogoEstado = true }
)
// RESTABLECER CONTRASEÑA
TarjetaAccionCuenta(
titulo = "Contraseña",
descripcion = "Genera una contraseña temporal. El usuario deberá establecer una nueva al iniciar sesión.",
textoBoton = "Restablecer contraseña",
habilitado = !guardando,
onClick = { mostrarDialogoRestablecer = true }
)
// ELIMINAR USUARIO
TarjetaAccionCuenta(
titulo = "Eliminar usuario",
descripcion = "Elimina definitivamente esta cuenta. No se podrá recuperar. Si tiene ventas u otros registros relacionados, no se permitirá eliminarla.",
textoBoton = "Eliminar usuario",
habilitado = !guardando,
onClick = {
mostrarDialogoEliminar = true
}
)
}
// MENSAJES
mensaje?.let {
Card(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors(
containerColor = if (esError)
MaterialTheme.colorScheme.errorContainer
else
MaterialTheme.colorScheme.primaryContainer
)
) {
Text(
text = it,
modifier = Modifier.padding(16.dp),
color = if (esError)
MaterialTheme.colorScheme.onErrorContainer
else
MaterialTheme.colorScheme.onPrimaryContainer,
style = MaterialTheme.typography.bodyMedium
)
}
}
Spacer(modifier = Modifier.height(20.dp))
}
// DIÁLOGO: CAMBIAR ROL
if (mostrarDialogoRol) {
var rolSeleccionado by remember(usuario.id, usuario.rol) {
mutableStateOf(usuario.rol)
}
AlertDialog(
onDismissRequest = { mostrarDialogoRol = false },
title = { Text("Cambiar rol") },
text = {
Column {
Text("Selecciona el nuevo rol para esta cuenta.")
Spacer(modifier = Modifier.height(12.dp))
listOf(
"vendedor" to "Vendedor",
"administrador_secundario" to "Administrador secundario"
).forEach { (valor, etiqueta) ->
Row(
verticalAlignment = Alignment.CenterVertically
) {
RadioButton(
selected = rolSeleccionado == valor,
onClick = { rolSeleccionado = valor }
)
Text(etiqueta)
}
}
}
},
confirmButton = {
TextButton(
enabled = !guardando,
onClick = {
mostrarDialogoRol = false
if (rolSeleccionado != usuario.rol) {
scope.launch {
guardando = true
mensaje = null
try {
val resultado = CuentaService()
.cambiarRolUsuario(
usuarioId = usuario.id,
nuevoRol = rolSeleccionado
)
onUsuarioActualizado(
usuario.copy(rol = rolSeleccionado)
)
mensaje = resultado
esError = false
} catch (e: Exception) {
mensaje = e.message
?: "No se pudo cambiar el rol."
esError = true
} finally {
guardando = false
}
}
}
}
) {
Text("Guardar")
}
},
dismissButton = {
TextButton(
onClick = { mostrarDialogoRol = false }
) {
Text("Cancelar")
}
}
)
}
7,080 chars · codepastes.com