fix: improve admin machine details and role gating

This commit is contained in:
Esdras Renan 2025-10-13 13:32:50 -03:00
parent 076c0df7f9
commit 42611df0f5
6 changed files with 311 additions and 162 deletions

View file

@ -8,10 +8,12 @@ import { Card, CardContent } from "@/components/ui/card"
import { Skeleton } from "@/components/ui/skeleton"
export function AdminMachineDetailsClient({ tenantId, machineId }: { tenantId: string; machineId: string }) {
const list = (useQuery(api.machines.listByTenant, { tenantId, includeMetadata: true }) ?? []) as MachinesQueryItem[]
const machine = useMemo(() => list.find((m) => m.id === machineId) ?? null, [list, machineId])
const queryResult = useQuery(api.machines.listByTenant, { tenantId, includeMetadata: true }) as MachinesQueryItem[] | undefined
const isLoading = queryResult === undefined
const machines = queryResult ?? []
const machine = useMemo(() => machines.find((m) => m.id === machineId) ?? null, [machines, machineId])
if (!list) {
if (isLoading) {
return (
<Card>
<CardContent className="space-y-3 p-6">
@ -25,4 +27,3 @@ export function AdminMachineDetailsClient({ tenantId, machineId }: { tenantId: s
return <MachineDetails machine={machine} />
}