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:
@ -3,6 +3,7 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
|
||||
|
||||
alias BeetRoundServer.Biddings
|
||||
alias BeetRoundServer.Biddings.Bidding
|
||||
alias BeetRoundServer.BiddingRounds.BiddingRoundFacade
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
@ -12,25 +13,35 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
|
||||
{@page_title}
|
||||
<:subtitle>Bitte gib hier den Betrag ein, den Du monatlich bezahlen willst.</:subtitle>
|
||||
</.header>
|
||||
<.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[:amount]} type="number" label="Amount" />
|
||||
<.input field={@form[:depot_wish_one]} type="text" label="Depot wish one" />
|
||||
<.input field={@form[:depot_wish_two]} type="text" label="Depot wish two" />
|
||||
<%= if @bidding.bidding_round == 0 do %>
|
||||
<p><b>Keine Bietrunde aktiv.</b></p>
|
||||
<footer>
|
||||
<.button phx-disable-with="Bearbeitung..." variant="primary">Gebot abgeben</.button>
|
||||
<.button navigate={return_path(@current_scope, @return_to, @bidding)}>Cancel</.button>
|
||||
</footer>
|
||||
</.form>
|
||||
<% else %>
|
||||
<.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[:amount]} type="number" label="Amount" />
|
||||
<.input field={@form[:depot_wish_one]} type="text" label="Depot wish one" />
|
||||
<.input field={@form[:depot_wish_two]} type="text" label="Depot wish two" />
|
||||
<footer>
|
||||
<.button phx-disable-with="Bearbeitung..." variant="primary">Gebot abgeben</.button>
|
||||
<.button navigate={return_path(@current_scope, @return_to, @bidding)}>Cancel</.button>
|
||||
</footer>
|
||||
</.form>
|
||||
<% end %>
|
||||
</Layouts.app>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(params, _session, socket) do
|
||||
# current_round = BiddingRoundFacade.get_current_round()
|
||||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(:return_to, return_to(params["return_to"]))
|
||||
# |> assign(bidding_round: current_round)
|
||||
|> apply_action(socket.assigns.live_action, params)}
|
||||
end
|
||||
|
||||
@ -47,7 +58,12 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
|
||||
end
|
||||
|
||||
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
|
||||
|> assign(:page_title, "Neues Gebot")
|
||||
|
||||
Reference in New Issue
Block a user