A new bidding can only placed in the new form if a bidding round is currently running. The bidding round is set automatically when opening the form.

This commit is contained in:
2026-02-14 14:38:31 +01:00
parent d6f2d8c1f6
commit 2519560b03

View File

@ -3,6 +3,7 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
alias BeetRoundServer.Biddings alias BeetRoundServer.Biddings
alias BeetRoundServer.Biddings.Bidding alias BeetRoundServer.Biddings.Bidding
alias BeetRoundServer.BiddingRounds.BiddingRoundFacade
@impl true @impl true
def render(assigns) do def render(assigns) do
@ -12,6 +13,12 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
{@page_title} {@page_title}
<:subtitle>Bitte gib hier den Betrag ein, den Du monatlich bezahlen willst.</:subtitle> <:subtitle>Bitte gib hier den Betrag ein, den Du monatlich bezahlen willst.</:subtitle>
</.header> </.header>
<%= if @bidding.bidding_round == 0 do %>
<p><b>Keine Bietrunde aktiv.</b></p>
<footer>
<.button navigate={return_path(@current_scope, @return_to, @bidding)}>Cancel</.button>
</footer>
<% else %>
<.form for={@form} id="bidding-form" phx-change="validate" phx-submit="save"> <.form for={@form} id="bidding-form" phx-change="validate" phx-submit="save">
<.input field={@form[:bidding_round]} type="number" label="Bidding round" /> <.input field={@form[:bidding_round]} type="number" label="Bidding round" />
<.input field={@form[:amount]} type="number" label="Amount" /> <.input field={@form[:amount]} type="number" label="Amount" />
@ -22,15 +29,19 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
<.button navigate={return_path(@current_scope, @return_to, @bidding)}>Cancel</.button> <.button navigate={return_path(@current_scope, @return_to, @bidding)}>Cancel</.button>
</footer> </footer>
</.form> </.form>
<% end %>
</Layouts.app> </Layouts.app>
""" """
end end
@impl true @impl true
def mount(params, _session, socket) do def mount(params, _session, socket) do
# current_round = BiddingRoundFacade.get_current_round()
{:ok, {:ok,
socket socket
|> assign(:return_to, return_to(params["return_to"])) |> assign(:return_to, return_to(params["return_to"]))
# |> assign(bidding_round: current_round)
|> apply_action(socket.assigns.live_action, params)} |> apply_action(socket.assigns.live_action, params)}
end end
@ -47,7 +58,12 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
end end
defp apply_action(socket, :new, _params) do defp apply_action(socket, :new, _params) do
bidding = %Bidding{user_id: socket.assigns.current_scope.user.id} current_round = BiddingRoundFacade.get_current_round()
bidding = %Bidding{
user_id: socket.assigns.current_scope.user.id,
bidding_round: current_round
}
socket socket
|> assign(:page_title, "Neues Gebot") |> assign(:page_title, "Neues Gebot")