diff --git a/lib/ex338_web/live/fantasy_team_draft_queues/edit_form_component.ex b/lib/ex338_web/live/fantasy_team_draft_queues/edit_form_component.ex index 69ac1816..76d35b1b 100644 --- a/lib/ex338_web/live/fantasy_team_draft_queues/edit_form_component.ex +++ b/lib/ex338_web/live/fantasy_team_draft_queues/edit_form_component.ex @@ -31,7 +31,7 @@ defmodule Ex338Web.FantasyTeamDraftQueuesLive.EditFormComponent do {:noreply, socket |> put_flash(:info, "Fantasy team draft queues updated successfully") - |> redirect(to: ~p"/fantasy_teams/#{fantasy_team}")} + |> push_patch(to: ~p"/fantasy_teams/#{fantasy_team}/draft_queues/edit")} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign_form(socket, changeset)} @@ -82,12 +82,13 @@ defmodule Ex338Web.FantasyTeamDraftQueuesLive.EditFormComponent do
<.draft_queue_form form={@form} fantasy_team={@fantasy_team} />
+ <.pending_changes_warning :if={form_has_changes?(@form)} />
<.submit_buttons submit_text="Save Changes" - back_text="Cancel" + back_text="Back" back_route={~p"/fantasy_teams/#{@fantasy_team.id}"} />
@@ -196,4 +197,36 @@ defmodule Ex338Web.FantasyTeamDraftQueuesLive.EditFormComponent do """ end + + defp form_has_changes?(form) do + form.source.changes != %{} + end + + defp pending_changes_warning(assigns) do + ~H""" +
+
+
+ +
+
+

+ You have pending changes. +

+
+
+
+ """ + end end diff --git a/test/ex338_web/live/fantasy_team_draft_queues_live/edit_test.exs b/test/ex338_web/live/fantasy_team_draft_queues_live/edit_test.exs index 40135431..d98b1421 100644 --- a/test/ex338_web/live/fantasy_team_draft_queues_live/edit_test.exs +++ b/test/ex338_web/live/fantasy_team_draft_queues_live/edit_test.exs @@ -16,18 +16,30 @@ defmodule Ex338Web.FantasyTeamDraftQueuesLive.EditTest do {:ok, view, _html} = live(conn, ~p"/fantasy_teams/#{team.id}/draft_queues/edit") attrs = %{ + "autodraft_setting" => "off", "draft_queues" => %{ "0" => %{"id" => queue.id} }, "draft_queues_order" => ["0"] } + html = + view + |> form("#fantasy-team-draft-queues-form", fantasy_team: attrs) + |> render_change() + + assert html =~ "You have pending changes." + view |> form("#fantasy-team-draft-queues-form", fantasy_team: attrs) |> render_submit() - {path, _flash} = assert_redirect(view) - assert path == ~p"/fantasy_teams/#{team}" + html = render(view) + + refute html =~ "You have pending changes." + + assert html =~ "Fantasy team draft queues updated successfully" + assert html =~ "Update Team Draft Queues" end test "does not update and renders draft queue errors when invalid", %{conn: conn} do