Refactor USB control to modal with improved UX

- Move USB policy control from bottom of page to modal dialog
- Add "Controle USB" button in device controls section
- Show USB chip for all Windows devices (default to ALLOW)
- Add close button (X) with hover effect in modal header
- Fix all Portuguese accents in USB control component
- Position status badge at top of modal content
- Add variant prop to UsbPolicyControl (card/inline)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
rever-tecnologia 2025-12-05 09:50:11 -03:00
parent 06ebad930c
commit 1ee5b34158
2 changed files with 57 additions and 34 deletions

View file

@ -137,7 +137,7 @@ export function UsbPolicyControl({
const handleApplyPolicy = async () => {
if (selectedPolicy === usbPolicy?.policy) {
toast.info("A politica selecionada ja esta aplicada.")
toast.info("A política selecionada já está aplicada.")
return
}
@ -150,10 +150,10 @@ export function UsbPolicyControl({
actorEmail,
actorName,
})
toast.success("Politica USB enviada para aplicacao.")
toast.success("Política USB enviada para aplicação.")
} catch (error) {
console.error("[usb-policy] Falha ao aplicar politica", error)
toast.error("Falha ao aplicar politica USB. Tente novamente.")
console.error("[usb-policy] Falha ao aplicar política", error)
toast.error("Falha ao aplicar política USB. Tente novamente.")
} finally {
setIsApplying(false)
}
@ -168,36 +168,42 @@ export function UsbPolicyControl({
const content = (
<div className="space-y-4">
<div className="flex items-center justify-between gap-2">
<div className="flex items-center gap-3 rounded-lg border bg-neutral-50 p-3 flex-1">
<div className="flex size-10 items-center justify-center rounded-full bg-white shadow-sm">
<CurrentIcon className="size-5 text-neutral-600" />
</div>
<div className="flex-1">
<p className="text-sm font-medium">{currentConfig.label}</p>
<p className="text-xs text-muted-foreground">{currentConfig.description}</p>
</div>
{/* Status atual no topo */}
{usbPolicy?.status && (
<div className="flex items-center justify-between rounded-lg border bg-slate-50 p-3">
<span className="text-sm font-medium text-slate-600">Status da política</span>
{getStatusBadge(usbPolicy.status)}
</div>
{usbPolicy?.status && getStatusBadge(usbPolicy.status)}
</div>
)}
{usbPolicy?.error && (
<div className="rounded-lg border border-red-200 bg-red-50 p-3">
<p className="text-sm font-medium text-red-700">Erro na aplicacao</p>
<p className="text-sm font-medium text-red-700">Erro na aplicação</p>
<p className="text-xs text-red-600">{usbPolicy.error}</p>
</div>
)}
{/* Política atual */}
<div className="flex items-center gap-3 rounded-lg border bg-neutral-50 p-3">
<div className="flex size-10 items-center justify-center rounded-full bg-white shadow-sm">
<CurrentIcon className="size-5 text-neutral-600" />
</div>
<div className="flex-1">
<p className="text-sm font-medium">{currentConfig.label}</p>
<p className="text-xs text-muted-foreground">{currentConfig.description}</p>
</div>
</div>
<div className="flex items-end gap-2">
<div className="flex-1 space-y-1.5">
<label className="text-xs font-medium text-muted-foreground">Alterar politica</label>
<label className="text-xs font-medium text-muted-foreground">Alterar política</label>
<Select
value={selectedPolicy}
onValueChange={(value) => setSelectedPolicy(value as UsbPolicyValue)}
disabled={disabled || isApplying}
>
<SelectTrigger>
<SelectValue placeholder="Selecione uma politica" />
<SelectValue placeholder="Selecione uma política" />
</SelectTrigger>
<SelectContent>
{POLICY_OPTIONS.map((option) => {
@ -234,8 +240,8 @@ export function UsbPolicyControl({
</TooltipTrigger>
<TooltipContent>
{selectedPolicy === usbPolicy?.policy
? "A politica ja esta aplicada"
: `Aplicar politica "${getPolicyConfig(selectedPolicy).label}"`}
? "A política já está aplicada"
: `Aplicar política "${getPolicyConfig(selectedPolicy).label}"`}
</TooltipContent>
</Tooltip>
</TooltipProvider>
@ -249,14 +255,14 @@ export function UsbPolicyControl({
onClick={() => setShowHistory(!showHistory)}
>
<History className="size-4" />
{showHistory ? "Ocultar historico" : "Ver historico de alteracoes"}
{showHistory ? "Ocultar histórico" : "Ver histórico de alterações"}
</Button>
{showHistory && policyEvents && (
<div className="mt-3 space-y-2">
{policyEvents.length === 0 ? (
<p className="text-center text-xs text-muted-foreground py-2">
Nenhuma alteracao registrada
Nenhuma alteração registrada
</p>
) : (
policyEvents.map((event: UsbPolicyEvent) => (
@ -269,14 +275,14 @@ export function UsbPolicyControl({
<span className="font-medium">
{getPolicyConfig(event.oldPolicy).label}
</span>
<span className="text-muted-foreground">-&gt;</span>
<span className="text-muted-foreground">&rarr;</span>
<span className="font-medium">
{getPolicyConfig(event.newPolicy).label}
</span>
{getStatusBadge(event.status)}
</div>
<p className="text-muted-foreground">
{event.actorName ?? event.actorEmail ?? "Sistema"} - {formatEventDate(event.createdAt)}
{event.actorName ?? event.actorEmail ?? "Sistema"} &middot; {formatEventDate(event.createdAt)}
</p>
{event.error && (
<p className="text-red-600">{event.error}</p>
@ -291,7 +297,7 @@ export function UsbPolicyControl({
{usbPolicy?.reportedAt && (
<p className="text-xs text-muted-foreground">
Ultimo relato do agente: {formatEventDate(usbPolicy.reportedAt)}
Último relato do agente: {formatEventDate(usbPolicy.reportedAt)}
</p>
)}
</div>