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:
parent
d071b02cea
commit
ea0c41ef50
1 changed files with 16 additions and 14 deletions
|
|
@ -17,25 +17,27 @@ defmodule MicrowavepropWeb.SubmitLive do
|
||||||
def mount(_params, _session, socket) do
|
def mount(_params, _session, socket) do
|
||||||
socket = allow_upload(socket, :csv, accept: ~w(.csv), max_entries: 1, max_file_size: 10_000_000)
|
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
|
case LiveStash.recover_state(socket) do
|
||||||
{:recovered, socket} ->
|
{:recovered, socket} ->
|
||||||
{:ok, socket}
|
{:ok, socket}
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
changeset = Radio.change_contact(%Contact{})
|
{:ok, socket}
|
||||||
|
|
||||||
{: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: ""
|
|
||||||
)}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue