Fix crash on /submit when LiveStash restores CSV tab without csv_result assign

Set all assigns before LiveStash recovery so reconnecting to the CSV
tab doesn't crash on missing :csv_result / :csv_preview keys.
This commit is contained in:
Graham McIntire 2026-04-10 14:04:16 -05:00
parent d071b02cea
commit ea0c41ef50

View file

@ -17,25 +17,27 @@ defmodule MicrowavepropWeb.SubmitLive do
def mount(_params, _session, socket) do
socket = allow_upload(socket, :csv, accept: ~w(.csv), max_entries: 1, max_file_size: 10_000_000)
changeset = Radio.change_contact(%Contact{})
socket =
assign(socket,
page_title: "Submit Contact",
form: to_form(changeset),
band_options: @band_options,
mode_options: @mode_options,
submitted_at: nil,
active_tab: :single,
csv_preview: nil,
csv_result: nil,
csv_email: ""
)
case LiveStash.recover_state(socket) do
{:recovered, socket} ->
{:ok, socket}
_ ->
changeset = Radio.change_contact(%Contact{})
{:ok,
assign(socket,
page_title: "Submit Contact",
form: to_form(changeset),
band_options: @band_options,
mode_options: @mode_options,
submitted_at: nil,
active_tab: :single,
csv_preview: nil,
csv_result: nil,
csv_email: ""
)}
{:ok, socket}
end
end