feat: melhorar inventário e gestão de máquinas
This commit is contained in:
parent
b1d334045d
commit
3f0702d80b
5 changed files with 584 additions and 59 deletions
|
|
@ -52,6 +52,8 @@ type AgentConfig = {
|
|||
tenantId?: string | null
|
||||
companySlug?: string | null
|
||||
machineEmail?: string | null
|
||||
collaboratorEmail?: string | null
|
||||
collaboratorName?: string | null
|
||||
apiBaseUrl: string
|
||||
appUrl: string
|
||||
createdAt: number
|
||||
|
|
@ -138,6 +140,8 @@ function App() {
|
|||
setToken(t)
|
||||
const cfg = await readConfig(s)
|
||||
setConfig(cfg)
|
||||
if (cfg?.collaboratorEmail) setCollabEmail(cfg.collaboratorEmail)
|
||||
if (cfg?.collaboratorName) setCollabName(cfg.collaboratorName)
|
||||
if (!t) {
|
||||
const p = await invoke<MachineProfile>("collect_machine_profile")
|
||||
setProfile(p)
|
||||
|
|
@ -149,6 +153,27 @@ function App() {
|
|||
})()
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!store || !config) return
|
||||
const email = collabEmail.trim()
|
||||
const name = collabName.trim()
|
||||
const normalizedEmail = email.length > 0 ? email : null
|
||||
const normalizedName = name.length > 0 ? name : null
|
||||
if (
|
||||
config.collaboratorEmail === normalizedEmail &&
|
||||
config.collaboratorName === normalizedName
|
||||
) {
|
||||
return
|
||||
}
|
||||
const nextConfig: AgentConfig = {
|
||||
...config,
|
||||
collaboratorEmail: normalizedEmail,
|
||||
collaboratorName: normalizedName,
|
||||
}
|
||||
setConfig(nextConfig)
|
||||
writeConfig(store, nextConfig).catch((err) => console.error("Falha ao atualizar colaborador", err))
|
||||
}, [store, config?.machineId, config?.collaboratorEmail, config?.collaboratorName, collabEmail, collabName])
|
||||
|
||||
useEffect(() => {
|
||||
if (!store || !config) return
|
||||
const normalizedAppUrl = normalizeUrl(config.appUrl, appUrl)
|
||||
|
|
@ -177,6 +202,9 @@ function App() {
|
|||
if (!provisioningSecret.trim()) { setError("Informe o código de provisionamento."); return }
|
||||
setBusy(true); setError(null)
|
||||
try {
|
||||
const collaboratorPayload = collabEmail.trim()
|
||||
? { email: collabEmail.trim(), name: collabName.trim() || undefined }
|
||||
: undefined
|
||||
const payload = {
|
||||
provisioningSecret: provisioningSecret.trim(),
|
||||
tenantId: tenantId.trim() || undefined,
|
||||
|
|
@ -185,7 +213,7 @@ function App() {
|
|||
os: profile.os,
|
||||
macAddresses: profile.macAddresses,
|
||||
serialNumbers: profile.serialNumbers,
|
||||
metadata: { inventory: profile.inventory, metrics: profile.metrics, collaborator: collabEmail ? { email: collabEmail.trim(), name: collabName.trim() || undefined } : undefined },
|
||||
metadata: { inventory: profile.inventory, metrics: profile.metrics, collaborator: collaboratorPayload },
|
||||
registeredBy: "desktop-agent",
|
||||
}
|
||||
const res = await fetch(`${apiBaseUrl}/api/machines/register`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) })
|
||||
|
|
@ -201,6 +229,8 @@ function App() {
|
|||
tenantId: data.tenantId ?? null,
|
||||
companySlug: data.companySlug ?? null,
|
||||
machineEmail: data.machineEmail ?? null,
|
||||
collaboratorEmail: collaboratorPayload?.email ?? null,
|
||||
collaboratorName: collaboratorPayload?.name ?? null,
|
||||
apiBaseUrl,
|
||||
appUrl,
|
||||
createdAt: Date.now(),
|
||||
|
|
@ -236,12 +266,19 @@ function App() {
|
|||
if (!token || !profile) return
|
||||
setBusy(true); setError(null)
|
||||
try {
|
||||
const collaboratorPayload = collabEmail.trim()
|
||||
? { email: collabEmail.trim(), name: collabName.trim() || undefined }
|
||||
: undefined
|
||||
const inventoryPayload: Record<string, unknown> = { ...profile.inventory }
|
||||
if (collaboratorPayload) {
|
||||
inventoryPayload.collaborator = collaboratorPayload
|
||||
}
|
||||
const payload = {
|
||||
machineToken: token,
|
||||
hostname: profile.hostname,
|
||||
os: profile.os,
|
||||
metrics: profile.metrics,
|
||||
inventory: profile.inventory,
|
||||
inventory: inventoryPayload,
|
||||
}
|
||||
const res = await fetch(`${apiBaseUrl}/api/machines/inventory`, {
|
||||
method: "POST",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue