Skip to content

Commit

Permalink
Show helpful message when uploading duplicate firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
nshoes committed Nov 1, 2024
1 parent b7efd90 commit 9d68cfd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/nerves_hub_web/live/firmware.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ defmodule NervesHubWeb.Live.Firmware do
}} ->
error_feedback(socket, "No matching product could be found.")

{:error,
%Ecto.Changeset{
errors: [
uuid:
{"has already been taken",
[constraint: :unique, constraint_name: "firmwares_product_id_uuid_index"]}
]
} = c} ->
route =
"/org/#{socket.assigns.org.name}/#{socket.assigns.product.name}/firmware/#{c.changes.uuid}"

error_feedback(
socket,
"Duplicate firmware - <a href='#{route}' target='blank'>View Firmware</a>"
)

{:error, %Ecto.Changeset{}} ->
error_feedback(socket, "Unknown error uploading firmware.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<.live_file_input upload={@uploads.firmware} required />

<div class="has-error">
<span :if={@error_message} class="help-block"><%= @error_message %></span>
<span :if={@error_message} class="help-block"><%= raw(@error_message) %></span>
</div>

<div :for={entry <- @uploads.firmware.entries} class="mt-1">
Expand Down

0 comments on commit 9d68cfd

Please sign in to comment.