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
|
||||||
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,25 +13,35 @@ 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>
|
||||||
<.form for={@form} id="bidding-form" phx-change="validate" phx-submit="save">
|
<%= if @bidding.bidding_round == 0 do %>
|
||||||
<.input field={@form[:bidding_round]} type="number" label="Bidding round" />
|
<p><b>Keine Bietrunde aktiv.</b></p>
|
||||||
<.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>
|
<footer>
|
||||||
<.button phx-disable-with="Bearbeitung..." variant="primary">Gebot abgeben</.button>
|
|
||||||
<.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>
|
<% 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>
|
</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")
|
||||||
|
|||||||
Reference in New Issue
Block a user