diff --git a/lib/towerops_web/live/org/settings_live.ex b/lib/towerops_web/live/org/settings_live.ex index aec61e1f..bfd21b7e 100644 --- a/lib/towerops_web/live/org/settings_live.ex +++ b/lib/towerops_web/live/org/settings_live.ex @@ -383,9 +383,8 @@ defmodule ToweropsWeb.Org.SettingsLive do provider = socket.assigns.configuring if provider == "netbox" do - integration = current_integration(socket) - url = get_credential(integration, "url") - token = get_credential(integration, "api_token") + # Read from form changeset (unsaved) first, fall back to saved integration + {url, token} = extract_netbox_credentials(socket) cond do url == "" or is_nil(url) -> @@ -574,6 +573,24 @@ defmodule ToweropsWeb.Org.SettingsLive do Map.get(socket.assigns.integrations, provider) end + defp extract_netbox_credentials(socket) do + # Try form changeset first (user may have typed but not saved) + changeset = socket.assigns.integration_form.source + form_creds = Ecto.Changeset.get_field(changeset, :credentials) || %{} + form_url = Map.get(form_creds, "url", "") + form_token = Map.get(form_creds, "api_token", "") + + # Fall back to saved integration + integration = current_integration(socket) + saved_url = get_credential(integration, "url") + saved_token = get_credential(integration, "api_token") + + url = if form_url == "", do: saved_url, else: form_url + token = if form_token == "", do: saved_token, else: form_token + + {url, token} + end + defp extract_api_key(socket) do changeset = socket.assigns.integration_form.source data = Ecto.Changeset.apply_changes(changeset)