feat: custom fields improvements
This commit is contained in:
parent
9495b54a28
commit
0f0f367b3a
11 changed files with 1290 additions and 12 deletions
|
|
@ -68,6 +68,7 @@ import { useAuth } from "@/lib/auth-client"
|
|||
import type { Id } from "@/convex/_generated/dataModel"
|
||||
import { TicketStatusBadge } from "@/components/tickets/status-badge"
|
||||
import type { TicketPriority, TicketStatus } from "@/lib/schemas/ticket"
|
||||
import { DeviceCustomFieldManager } from "@/components/admin/devices/device-custom-field-manager"
|
||||
|
||||
type DeviceMetrics = Record<string, unknown> | null
|
||||
|
||||
|
|
@ -2413,6 +2414,7 @@ export function DeviceDetails({ device }: DeviceDetailsProps) {
|
|||
const { role: viewerRole } = useAuth()
|
||||
const normalizedViewerRole = (viewerRole ?? "").toLowerCase()
|
||||
const canManageRemoteAccess = normalizedViewerRole === "admin" || normalizedViewerRole === "agent"
|
||||
const canManageFieldCatalog = normalizedViewerRole === "admin"
|
||||
const effectiveStatus = device ? resolveDeviceStatus(device) : "unknown"
|
||||
const [isActiveLocal, setIsActiveLocal] = useState<boolean>(device?.isActive ?? true)
|
||||
const isDeactivated = !isActiveLocal || effectiveStatus === "deactivated"
|
||||
|
|
@ -3430,12 +3432,17 @@ export function DeviceDetails({ device }: DeviceDetailsProps) {
|
|||
.filter((entry) => entry.value !== undefined) as Array<{ fieldId: Id<"deviceFields">; value: unknown }>
|
||||
await saveCustomFields({ tenantId: device.tenantId, actorId: convexUserId as Id<"users">, machineId: device.id as Id<"machines">, fields })
|
||||
toast.success("Campos salvos com sucesso.")
|
||||
try {
|
||||
router.refresh()
|
||||
} catch {
|
||||
// ignore refresh errors (e.g., when not in a routed context)
|
||||
}
|
||||
setCustomFieldsEditorOpen(false)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.error("Não foi possível salvar os campos.")
|
||||
}
|
||||
}, [device, convexUserId, editableFields, customFieldValues, saveCustomFields])
|
||||
}, [device, convexUserId, editableFields, customFieldValues, saveCustomFields, router])
|
||||
|
||||
const [newFieldOpen, setNewFieldOpen] = useState(false)
|
||||
const [newFieldLabel, setNewFieldLabel] = useState("")
|
||||
|
|
@ -3458,6 +3465,7 @@ export function DeviceDetails({ device }: DeviceDetailsProps) {
|
|||
required: false,
|
||||
options: (newFieldType === "select" || newFieldType === "multiselect") ? newFieldOptions : undefined,
|
||||
scope: (device.deviceType ?? "all") as string,
|
||||
companyId: device.companyId ? (device.companyId as Id<"companies">) : undefined,
|
||||
})
|
||||
toast.success("Campo criado")
|
||||
setNewFieldLabel("")
|
||||
|
|
@ -3558,6 +3566,13 @@ export function DeviceDetails({ device }: DeviceDetailsProps) {
|
|||
<Pencil className="size-4" />
|
||||
Editar
|
||||
</Button>
|
||||
{canManageFieldCatalog && device ? (
|
||||
<DeviceCustomFieldManager
|
||||
tenantId={device.tenantId}
|
||||
defaultScope={device.deviceType ?? "all"}
|
||||
defaultCompanyId={device.companyId ?? null}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{device.customFields && device.customFields.length > 0 ? (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue